displayAddEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " <!-- (DIS)?CONTINUE Notes -->" to "")
m (formatting)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


| arma2
|game1= arma2


|1.00
|version1= 1.00
 
|game2= arma2oa
 
|version2= 1.51
 
|game3= tkoh
 
|version3= 1.00
 
|game4= arma3
 
|version4= 0.50


|gr1= GUI Control - Event Handlers
|gr1= GUI Control - Event Handlers
|gr2= Event Handlers
|gr2= Event Handlers


| Adds an event handler to the given display. Returns the ID of the event handler, or -1 when failed.
|descr= Adds an event handler to the given display. See [[User Interface Event Handlers]] for the full list of event names.
<br>
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]].
Returning [[true]] in EH code will override default engine handling for keyboard events.
{{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.}}
<br>
See [[User_Interface_Event_Handlers|User Interface Event Handlers]] for the full list of event names.
<br>
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]].<br><br>
{{ 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.}}
<br>
{{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'''').}}


| display '''displayAddEventHandler''' [eventName, code]
|s1= display '''displayAddEventHandler''' [eventName, code]


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


|p2= [eventName, code]: [[Array]]
|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= eventName: [[String]]
|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.


|p4= code: [[String]] or [[Code]]
|r1= [[Number]] - Index of the newly added event handler or <tt>-1</tt> if creation failed
 
| [[Number]]


|x1= <code>moduleName_keyDownEHId <nowiki>=</nowiki> [[findDisplay]] 46 [[displayAddEventHandler]] ["KeyDown", "[[hint]] [[str]] _this;"];</code>
|x1= <code>moduleName_keyDownEHId <nowiki>=</nowiki> [[findDisplay]] 46 [[displayAddEventHandler]] ["KeyDown", "[[hint]] [[str]] _this;"];</code>
Line 42: Line 46:
<dt class="note">[[User:Killzone_Kid|Killzone_Kid]]<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]
<dt class="note">[[User:Killzone_Kid|Killzone_Kid]]<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]
<dd class="notedate">Posted on March 10, 2014 - 14:52</dd>
<dd class="notedate">Posted on March 10, 2014 - 14:52</dd>
<dt class="note">[[User:Axyl|Axyl]]<dd class="note">From within an Addon, you must assign the events from a spawned script.  eg<code>[] spawn { (findDisplay 46) displayAddEventHandler["KeyDown","_this call my_KeyDownFunctionhandler"]; };</code>
<dt class="note">[[User:Axyl|Axyl]]<dd class="note">From within an Addon, you must assign the events from a spawned script.  e.g. <code>[] [[spawn]] { [[findDisplay]] 46 [[displayAddEventHandler]] ["KeyDown", "[[_this]] [[call]] my_KeyDownFunctionhandler"]; };</code>


</dl>
</dl>
{{GameCategory|arma2|Scripting Commands}}
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]


<dl class="command_description">
<dl class="command_description">
Line 57: Line 55:
<dt class="note">[[User:Pigneedle|Pigneedle]]</dt>
<dt class="note">[[User:Pigneedle|Pigneedle]]</dt>
<dd class="note">
<dd class="note">
Be sure to wait until the main display is initialized before using this command by using: <code>waituntil {!isnull (finddisplay 46)};</code>
Be sure to wait until the main display is initialized before using this command by using: <code>[[waitUntil]] { ![[isNull]] ([[findDisplay]] 46) };</code>
</dd>
</dd>
<dt><dt>
<dt><dt>
Line 64: Line 62:
<dd class="note">
<dd class="note">
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>
</dd>
<dt><dt>
<dt><dt>
Line 70: Line 68:
<dt class="note">[[User:DrSova|DrSova]]</dt>
<dt class="note">[[User:DrSova|DrSova]]</dt>
<dd class="note">
<dd class="note">
Using '''KeyUp''' you can't override default engine action by returning '''true''' ('''A3 1.72.142342''')
Using '''KeyUp''' you can't override default engine action by returning '''true''' ('''Arma3 v1.72''')
</dd>
</dd>
</dl>
</dl>

Revision as of 16:39, 12 May 2021

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 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.
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 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:
ListOfKeyCodesdisableSerializationdisplayRemoveAllEventHandlersdisplayRemoveEventHandlerdisplaySetEventHandlerctrlAddEventHandlerUI Event HandlersfindDisplayDIK KeyCodeskeyName

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 October 30, 2013 - 11:14
Killzone_Kid
As of Arma 3 v1.06 ctrlAddEventHandler and displayAddEventHandler support script Code in addition to String [1]
Posted on March 10, 2014 - 14:52
Axyl
From within an Addon, you must assign the events from a spawned script. e.g. [] spawn { findDisplay 46 displayAddEventHandler ["KeyDown", "_this call my_KeyDownFunctionhandler"]; };
Posted on January 22, 2016 - 08:15 (UTC)
Pigneedle
Be sure to wait until the main display is initialized before using this command by using: waitUntil { !isNull (findDisplay 46) };
Posted on May 28, 2017 - 11:32 (UTC)
IT07
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.
Posted on August 7, 2017 - 15:08 (UTC)
DrSova
Using KeyUp you can't override default engine action by returning true (Arma3 v1.72)