displayAddEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Some wiki formatting)
m (Some wiki formatting)
Line 19: 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 in reversed order, i.e. last added: first, first added: last. So if you have an override it should be set up in the 1st added EH.}}
{{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 {{ic|_thisEventHandler}} [[Magic_Variables#thisEventHandler|magic variable]].}}
{{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]] [eventName, code]
|s1= display [[displayAddEventHandler]] [eventName, code]


|p1= display: [[Display]]
|p1= display: [[Display]]


|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'''').}}
|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]] - The code which gets executed when event is triggered. Returning [[true]] in event handler code will override default engine handling for keyboard events.
|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.


|r1= [[Number]] - Index of the newly added event handler or {{hl|-1}} if creation failed
|r1= [[Number]] - index of the newly added event handler or {{hl|-1}} if creation failed


|x1= <sqf>moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", "hint str _this;"];</sqf>
|x1= <sqf>moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", "hint str _this;"];</sqf>
Line 39: Line 40:
}}
}}


<dl class="command_description">
{{Note
|user= Axyl
|timestamp= 20140310145200
|text= From within an Addon, you must assign the events from a spawned script.  e.g. <sqf>[] spawn { findDisplay 46 displayAddEventHandler ["KeyDown", "[[_this]] call my_KeyDownFunctionhandler"]; };</sqf>
}}


<dt></dt>
{{Note
<dd class="notedate">Posted on October 30, 2013 - 11:14</dd>
|user= Pigneedle
<dt class="note">[[User:Killzone_Kid|Killzone_Kid]]</dt>
|timestamp= 20160122081500
<dd class="note">As of Arma 3 v1.06 [[ctrlAddEventHandler]] and [[displayAddEventHandler]] support script [[Code]] in addition to [[String]] [http://forums.bistudio.com/showthread.php?149636-Development-Branch-Changelog&p=2546439&viewfull=1#post2546439]
|text= Be sure to wait until the main display is initialized before using this command by using:
<dd class="notedate">Posted on March 10, 2014 - 14:52</dd>
<dt class="note">[[User:Axyl|Axyl]]</dt>
<dd class="note">From within an Addon, you must assign the events from a spawned script.  e.g. <sqf>[] spawn { findDisplay 46 displayAddEventHandler ["KeyDown", "[[_this]] call my_KeyDownFunctionhandler"]; };</sqf>
 
<dt></dt>
<dd class="notedate">Posted on January 22, 2016 - 08:15 (UTC)</dd>
<dt class="note">[[User:Pigneedle|Pigneedle]]</dt>
<dd class="note">
Be sure to wait until the main display is initialized before using this command by using:
<sqf>waitUntil { !isNull (findDisplay 46) };</sqf>
<sqf>waitUntil { !isNull (findDisplay 46) };</sqf>
</dd>
}}


<dt><dt>
{{Note
<dd class="notedate">Posted on May 28, 2017 - 11:32 (UTC)</dd>
|user= IT07
<dt class="note">[[User:IT07|IT07]]</dt>
|timestamp= 20170528113200
<dd class="note">
|text= use #define if you want the displayEventHandler to use data that is defined in the same file in which the command is executed.
use #define if you want the displayEventHandler to use data that is defined in the same file in which the command is executed.
However, that does not work if you use [[String]] as 'code'. In case of [[String]], use the format command around it.  
However, that does not work if you use [[String]] as 'code'. In case of [[String]], use the format command around it.  
</dd>
}}


<dt><dt>
{{Note
<dd class="notedate">Posted on August 7, 2017 - 15:08 (UTC)</dd>
|user= DrSova
<dt class="note">[[User:DrSova|DrSova]]</dt>
|timestamp= 20170807150800
<dd class="note">
|text= Using '''KeyUp''' you can't override default engine action by returning '''true'''
Using '''KeyUp''' you can't override default engine action by returning '''true''' ('''Arma3 v1.72''')
|game= arma3
</dd>
|version= 1.72
}}


<dt></dt>
{{Note
<dd class="notedate">Posted on June 26, 2021 - 16:17 (UTC)</dd>
|user= R3vo
<dt class="note">[[User:R3vo|R3vo]]</dt>
|timestamp= 20210626161700
<dd class="note">
|text= To prevent a display from getting closed by pressing ESC, add the following event handler.
To prevent a display from getting closed by pressing ESC, add the following event handler.
<sqf>
<sqf>#include "\a3\ui_f\hpp\definedikcodes.inc"
#include "\a3\ui_f\hpp\definedikcodes.inc"
_display displayAddEventHandler ["KeyDown",
_display displayAddEventHandler ["KeyDown",
{
{
params ["", "_key"];
params ["", "_key"];
_key == DIK_ESC // ESC pressed while dialog is open, overwrite default behaviour
_key == DIK_ESC; // ESC pressed while dialog is open, overwrite default behaviour
}];</sqf>
}];
</dd>
</sqf>
</dl>
}}

Revision as of 14:21, 27 July 2022

Hover & click on the images for description

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.
Display EHs are processed from last to first added; an input override should be set up in the first added EH.
The event handler ID can be accessed inside the event handler code using the _thisEventHandler magic variable.
Groups:
GUI Control - Event HandlersEvent Handlers

Syntax

Syntax:
display displayAddEventHandler [eventName, code]
Parameters:
display: Display
eventName: String - event name
When using the event names listed 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').
code: String or Arma 3 logo black.png1.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.
Return Value:
Number - index of the newly added event handler or -1 if creation failed

Examples

Example 1:
moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", "hint str _this;"];
Example 2:
moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", { hint str _this }];

Additional Information

See also:
ListOfKeyCodes disableSerialization displayRemoveAllEventHandlers displayRemoveEventHandler displaySetEventHandler ctrlAddEventHandler UI Event Handlers findDisplay DIK KeyCodes 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
Axyl - c
Posted on Mar 10, 2014 - 14:52 (UTC)
From within an Addon, you must assign the events from a spawned script. e.g.
[] spawn { findDisplay 46 displayAddEventHandler ["KeyDown", "[[_this]] call my_KeyDownFunctionhandler"]; };
Pigneedle - c
Posted on Jan 22, 2016 - 08:15 (UTC)
Be sure to wait until the main display is initialized before using this command by using:
IT07 - c
Posted on May 28, 2017 - 11:32 (UTC)
use #define if you want the displayEventHandler to use data that is defined in the same file in which the command is executed. However, that does not work if you use String as 'code'. In case of String, use the format command around it.
DrSova - c
Posted on Aug 07, 2017 - 15:08 (UTC)

Using KeyUp you can't override default engine action by returning true

R3vo - c
Posted on Jun 26, 2021 - 16:17 (UTC)
To prevent a display from getting closed by pressing ESC, add the following event handler.
#include "\a3\ui_f\hpp\definedikcodes.inc" _display displayAddEventHandler ["KeyDown", { params ["", "_key"]; _key == DIK_ESC; // ESC pressed while dialog is open, overwrite default behaviour }];