---
name: "displaySetEventHandler"
type: command
status: ok
groups: ["GUI Control - Event Handlers", "Event Handlers"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/displaySetEventHandler
revid: 369398
updated: 2024-09-03T18:43:19Z
---

# displaySetEventHandler

*Command · GUI Control - Event Handlers, Event Handlers · Arma 3 v0.50 · introduced in Armed Assault v1.00*

## Description

Sets given event handler of given display.
The return code of the provided function should indicate whether this event was handled correctly. This implies telling the engine whether it is default code should be executed.
See [User Interface Event Handlers](../topics/User_Interface_Event_Handlers.md) for the full list of handler names.

If applicable, see DIK KeyCodes for a list of key code constants, which are relevant to key related user interface events like [onKeyDown](../topics/User_Interface_Event_Handlers.md#onkeydown) and [onKeyUp](../topics/User_Interface_Event_Handlers.md#onkeyup).

> [!IMPORTANT]
> When using the event names listed [here](../topics/User_Interface_Event_Handlers.md) with the [ctrlAddEventHandler](../commands/ctrlAddEventHandler.md), [ctrlSetEventHandler](../commands/ctrlSetEventHandler.md), [displayAddEventHandler](../commands/displayAddEventHandler.md) or [displaySetEventHandler](../commands/displaySetEventHandler.md) commands, the prefix "on" in the event name must be removed (e.g. **'ButtonDown**' instead of **'onButtonDown**').

## Syntax

```sqf
display displaySetEventHandler [handlerName, function]
```

**Parameters:**

- `display`: [Display](../topics/Display.md)
- `handlerName`: [String](../topics/String.md)
- `function`: [String](../topics/String.md) - code

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
_control displaySetEventHandler ["KeyDown", ""];
```

### Example 2

`init.sqf`:

```sqf
KeysPressed = compile preprocessFile "keysPressed.sqf";
private _display = findDisplay 46;
_display displaySetEventHandler ["KeyDown", "_this call KeysPressed"];
```

`keysPressed.sqf`:

```sqf
private _handled = false;
switch (_this select 1) do {
    // F key
    case 33: {
        // code here
        _handled = true;
    };
};
_handled;
```

## See also

ListOfKeyCodes · [displayAddEventHandler](../commands/displayAddEventHandler.md) · [displayRemoveEventHandler](../commands/displayRemoveEventHandler.md) · [displayRemoveAllEventHandlers](../commands/displayRemoveAllEventHandlers.md) · [ctrlSetEventHandler](../commands/ctrlSetEventHandler.md) · [User Interface Event Handlers](../topics/User_Interface_Event_Handlers.md) · DIK KeyCodes · [keyName](../commands/keyName.md)

## Community notes

**WGL.Q** — 2009-11-25

Always use [displayAddEventHandler](../commands/displayAddEventHandler.md) instead, as [displaySetEventHandler](../commands/displaySetEventHandler.md) **overwrites** other (peoples') DEH.

<sub>Source: [BI Community Wiki — displaySetEventHandler](https://community.bistudio.com/wiki/displaySetEventHandler) (revision 369398).</sub>
