{"name":"ctrlSetEventHandler","operator":null,"title":"ctrlSetEventHandler","type":"command","url":"https://community.bistudio.com/wiki/ctrlSetEventHandler","revid":369343,"updated":"2024-09-03T18:43:02Z","groups":["GUI Control - Event Handlers","Event Handlers"],"status":"deprecated","replaced_by":["ctrlAddEventHandler"],"games":[{"game":"arma1","name":"Armed Assault","version":"1.00"},{"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":"arma1","name":"Armed Assault","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"> [!CAUTION]\n> This information is **obsolete**. Use ctrlAddEventHandler instead as it can stack event handlers.\n\nSets given event handler of given control: any previously added event handler is removed.\n\n> [!NOTE]\n> - See User Interface Event Handlers for the full list of handler names\n> - See also DIK KeyCodes for a list of key code constants relevant to key-related events like KeyDown and KeyUp\n\n> [!IMPORTANT]\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":"controlName ctrlSetEventHandler [handlerName, function]","since":null,"effect":null,"exec":null,"params":[{"name":"controlName","type":"Control","optional":false,"default":null,"description":null,"types":["Control"],"since":null,"text":"controlName: Control"},{"name":"handlerName","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"handlerName: String"},{"name":"function","type":"String","optional":false,"default":null,"description":"should return a Boolean indicating that the event has handled this event fully or not and whether the engine should execute its default code or not afterwards","types":["String"],"since":null,"text":"function: String - should return a Boolean indicating that the event has handled this event fully or not and whether the engine should execute its default code or not afterwards"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"controlName","types":["Control"]},"right":{"text":"[handlerName, function]","types":["Array"]}}],"examples":[{"text":"```sqf\n_control ctrlSetEventHandler [\"KeyDown\", \"\"];\n```","code":["_control ctrlSetEventHandler [\"KeyDown\", \"\"];"]},{"text":"```sqf\n(_display displayCtrl 108) ctrlSetEventHandler [\"LBSelChanged\",\"['ListChange',_this] call FireEvents\"];\n```","code":["(_display displayCtrl 108) ctrlSetEventHandler [\"LBSelChanged\",\"['ListChange',_this] call FireEvents\"];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["displaySetEventHandler","ctrlAddEventHandler","ctrlRemoveEventHandler","User Interface Event Handlers","DIK KeyCodes"],"notes":[{"user":"pierremgi","date":"2021-04-28T19:59:00Z","text":"This command doesn't work on map.\n\n```sqf\nwaitUntil { !isNull (findDisplay 12 displayCtrl 51) };\n(findDisplay 12 displayCtrl 51) ctrlSetEventHandler [\"MouseButtonDblClick\", \"hint str _this; true\"]; // doesn't skip the marker dialog as it should.\n```"}],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: 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 Armed Assault version 1.00","Scripting Commands","Take On Helicopters: Scripting Commands"]}