displayAddEventHandler: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " \| *s([0-9]) *= ([^ ]+)? ?'''([a-zA-Z0-9_]+)''' ?([^ ]+)? " to " |s$1= $2 $3 $4 ") |
Lou Montana (talk | contribs) m (Text replacement - "[] spawn" to "0 spawn") |
||
(39 intermediate revisions by 4 users not shown) | |||
Line 2: | Line 2: | ||
|game1= arma2 | |game1= arma2 | ||
|version1= 1.00 | |version1= 1.00 | ||
|game2= arma2oa | |game2= arma2oa | ||
|version2= 1.50 | |||
|version2= 1. | |||
|game3= tkoh | |game3= tkoh | ||
|version3= 1.00 | |version3= 1.00 | ||
|game4= arma3 | |game4= arma3 | ||
|version4= 0.50 | |version4= 0.50 | ||
Line 23: | Line 19: | ||
|descr= Adds an event handler to the given display. See [[User Interface Event Handlers]] for the full list of event names. | |descr= Adds an event handler to the given display. See [[User Interface Event Handlers]] for the full list of event names. | ||
If applicable, see [[DIK_KeyCodes]] for a list of key code constants, which are relevant to key related user interface events like: [[User Interface Event Handlers#onKeyDown|KeyDown]] & [[User Interface Event Handlers#onKeyUp|KeyUp]]. | If applicable, see [[DIK_KeyCodes]] for a list of key code constants, which are relevant to key related user interface events like: [[User Interface Event Handlers#onKeyDown|KeyDown]] & [[User Interface Event Handlers#onKeyUp|KeyUp]]. | ||
{{Feature|important|Display EHs are processed | {{Feature|important|Display EHs are processed from last to first added; an input override should be set up in the first added EH.}} | ||
{{Feature|informative|The event handler ID can be accessed inside the event handler code using the <sqf inline>_thisEventHandler</sqf> [[Magic_Variables#thisEventHandler|magic variable]].}} | |||
|s1= display [[displayAddEventHandler]] | |s1= display [[displayAddEventHandler]] [eventName, code] | ||
|p1= display: [[Display]] | |p1= display: [[Display]] | ||
|p2= eventName: [[String]] - | |p2= eventName: [[String]] - event name | ||
{{Feature|important|When using the event names listed [[User Interface Event Handlers|here]] with the [[ctrlAddEventHandler]], [[ctrlSetEventHandler]], [[displayAddEventHandler]] or [[displaySetEventHandler]] commands, the prefix "on" in the event name must be removed (e.g. ''''ButtonDown'''' instead of ''''onButtonDown'''').}} | |||
|p3= code: [[String]] or [[Code]] - | |p3= code: [[String]] or {{GVI|arma3|1.06|size= 0.75}} [[Code]] - the code which gets executed when event is triggered. Returning [[true]] in event handler code will override default engine handling for keyboard events. | ||
Several [[Magic Variables]] are available: | |||
* Event Handler parameters are accessible via {{hl|_this}} | |||
* The Event Handler type is available as {{hl|_thisEvent}} | |||
* The Event Handler index is available as {{hl|_thisEventHandler}} | |||
|r1= [[Number]] - | |r1= [[Number]] - index of the newly added event handler or {{hl|-1}} if creation failed | ||
|x1= < | |x1= <sqf>moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", "hint str _this;"];</sqf> | ||
|x2= < | |x2= <sqf>moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", { hint str _this }];</sqf> | ||
|seealso= | |seealso= [[disableSerialization]] [[displayRemoveAllEventHandlers]] [[displayRemoveEventHandler]] [[displaySetEventHandler]] [[ctrlAddEventHandler]] [[User_Interface_Event_Handlers|UI Event Handlers]] [[findDisplay]] [[DIK_KeyCodes|DIK Key Codes]] [[keyName]] | ||
}} | }} | ||
< | {{Note | ||
|user= Axyl | |||
|timestamp= 20140310145200 | |||
|text= From within an Addon, you must assign the events from a spawned script. e.g. <sqf>0 spawn { findDisplay 46 displayAddEventHandler ["KeyDown", "_this call my_KeyDownFunctionhandler"]; };</sqf> | |||
}} | |||
{{Note | |||
|user= Pigneedle | |||
|timestamp= 20160122081500 | |||
|text= Be sure to wait until the main display is initialized before using this command by using: | |||
< | <sqf>waitUntil { !isNull (findDisplay 46) };</sqf> | ||
}} | |||
{{Note | |||
|user= Nelis75733126 | |||
|timestamp= 20170528113200 | |||
|text= use ({{Link|PreProcessor_Commands##define|#define}}) if you want <sqf inline>displayAddEventHandler</sqf> to use data defined in the same script. You can then integrate that data either directly, or by applying {{Link|format|format}} to the second parameter. | |||
}} | |||
{{Note | |||
|user= DrSova | |||
|timestamp= 20170807150800 | |||
|text= Using '''KeyUp''' you can't override default engine action by returning '''true''' | |||
|game= arma3 | |||
|version= 1.72 | |||
}} | |||
{{Note | |||
|user= R3vo | |||
|timestamp= 20210626161700 | |||
|text= To prevent a display from getting closed by pressing ESC, add the following event handler. | |||
<sqf> | |||
</ | #include "\a3\ui_f\hpp\definedikcodes.inc" | ||
_display displayAddEventHandler ["KeyDown", | |||
{ | |||
params ["", "_key"]; | |||
_key == DIK_ESC; // ESC pressed while dialog is open, overwrite default behaviour | |||
}]; | |||
</sqf> | |||
}} |
Latest revision as of 21:24, 2 September 2024
Description
- Description:
- Adds an event handler to the given display. See User Interface Event Handlers for the full list of event names. If applicable, see DIK_KeyCodes for a list of key code constants, which are relevant to key related user interface events like: KeyDown & KeyUp.
- Groups:
- GUI Control - Event HandlersEvent Handlers
Syntax
- Syntax:
- display displayAddEventHandler [eventName, code]
- Parameters:
- display: Display
- eventName: String - event name
- code: String or 1.06 Code - the code which gets executed when event is triggered. Returning true in event handler code will override default engine handling for keyboard events.
Several Magic Variables are available:
- Event Handler parameters are accessible via _this
- The Event Handler type is available as _thisEvent
- The Event Handler index is available as _thisEventHandler
- Return Value:
- Number - index of the newly added event handler or -1 if creation failed
Examples
- Example 1:
- Example 2:
Additional Information
- See also:
- disableSerialization displayRemoveAllEventHandlers displayRemoveEventHandler displaySetEventHandler ctrlAddEventHandler UI Event Handlers findDisplay DIK Key Codes keyName
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Mar 10, 2014 - 14:52 (UTC)
-
From within an Addon, you must assign the events from a spawned script. e.g. 0 spawn { findDisplay 46 displayAddEventHandler ["KeyDown", "_this call my_KeyDownFunctionhandler"]; };
- Posted on Jan 22, 2016 - 08:15 (UTC)
-
Be sure to wait until the main display is initialized before using this command by using:
- Posted on May 28, 2017 - 11:32 (UTC)
- use ( #define) if you want displayAddEventHandler to use data defined in the same script. You can then integrate that data either directly, or by applying format to the second parameter.
- Posted on Aug 07, 2017 - 15:08 (UTC)
-
Using KeyUp you can't override default engine action by returning true
- Posted on Jun 26, 2021 - 16:17 (UTC)
- To prevent a display from getting closed by pressing ESC, add the following event handler.