Arma 3 Scripting

Command in GUI Control - Event Handlers, Event Handlers

displayAddEventHandler

Also available as Markdown and JSON, or read the original wiki page.

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.

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 _thisEventHandler magic variable.

Syntax

display displayAddEventHandler [eventName, code]

Parameters:

Returns: 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 }];

See also

disableSerialization · displayRemoveAllEventHandlers · displayRemoveEventHandler · displaySetEventHandler · ctrlAddEventHandler · User Interface Event Handlers · findDisplay · DIK KeyCodes · keyName

Community notes

Axyl

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"]; };
Pigneedle

Be sure to wait until the main display is initialized before using this command by using:

waitUntil { !isNull (findDisplay 46) };
Nelis75733126

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

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

R3vo

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
}];