User Interface Event handlers allow you to automatically monitor and then execute custom code upon particular UI events being triggered.
Reference List[]
! | When using the event names listed below with the ctrlAddEventHandler, ctrlSetEventHandler, displayAddEventHandler or displaySetEventHandler commands, the prefix "on" in the name must be removed. (e.g. 'ButtonDown' instead of 'onButtonDown') |
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. | Not in Arma 2 or Arma 3 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 coordinates relative to control and mouseOver. | Control |
Returns the display, the some kind of x and y delta position. | 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. Does not fire on disabled control. Checked with CT_EDIT type in v1.50. | 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. When returned value is true, button's display remains opened. | Returns control. | Button |
? | onButtonDblClick | ? | Arma 3 | 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 and the new selection path. | Tree |
2 | onTreeLButtonDown | Pressing and releasing left mouse button on a tree. | Returns the control. | Tree |
2 | onTreeDblClick | Pressing and releasing twice on a tree entry. | Returns the control and the current selection path. | 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 | onTreeMouseMove | Fires continuously while moving the mouse with a certain interval. | Returns the control. | Tree |
2 | onTreeMouseHold | Fires continuously while mouse is not moving with a certain interval. | Returns the control. | Tree |
2 | onTreeMouseExit | The mouse pointer exits the tree control area | Returns the control. | Tree |
2 | onToolBoxSelChanged | Changed the selection in a toolbox. | Returns the control and the selected element index. | Toolbox |
? | onChecked | ? | Arma 3 | Checkbox |
? | onCheckedChanged | Checked state of CheckBox changed. | Arma 3. Returns control and the checked state. | Checkbox |
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 |
? | onDraw | Fires when the map is drawn (can occur more than once per second). | Returns the map control. | Map |
2 | onVideoStopped | Activated every time video ends (when looped, handler is executed after every finished loop). |
Returns the control | Control |
Event parameters[]
The events handlers receive parameters in the _this variable. Each event passes a different set of parameters (listed in the table above) 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.021000;
autoScrollSpeed = -1;
autoScrollDelay = 5;
autoScrollRewind = 0;
};
class HScrollbar {
color[] = {1, 1, 1, 1};
height = 0.028;
};
class ScrollBar { //for ARMA 2
color[] = {1,1,1,0.600000};
colorActive[] = {1,1,1,1};
colorDisabled[] = {1,1,1,0.300000};
thumb = "#(argb,8,8,3)color(1,1,1,1)";
arrowEmpty = "#(argb,8,8,3)color(1,1,1,1)";
arrowFull = "#(argb,8,8,3)color(1,1,1,1)";
border = "#(argb,8,8,3)color(1,1,1,1)";
};
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.
(findDisplay 46) displayAddEventHandler ["keyDown", "_this call functionName_keyDown"];
functionName_keyDown = {
params ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
private _handled = false;
if (!_shift && !_ctrlKey && !_alt) then {
if (_dikCode in (actionKeys "NetworkStats")) then {
[] execVM "path\script.sqf";
_handled = true;
};
};
_handled;
};
Demo mission[]
For VBS2 users, a demo mission is available here.