{"name":"ctrlSetEventHandler","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":{"arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma1 1.00","arma3_since":"0.50","description":"> [!CAUTION]\n> This information is **obsolete** as of Arma 2 v1.00. Reason: 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]","params":[{"name":"controlName","type":"Control","type_expr":"Control"},{"name":"handlerName","type":"String","type_expr":"String"},{"name":"function","type":"String","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","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"controlName"},"right":{"text":"[handlerName, function]"}}],"examples":[{"code":["_control ctrlSetEventHandler [\"KeyDown\", \"\"];"]},{"code":["(_display displayCtrl 108) ctrlSetEventHandler [\"LBSelChanged\",\"['ListChange',_this] call FireEvents\"];"]}],"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```"}]}