{"name":"ctrlAddEventHandler","operator":null,"title":"ctrlAddEventHandler","type":"command","url":"https://community.bistudio.com/wiki/ctrlAddEventHandler","revid":376337,"updated":"2025-10-07T13:17:20Z","groups":["GUI Control - Event Handlers","Event Handlers"],"status":"ok","replaced_by":[],"games":[{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2","name":"Arma 2","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Add an event handler to the given control.\n\n> [!IMPORTANT]\n> - Control event handlers are processed in reversed order, i.e. last added: first, first added: last. So if you have an override it should be set up in the 1st added EH.\n> - 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**').","syntaxes":[{"syntax":"control ctrlAddEventHandler [handler, function]","since":null,"effect":null,"exec":null,"params":[{"name":"control","type":"Control","optional":false,"default":null,"description":null,"types":["Control"],"since":null,"text":"control: Control"},{"name":"handler","type":"String","optional":false,"default":null,"description":"handler name, see User Interface Event Handlers","types":["String"],"since":null,"text":"handler: String - handler name, see User Interface Event Handlers"},{"name":"function","type":"String, since Arma 3 v1.06 also Code","optional":false,"default":null,"description":"script. Several Magic Variables are available:\n- Event Handler parameters are accessible via `_this`\n- The Event Handler type is available as `_thisEvent`\n- The Event Handler index is available as `_thisEventHandler`","types":["String","Code"],"since":null,"text":"function: String, since Arma 3 v1.06 also Code - script. Several Magic Variables are available:\n- Event Handler parameters are accessible via `_this`\n- The Event Handler type is available as `_thisEvent`\n- The Event Handler index is available as `_thisEventHandler`"}],"returns":{"type":"Number","types":["Number"],"description":"handler ID or -1 if failed","text":"Number - handler ID or -1 if failed"},"form":"binary","operator":null,"left":{"text":"control","types":["Control"]},"right":{"text":"[handler, function]","types":["Array"]}}],"examples":[{"text":"```sqf\n_map ctrlAddEventHandler [\"Draw\", \"_this call BIS_fnc_strategicMapOpen_draw\"];\n```","code":["_map ctrlAddEventHandler [\"Draw\", \"_this call BIS_fnc_strategicMapOpen_draw\"];"]},{"text":"```sqf\n_map ctrlAddEventHandler [\"Draw\", { hintSilent str _this }];\n```","code":["_map ctrlAddEventHandler [\"Draw\", { hintSilent str _this }];"]},{"text":"```sqf\nfindDisplay 12 displayCtrl 51 ctrlAddEventHandler [\"Draw\", { hintSilent str _this }]; //Arma 3 map control\n```","code":["findDisplay 12 displayCtrl 51 ctrlAddEventHandler [\"Draw\", { hintSilent str _this }]; //Arma 3 map control"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["displayAddEventHandler","ctrlRemoveEventHandler","ctrlRemoveAllEventHandlers"],"notes":[],"categories":["Arma 2: New Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Event Handlers","Command Group: GUI Control - Event Handlers","Introduced with Arma 2 version 1.00","Scripting Commands","Take On Helicopters: Scripting Commands"]}