{"name":"displaySetEventHandler","operator":null,"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","replaced_by":[],"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":"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.\n\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]","since":null,"effect":null,"exec":null,"params":[{"name":"display","type":"Display","optional":false,"default":null,"description":null,"types":["Display"],"since":null,"text":"display: Display"},{"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":"code","types":["String"],"since":null,"text":"function: String - code"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"display","types":["Display"]},"right":{"text":"[handlerName, function]","types":["Array"]}}],"examples":[{"text":"```sqf\n_control displaySetEventHandler [\"KeyDown\", \"\"];\n```","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;"]}],"multiplayer":null,"problems":null,"aliases":[],"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."}],"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"]}