---
name: "ctrlSetEventHandler"
type: command
status: deprecated
replaced_by: ["ctrlAddEventHandler"]
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/ctrlSetEventHandler
revid: 369343
updated: 2024-09-03T18:43:02Z
---

# ctrlSetEventHandler

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

> [!WARNING]
> This command is deprecated. Use [ctrlAddEventHandler](../commands/ctrlAddEventHandler.md) instead.

## Description

> [!CAUTION]
> This information is **obsolete**. Use [ctrlAddEventHandler](../commands/ctrlAddEventHandler.md) instead as it can stack event handlers.

Sets given event handler of given control: any previously added event handler is removed.

> [!NOTE]
> - See [User Interface Event Handlers](../topics/User_Interface_Event_Handlers.md) for the full list of handler names
> - See also DIK KeyCodes for a list of key code constants relevant to key-related events like [KeyDown](../topics/User_Interface_Event_Handlers.md#onkeydown) and [KeyUp](../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
controlName ctrlSetEventHandler [handlerName, function]
```

**Parameters:**

- `controlName`: [Control](../topics/Control.md)
- `handlerName`: [String](../topics/String.md)
- `function`: [String](../topics/String.md) - should return a [Boolean](../topics/Boolean.md) indicating that the event has handled this event fully or not and whether the engine should execute its default code or not afterwards

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

## Examples

### Example 1

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

### Example 2

```sqf
(_display displayCtrl 108) ctrlSetEventHandler ["LBSelChanged","['ListChange',_this] call FireEvents"];
```

## See also

[displaySetEventHandler](../commands/displaySetEventHandler.md) · [ctrlAddEventHandler](../commands/ctrlAddEventHandler.md) · [ctrlRemoveEventHandler](../commands/ctrlRemoveEventHandler.md) · [User Interface Event Handlers](../topics/User_Interface_Event_Handlers.md) · DIK KeyCodes

## Community notes

**pierremgi** — 2021-04-28

This command doesn't work on map.

```sqf
waitUntil { !isNull (findDisplay 12 displayCtrl 51) };
(findDisplay 12 displayCtrl 51) ctrlSetEventHandler ["MouseButtonDblClick", "hint str _this; true"]; // doesn't skip the marker dialog as it should.
```

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