displayAddEventHandler

From Bohemia Interactive Community
Revision as of 00:58, 4 November 2015 by PierreMGI (talk | contribs)
Jump to navigation Jump to search
Hover & click on the images for description

Description

Description:
Adds an event handler to the given display. Returns the ID of the event handler, or -1 when failed.
Returning true in EH code will override default engine handling for keyboard events.
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:
Uncategorised

Syntax

Syntax:
display displayAddEventHandler [eventName, code]
Parameters:
display: Display
[eventName, code]: Array
eventName: String
code: String or Code
Return Value:
Number

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

Notes

Posted on October 30, 2013 - 11:14
Killzone_Kid
As of Arma 3 v1.05.111658 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. eg[] spawn { (findDisplay 46) displayAddEventHandler["KeyDown","_this call my_KeyDownFunctionhandler"]; };

Bottom Section

Posted on April 20, 2015 - 15:07 (UTC)
IT07
If you have a file in which there are variables defined that provide the key that triggers the eventHandler or variables that need to be passed onto the function called by the eventHandler if the if condition inside returns true, use this: _myCuteLittleEvent = (findDisplay 46) displayAddEventHandler ["KeyDown", " _keyDown = _this select 1; if (_keyDown == " + str (_key) + ") then { [" + str _arguments + "] call fnc_myFunction }; false; "]; where _key is a var containing the DIK keycode for the key you want to use and where _arguments is a variable that contains stuff that needs to be passed onto fnc_myFunction.
Posted on November 11, 2015 - 02:56 (UTC)
Pierre MGI
FindDisplay only finds present display. So, don't try to use this command if you're out of this display context, and as Axyl said, in a scheduled event For example, in init.sqf: 0 = [] spawn { waituntil {!isNull (findDisplay 46)}; keys = (findDisplay 46) displayAddEventHandler ["keyDown", "_this call my_keys"]; };