{"name":"displaySetEventHandler","title":"displaySetEventHandler","type":"command","url":"https://community.bistudio.com/wiki/displaySetEventHandler","revid":369398,"updated":"2024-09-03T18:43:19Z","groups":["GUI Control - Event Handlers","Event Handlers"],"status":"ok","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":"Sets given event handler of given display.\nThe 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.\nSee User Interface Event Handlers for the full list of handler names.\nIf applicable, see DIK KeyCodes for a list of key code constants, which are relevant to key related user interface events like onKeyDown and onKeyUp.\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":"display displaySetEventHandler [handlerName, function]","params":[{"name":"display","type":"Display","type_expr":"Display"},{"name":"handlerName","type":"String","type_expr":"String"},{"name":"function","type":"String","description":"code","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"display"},"right":{"text":"[handlerName, function]"}}],"examples":[{"code":["_control displaySetEventHandler [\"KeyDown\", \"\"];"]},{"text":"`init.sqf`:\n\n```sqf\nKeysPressed = compile preprocessFile \"keysPressed.sqf\";\nprivate _display = findDisplay 46;\n_display displaySetEventHandler [\"KeyDown\", \"_this call KeysPressed\"];\n```\n\n`keysPressed.sqf`:\n\n```sqf\nprivate _handled = false;\nswitch (_this select 1) do {\n    // F key\n    case 33: {\n        // code here\n        _handled = true;\n    };\n};\n_handled;\n```","code":["KeysPressed = compile preprocessFile \"keysPressed.sqf\";\nprivate _display = findDisplay 46;\n_display displaySetEventHandler [\"KeyDown\", \"_this call KeysPressed\"];","private _handled = false;\nswitch (_this select 1) do {\n\t// F key\n\tcase 33: {\n\t\t// code here\n\t\t_handled = true;\n\t};\n};\n_handled;"]}],"see_also":["ListOfKeyCodes","displayAddEventHandler","displayRemoveEventHandler","displayRemoveAllEventHandlers","ctrlSetEventHandler","User Interface Event Handlers","DIK KeyCodes","keyName"],"notes":[{"user":"WGL.Q","date":"2009-11-25T18:02:00Z","text":"Always use displayAddEventHandler instead, as displaySetEventHandler **overwrites** other (peoples') DEH."}]}