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"]; };
Command in GUI Control - Event Handlers, Event Handlers
Also available as Markdown and JSON, or read the original wiki page.
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.
Important
Display EHs are processed from last to first added; an input override should be set up in the first added EH.
Note
The event handler ID can be accessed inside the event handler code using the
_thisEventHandlermagic variable.
display displayAddEventHandler [eventName, code]
Parameters:
display: Display
eventName: String - event name
Important
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 v1.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:
_this_thisEvent_thisEventHandlerReturns: Number - index of the newly added event handler or -1 if creation failed
moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", "hint str _this;"];
moduleName_keyDownEHId = findDisplay 46 displayAddEventHandler ["KeyDown", { hint str _this }];
disableSerialization · displayRemoveAllEventHandlers · displayRemoveEventHandler · displaySetEventHandler · ctrlAddEventHandler · User Interface Event Handlers · findDisplay · DIK KeyCodes · keyName
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"]; };
Be sure to wait until the main display is initialized before using this command by using:
waitUntil { !isNull (findDisplay 46) };
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.
Using KeyUp you can't override default engine action by returning true
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
}];