displaySetEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<code>([^<]*)\[\[([a-zA-Z][a-zA-Z0-9_]+)\]\]([^<]*) *<\/code>" to "<code>$1$2$3</code>")
m (Text replacement - "<code>([^<]*)\[\[([a-zA-Z][a-zA-Z0-9_]+)\]\]([^<]*) *<\/code>" to "<code>$1$2$3</code>")
Line 38: Line 38:
|x1= <code>_control displaySetEventHandler ["KeyDown", ""];</code>
|x1= <code>_control displaySetEventHandler ["KeyDown", ""];</code>
|x2= init.sqf<code>KeysPressed = compile preprocessFile "keysPressed.sqf";
|x2= init.sqf<code>KeysPressed = compile preprocessFile "keysPressed.sqf";
private _display = [[findDisplay]] 46;
private _display = findDisplay 46;
_display [[displaySetEventHandler]] ["KeyDown", "_this call keyspressed"];</code>
_display [[displaySetEventHandler]] ["KeyDown", "_this call keyspressed"];</code>


keyspressed.sqf<code>private _handled = [[false]];
keyspressed.sqf<code>private _handled = false;
[[switch]] (_this [[select]] 1) [[do]]
[[switch]] (_this [[select]] 1) [[do]]
{
{

Revision as of 13:02, 12 May 2022

Hover & click on the images for description

Description

Description:
Sets given event handler of given display. The 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. See User Interface Event Handlers for the full list of handler names.
If applicable, see DIK_KeyCodes for a list of key code constants, which are relevant to key related user interface events like: KeyDown & KeyUp.
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').
Groups:
GUI Control - Event HandlersEvent Handlers

Syntax

Syntax:
display displaySetEventHandler [handlerName, function]
Parameters:
display: Display
handlerName: String
function: String - code
Return Value:
Nothing

Examples

Example 1:
_control displaySetEventHandler ["KeyDown", ""];
Example 2:
init.sqfKeysPressed = compile preprocessFile "keysPressed.sqf"; private _display = findDisplay 46; _display displaySetEventHandler ["KeyDown", "_this call keyspressed"]; keyspressed.sqfprivate _handled = false; switch (_this select 1) do { // F key case 33: { // code here _handled = true; }; }; _handled;

Additional Information

See also:
ListOfKeyCodes displayAddEventHandler displayRemoveEventHandler displayRemoveAllEventHandlers ctrlSetEventHandler UI Event Handlers DIK KeyCodes keyName

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Posted on Nov 25, 2009
kju
Always use displayAddEventHandler instead, as DSetEH overwrites other (peoples') DEH.