displayAddEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(note -> important)
m (sentence formatting improved.)
 
(83 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma2 |= Game name
|game1= arma2
|version1= 1.00


|1.00|= Game version
|game2= arma2oa
____________________________________________________________________________________________
|version2= 1.50


| Adds an event handler to the given display. Returns the ID of the event handler, or -1 when failed.
|game3= tkoh
<br>
|version3= 1.00
Returning [[true]] in EH code will override default engine handling for keyboard events.
<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>
{{ 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.}} |= Description
____________________________________________________________________________________________


| display '''displayAddEventHandler''' [eventName, code] |= Syntax
|game4= arma3
|version4= 0.50


|p1= display: [[Display]] |= PARAMETER1
|gr1= GUI Control - Event Handlers


|p2= [eventName, code]: [[Array]] |= PARAMETER2
|gr2= Event Handlers


|p3= eventName: [[String]] |= Parameter 3
|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]].
{{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]].}}


|p4= code: [[String]] or [[Code]] |= Parameter 4
|s1= display [[displayAddEventHandler]] [eventName, code]


| [[Number]] |= RETURNVALUE
|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'''').}}


|x1= <code>moduleName_keyDownEHId <nowiki>=</nowiki> ([[findDisplay]] 46) [[displayAddEventHandler]] ["KeyDown", "[[hint]] [[str]] _this;"];</code> |= Example 1
|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}}


|x2= <code>moduleName_keyDownEHId <nowiki>=</nowiki> [[findDisplay]] 46 [[displayAddEventHandler]] ["KeyDown", {[[hint]] [[str]] _this}];</code> |= Example 2
|r1= [[Number]] - index of the newly added event handler or {{hl|-1}} if creation failed
____________________________________________________________________________________________


| [[ListOfKeyCodes]], [[disableSerialization]], [[displayRemoveAllEventHandlers]], [[displayRemoveEventHandler]], [[displaySetEventHandler]], [[ctrlAddEventHandler]], [[User_Interface_Event_Handlers|UI Event Handlers]], [[findDisplay]], [[DIK_KeyCodes|DIK KeyCodes]], [[keyName]] |= SEEALSO
|x1= <sqf>moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", "hint str _this;"];</sqf>


| |= MPBEHAVIOUR
|x2= <sqf>moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", { hint str _this }];</sqf>
____________________________________________________________________________________________
 
|seealso= [[disableSerialization]] [[displayRemoveAllEventHandlers]] [[displayRemoveEventHandler]] [[displaySetEventHandler]] [[ctrlAddEventHandler]] [[User_Interface_Event_Handlers|UI Event Handlers]] [[findDisplay]] [[DIK_KeyCodes|DIK Key Codes]] [[keyName]]
}}
}}


<h3 style='display:none'>Notes</h3>
{{Note
<dl class='command_description'>
|user= Axyl
<!-- Note Section BEGIN -->
|timestamp= 20140310145200
<dd class="notedate">Posted on October 30, 2013 - 11:14
|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 class="note">'''[[User:Killzone_Kid|Killzone_Kid]]'''<dd class="note">As of Arma 3 v1.05.111658 [[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
<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>


<!-- Note Section END -->
{{Note
</dl>
|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>
}}


<h3 style='display:none'>Bottom Section</h3>
{{Note
[[Category:ArmA 2: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
|user= Nelis.75733126
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
|timestamp= 20170528113200
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
|text= use ({{Link|https://community.bistudio.com/wiki/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|https://community.bistudio.com/wiki/format|format}} to the second parameter.
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
}}
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_Interaction|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_GUI_Control|{{uc:{{PAGENAME}}}}]]


{{Note
|user= DrSova
|timestamp= 20170807150800
|text= Using '''KeyUp''' you can't override default engine action by returning '''true'''
|game= arma3
|version= 1.72
}}


 
{{Note
<!-- CONTINUE Notes -->
|user= R3vo
<dl class="command_description">
|timestamp= 20210626161700
<dd class="notedate">Posted on January 22, 2016 - 08:15 (UTC)</dd>
|text= To prevent a display from getting closed by pressing ESC, add the following event handler.
<dt class="note">[[User:Pigneedle|Pigneedle]]</dt>
<sqf>
<dd class="note">
#include "\a3\ui_f\hpp\definedikcodes.inc"
Be sure to wait until the main display is initialized before using this command by using: <code>waituntil {!isnull (finddisplay 46)};</code>
_display displayAddEventHandler ["KeyDown",
</dd>
{
</dl>
params ["", "_key"];
<!-- DISCONTINUE Notes -->
_key == DIK_ESC; // ESC pressed while dialog is open, overwrite default behaviour
 
}];
<!-- CONTINUE Notes -->
</sqf>
<dl class="command_description">
}}
<dd class="notedate">Posted on May 28, 2017 - 11:32 (UTC)</dd>
<dt class="note">[[User:IT07|IT07]]</dt>
<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.
However, that does not work if you use STRING as 'code'. In case of STRING, use the format command around it.
</dd>
</dl>
<!-- DISCONTINUE Notes -->
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on August 7, 2017 - 15:08 (UTC)</dd>
<dt class="note">[[User:DrSova|DrSova]]</dt>
<dd class="note">
Using '''KeyUp''' you can't override default engine action by returning '''true''' ('''A3 1.72.142342''')
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 20:15, 16 April 2024

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. 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:
moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", "hint str _this;"];
Example 2:
moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", { hint str _this }];

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
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:
Nelis.75733126 - c
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.
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 }];