User Interface Event Handlers
Overview
User Interface Event handlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.
Event parameters
The events handlers receive parameters in the _this variable. Each event passes a different set of parameters (listed in the table below) in an array. The control or display that the event was assigned to is always found in (_this select 0).
Scope
In ArmA, most control-specific events work for controls and do not work for displays. The 2 exceptions being: onKeyDown and onKeyUp.
Since Arma 2, most control-specific events now work for both displays and controls.
Defining events
User Interface Event Handlers can be assigned in two ways: via class property definitions or via scripting commands.
Class defined events
Events can be defined in the Dialog (display) or Control classes (in config.cpp or description.ext). The event property value (string) is executed as a line of code. An example line (this would be put within a control or dialog class):
onMouseDown = "hint str _this";
Example:
class RscControlsGroup { type = 15; idc = -1; style = 0; x = 0; y = 0; w = 1; h = 1; class VScrollbar { color[] = {1, 1, 1, 1}; width = 0.021; }; class HScrollbar { color[] = {1, 1, 1, 1}; height = 0.028; }; class Controls {}; }; class mouseHandler: RscControlsGroup { onMouseHolding = "[0,_this] call Axx"; onMouseButtonDown = "[1,_this] call Axx"; onMouseButtonUp = "[2,_this] call Axx"; onMouseZChanged = "[3,_this] call Axx"; onMouseEnter = "[4,_this] call Axx"; idc = 123; x = 0.0; y = 0.0; w = 1.0; h = 1.0; colorBackground[] = {0.2, 0.0, 0.0, 0.0}; };
Script defined events
These events can also be given to dialogs/controls using the ctrlSetEventHandler scripting command. For the event handler to be called enable the control using the ctrlEnable scripting command.
Important Note: When using the event names listed below with the ctrlSetEventHandler command, the prefix "on" in the name is not required and must be removed. (e.g. 'ButtonDown' instead of 'onButtonDown')
(findDisplay 46) displayAddEventHandler ["keyDown", "_this call functionName_keyDown"];
functionName_keyDown = { private["_handled", "_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"]; _ctrl = _this select 0; _dikCode = _this select 1; _shift = _this select 2; _ctrlKey = _this select 3; _alt = _this select 4; _handled = false; if (!_shift && !_ctrlKey && !_alt) then { if (_dikCode in (actionKeys "NetworkStats")) then { nul = [] execVM "path\script.sqf"; _handled = true; }; }; _handled; };
Reference List
Priority | Event | Fired | Notes and Parameters | Scope |
---|---|---|---|---|
1 | onLoad | Display and all controls are created, but no action on any is taken. | Returns the display. | Display |
1 | onUnload | Display is closed, but no controls are destroyed yet. | Returns the display and exit code. | Display |
1 | onChildDestroyed | Child display is closed. | Returns the display, which child display was closed and exit code. | Display |
1 | onMouseEnter | The mouse pointer enters the control area. | Returns control. | Control |
1 | onMouseExit | The mouse pointer exits the control area. | Returns control. | Control |
2 | onSetFocus | Input focus is on control. It now begins to accept keyboard input. | Returns control. | Control |
2 | onKillFocus | Input focus is no longer on control. It no longer accepts keyboard input. | Returns control. | Control |
3 | onTimer | After amount of time given by setTimer function. | Returns control. | Control |
2 | onKeyDown | Pressing any keyboard key. Fired before the onKeyUp event. | Returns the control, the keyboard code and the state of Shift, Ctrl and Alt. | Display, Control |
2 | onKeyUp | Releasing any keyboard key. Fired after the onKeyDown event. | Returns the control, the keyboard code and the state of Shift, Ctrl and Alt. | Display, Control |
2 | onChar | When some readable characters is recognised. | Returns the control and the char code. | Control |
2 | onIMEChar | When IME character is recognized (used in Korean and other eastern languages). | Returns the control and the char code. | Control |
2 | onIMEComposition | When partial IME character is recognized (used in Korean and other eastern languages). | Returns the control and the char code. | Control |
3 | onJoystickButton | Pressing and releasing any joystick button. | Returns the control and the the pressed button. | Control |
2 | onMouseButtonDown | Pressing a mouse button. Followed by the onMouseButtonUp event. | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt. | Control |
2 | onMouseButtonUp | Releasing a mouse button. Follows the onMouseButtonDown event. | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt. | Control |
2 | onMouseButtonClick | Pressing and releasing a mouse button. | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt. | ListBox, ComboBox, TextBox, Button, ActiveText |
2 | onMouseButtonDblClick | Pressing and releasing a mouse button twice within very short time. | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt. | Control |
2 | onMouseMoving | Fires continuously while moving the mouse with a certain interval. | Returns the control, the x and y screen coordinates and mouseOver. | Control |
Returns the display, the x and y delta postition. | Display | |||
2 | onMouseHolding | Fires continuously while mouse is not moving with a certain interval. | Returns the control, the x and y coordinates and mouseOver. If used with a display, the mouseOver parameter is excluded. | Control |
2 | onMouseZChanged | Fires when mouse wheel position is changed. | Returns the control and the change of the scrollbar. | Control only |
3 | onCanDestroy | Ask this control if dialog can be closed (used for validation of contained data). | Returns the control and exit code. | Control |
3 | onDestroy | Destroying control | Returns the control and exit code. | Control |
1 | onButtonClick | The attached button action is performed. | Returns control. | Button |
1 | onButtonDown | The left mouse button is pressed over the button area or a key on the keyboard is pressed. | Returns control. | Button |
1 | onButtonUp | The left mouse buttons is released outside the button area and the attached button action is not performed. | Returns control. | Button |
2 | onLBSelChanged | The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made. | Returns the control and the selected element index. | Listbox |
2 | onLBListSelChanged | Selection in XCombo box changed (but value is not stored yet). | Returns the control and the selected element index. | Listbox |
2 | onLBDblClick | Double click on some row in listbox. | Returns the control and the selected element index. | Listbox |
2 | onLBDrag | Drag & drop operation started. | Returns the control and the selected element index. | Listbox |
2 | onLBDragging | Drag & drop operation is in progress. | Returns the control and the x and y coordinates. | Listbox |
2 | onLBDrop | Drag & drop operation finished. | Returns the control and the x and y coordinates. | Listbox, Combobox, Textbox, ActiveText, Button |
2 | onTreeSelChanged | Changing the selection in a tree. | Returns the control. | Tree |
2 | onTreeDblClick | Pressing and releasing twice on a tree. | Returns the control. | Tree |
3 | onTreeExpanded | The tree folder structure has been expanded. | Returns the control. | Tree |
3 | onTreeCollapsed | The tree folder structure has been collapsed. | Returns the control. | Tree |
2 | onToolBoxSelChanged | Changed the selection in a toolbox. | Returns the control and the selected element index. | Toolbox |
2 | onCheckBoxesSelChanged | Changed the selection in a checkbox. | Returns the control, the selected element index and the current state. | Checkbox |
2 | onHTMLLink | Pressing and releasing a HTML link. | Returns the control and href. | HTML |
2 | onSliderPosChanged | Changing the position of a slider. | Returns the control and the change. | Slider |
2 | onObjectMoved | Moving an object. | Returns the control and the offset on the x,y and z axes. | Object |
2 | onMenuSelected | Some item in context menu (used now only in new mission editor) was selected. | Returns the control and the command id. | Context menu |