User Interface Event Handlers: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (categorized)
m (Text replacement - "{{Feature|Informative|" to "{{Feature|informative|")
(143 intermediate revisions by 30 users not shown)
Line 1: Line 1:
===Basic Overview===
__NOEDITSECTION__
{{TOC|side}}
User Interface Event Handlers are used to execute code when events related to GUI components (i.e. [[Display]]s and [[Control]]s) occur.


User Interface Event Handlers are given as values in the Dialog/Control description classes.
{{Feature|warning|Deleting a display or control from within a UI Event Handler will crash the game if deleting is not the last line in the Event Handler's script. Alternatively, the code can also be [[Scheduler|spawned]] to circumvent this issue.
<syntaxhighlight lang="cpp">
onButtonClick = "ctrlDelete (_this select 0); systemChat 'You will never see this';"; // Crashes the game
onButtonClick = "systemChat 'Bye bye button!'; ctrlDelete (_this select 0);"; // Works fine
onButtonClick = "_this spawn { ctrlDelete (_this select 0); systemChat 'Bye bye button!'; };"; // Works fine
</syntaxhighlight>
}}


===Reference List===


{| border="1"
== Reference List ==
! Priority
 
! Event
=== Generic Events ===
! Fired
 
! Notes
<div><!-- Used to limit Sticky range -->
! Scope
{{ConfigPage|start}}
|-
{{ConfigPage|abc}}
| class="priority" | 1
==== onLoad ====
|  class="event" | onLoad
* '''Use on:''' Display, Control
|  class="fired" | Display and all controls are created, but no action on any is taken.
* '''Fired on:''' Fires when UI container is created, but no action is taken. The {{hl|onLoad}} event for display fires '''after''' the {{hl|onLoad}} events for all controls it contains are fired.
| class="notes" | Returns the display.
* '''Returns:''' Display or control, for controls it also returns the control's config (since {{GVI|arma3|1.56}}).
|  class="scope" | Display
<sqf>params ["_displayOrControl", ["_config", configNull]];</sqf>
|-
{{Feature|informative|The order of initialisation is as follows:
| class="priority" | 1
# Topmost config class (control class)
|  class="event" | onUnload
# Last config class
| class="fired" | Display is closed, but no controls are destroyed yet.
# Display
class="notes" | Returns the display and exit code.
This means that during the {{hl|onLoad}} event of the upper controls the lower controls do not exist!}}
class="scope" | Display
 
|-
==== onUnload ====
|  class="priority" | 1
* '''Use on:''' Display
|  class="event" | onChildDestroyed
* '''Fired on:''' Display is closed, but no controls are destroyed yet.
|  class="fired" | Child display is closed.
* '''Returns:''' Returns the display and exit code.
|  class="notes" | Returns the display, which child display was closed and exit code.
<sqf>params ["_display", "_exitCode"];</sqf>
|  class="scope" | Display
{{Feature | Informative | The {{hl|onUnload}} event does not fire for RscTitles displays created with [[cutRsc]].}}
|-
{{Feature | Warning | Code or function should be [[call]]ed, otherwise controls might be destroyed before [[spawn]]ed code is executed!}}
| class="priority" | 1
 
|  class="event" | onMouseEnter
==== onChildDestroyed ====
| class="fired" | The mouse pointer enters the control area.
* '''Use on:''' Display
|  class="notes" | Returns control.
* '''Fired on:''' Child display is closed.
|  class="scope" | Control
* '''Returns:''' Returns the display, which child display was closed and exit code.
|-
<sqf>params ["_display", "_closedChildDisplay", "_exitCode"];</sqf>
|  class="priority" | 1
 
|  class="event" | onMouseExit
{{ArgTitle|4|onCommitted|{{GVI|arma3|2.14}}}}
|  class="fired" | The mouse pointer exits the control area.
* '''Use on:''' Control
|  class="notes" | Returns control.
* '''Fired on:''' [[ctrlSetFade]], [[ctrlSetScale]], [[ctrlSetAngle]] and [[ctrlSetPosition]] in combination with [[ctrlCommit]].
|  class="scope" | Control
* '''Returns:''' Returns the control, type of animation ({{hl|"alpha"}}, {{hl|"scale"}}, {{hl|"rotation"}} or {{hl|"position"}}) and the committed time.
|-
<sqf>params ["_control", "_animType", "_animTime"];</sqf>
| class="priority" | 2
 
| class="event" | onSetFocus
{{ArgTitle|4|onEditChanged|{{GVI|arma3|2.14}}}}
| class="fired" | Input focus is on control. It now begins to accept keyboard input.
* '''Use on:''' Control
|  class="notes" | Returns control.
* '''Fired on:''' Any changes to the [[CT_EDIT]] text field content.
| class="scope" | Control
* '''Returns:''' Returns the control and the changed text.
|-
<sqf>params ["_control", "_newText"];</sqf>
| class="priority" | 2
 
|  class="event" | onKillFocus
==== onMouseEnter ====
|  class="fired" | Input focus is no longer on control. It no longer accepts keyboard input.
* '''Use on:''' Control
|  class="notes" | Returns control.
* '''Fired on:''' The mouse pointer enters the control area.
| class="scope" | Control
* '''Returns:''' Returns control.
|-
<sqf>params ["_control"];</sqf>
| class="priority" | 3
{{Feature | Informative | The {{hl|onMouseEnter}} event does not fire for disabled buttons (see [[ctrlEnable]]).}}
|  class="event" | onTimer
 
|  class="fired" | After amount of time given by setTimer function.
==== onMouseExit ====
|  class="notes" | Returns control.
* '''Use on:''' Control
|  class="scope" | Control
* '''Fired on:''' The mouse pointer exits the control area.
|- <span idonKeyDown"/>
* '''Returns:''' Returns control.
|  class="priority" | 2
<sqf>params ["_control"];</sqf>
|  class="event" | onKeyDown
 
|  class="fired" | Pressing any keyboard key. Fired before the [[#onKeyUp|onKeyUp]] event.
==== onSetFocus ====
|  class="notes" | Returns the control, the code of the keyboard key and the state of Shift, Ctrl and Alt.
* '''Use on:''' Control
| class="scope" | Control
* '''Fired on:''' Input focus is on control. It now begins to accept keyboard input.
|- <span idonKeyUp"/>
* '''Returns:''' Returns control.
|  class="priority" | 2
<sqf>params ["_control"];</sqf>
|  class="event" | onKeyUp
 
|  class="fired" | Releasing any keyboard key. Fired after the [[#onKeyDown|onKeyDown]] event.
==== onKillFocus ====
|  class="notes" | Returns the control, the code of the keyboard key and the state of Shift, Ctrl and Alt.
* '''Use on:''' Control
|  class="scope" | Control
* '''Fired on:''' Input focus is no longer on control. It no longer accepts keyboard input.
|-
* '''Returns:''' Returns control.
|  class="priority" | 2
<sqf>params ["_control"];</sqf>
|  class="event" | onChar
 
|  class="fired" | When some readable characters is recognised.
==== onTimer ====
|  class="notes" | Returns the control and the char code.
* '''Use on:''' Control
|  class="scope" | Control
* '''Fired on:''' N/A.
|-
* '''Returns:''' N/A.
|  class="priority" | 2
{{Feature | Informative | This feature has not been implemented.}}
|  class="event" | onIMEChar
 
|  class="fired" | When IME character is recognized (used in Korean and other eastern languages).
==== onKeyDown ====
|  class="notes" | Returns the control and the char code.
* '''Use on:''' Display, Control
|  class="scope" | Control
* '''Fired on:''' Pressing any keyboard key. Fired before the [[#onKeyUp|{{hl|onKeyUp}}]] event.
|-
* '''Returns:''' Returns the display or control, the [[DIK_KeyCodes|keyboard code]] and the state of {{Controls|Shift}}, {{Controls|Ctrl}} and {{Controls|Alt}}.
| class="priority" | 2
<sqf>
|  class="event" | onIMEComposition
params ["_displayOrControl", "_key", "_shift", "_ctrl", "_alt"];
|  class="fired" | When partial IME character is recognized (used in Korean and other eastern languages).
true // Intercepts the default action, e.g. pressing Escape won't close the dialog.
| class="notes" | Returns the control and the char code.
</sqf>
|  class="scope" | Control
 
|-
In {{arma3}}, in order to be able to intercept key events during gameplay, the Event Handler should be added to [[Arma_3:_IDD_List|Display 46]]:
|  class="priority" | 3
<sqf>
|  class="event" | onJoystickButton
findDisplay 46 displayAddEventHandler ["KeyDown", {}];
|  class="fired" | Pressing and releasing any joystick button.
</sqf>
|  class="notes" | Returns the control and the the pressed button.
 
|  class="scope" | Control
In general, one should never return [[true]] in the {{hl|onKeyDown}} EH, especially if it's added to [[Arma_3:_IDD_List|Display 46]] - otherwise all input is overridden and there is no way to do anything in the game anymore.
|- <span idonMouseButtonDown"/>
{{Feature|warning|Pressing and holding key triggers 'autorepeat' action on Windows, which in turn will make this EH fire repeatedly as well.}}
|  class="priority" | 2
 
|  class="event" | onMouseButtonDown
==== onKeyUp ====
|  class="fired" | Pressing a mouse button. Followed by the [[#onMouseButtonUp|onMouseButtonUp]] event.
* '''Use on:''' Display, Control
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
* '''Fired on:''' Releasing any keyboard key. Fired after the [[#onKeyDown|onKeyDown]] event.
| class="scope" | Control
* '''Returns:''' Returns the display or control, the [[DIK_KeyCodes|keyboard code]] and the state of {{Controls|Shift}}, {{Controls|Ctrl}} and {{Controls|Alt}}.
|- <span idonMouseButtonUp"/>
<sqf>params ["_displayOrControl", "_key", "_shift", "_ctrl", "_alt"];</sqf>
|  class="priority" | 2
 
|  class="event" | onMouseButtonUp
==== onChar ====
|  class="fired" | Releasing a mouse button. Follows the [[#onMouseButtonDown|onMouseButtonDown]] event.
* '''Use on:''' Display, Control
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
* '''Fired on:''' When some readable characters is recognised.
|  class="scope" | Control
* '''Returns:''' Returns the display or control and the {{Link|https://www.ascii-code.com/|char code}}.
|-
<sqf>params ["_displayOrControl", "_charCode"];</sqf>
|  class="priority" | 2
 
|  class="event" | onMouseButtonClick
==== onIMEChar ====
|  class="fired" | Pressing and releasing a mouse button.
* '''Use on:''' Control
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
* '''Fired on:''' When IME character is recognized (used in Korean and other eastern languages).
|  class="scope" | Control
* '''Returns:''' Returns the control and the char code.
|-
<sqf>params ["_control", "_charCode"];</sqf>
|  class="priority" | 2
 
|  class="event" | onMouseButtonDblClick
==== onIMEComposition ====
|  class="fired" | Pressing and releasing a mouse button twice within very short time.
* '''Use on:''' Control
|  class="notes" | Returns the control, the pressed button, the x and y coordinates and the state of Shift, Ctrl and Alt.
* '''Fired on:''' When partial IME character is recognized (used in Korean and other eastern languages).
|  class="scope" | Control
* '''Returns:''' Returns the control and the char code.
|-
<sqf>params ["_control", "_charCode"];</sqf>
|  class="priority" | 2
 
|  class="event" | onMouseMoving
==== onMouseButtonDown ====
|  class="fired" | Fires continiuously while moving the mouse with a certain interval.
* '''Use on:''' Display, Control
|  class="notes" | Returns the control, the x and y coordinates and mouseOver.
* '''Fired on:''' Pressing a mouse button. Followed by the [[#onMouseButtonUp|{{hl|onMouseButtonUp}}]] event.
|  class="scope" | Control
* '''Returns:''' Returns the display or control, the pressed button, the x and y coordinates and the state of {{Controls|Shift}}, {{Controls|Ctrl}} and {{Controls|Alt}}.
|-
<sqf>params ["_displayOrControl", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</sqf>
|  class="priority" | 2
 
|  class="event" | onMouseHolding
==== onMouseButtonUp ====
|  class="fired" | Fires contiuously while mouse is not moving with a certain interval.
* '''Use on:''' Display, Control
| class="notes" | Returns the control, the x and y coordinates and mouseOver.
* '''Fired on:''' Releasing a mouse button. Follows the [[#onMouseButtonDown|{{hl|onMouseButtonDown}}]] event.
| class="scope" | Control
* '''Returns:''' Returns the display or control, the pressed button, the x and y coordinates and the state of {{Controls|Shift}}, {{Controls|Ctrl}} and {{Controls|Alt}}.
|-
<sqf>params ["_displayOrControl", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</sqf>
|  class="priority" | 2
 
|  class="event" | onMouseZChanged
==== onMouseButtonClick ====
|  class="fired" | Fires when mouse wheel position is changed.
* '''Use on:''' ListBox, ComboBox, TextBox, Button, ActiveText
|  class="notes" | Returns the control and the change of the scrollbar.
* '''Fired on:''' Pressing and releasing a mouse button.
|  class="scope" | Control
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of {{Controls|Shift}}, {{Controls|Ctrl}} and {{Controls|Alt}}.
|-
<sqf>params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</sqf>
|  class="priority" | 3
 
| class="event" | onCanDestroy
==== onMouseButtonDblClick ====
|  class="fired" | Ask this control if dialog can be closed (used for validation of contained data).
* '''Use on:''' Control
|  class="notes" | Returns the control and exit code.
* '''Fired on:''' Pressing and releasing a mouse button twice within very short time.
| class="scope" | Control
* '''Returns:''' Returns the control, the pressed button, the x and y coordinates and the state of {{Controls|Shift}}, {{Controls|Ctrl}} and {{Controls|Alt}}.
|-
<sqf>params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];</sqf>
|  class="priority" | 3
 
|  class="event" | onDestroy
==== onMouseMoving ====
|  class="fired" | Destroying control
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
|  class="notes" | Returns the control and exit code.
<hr />
|  class="scope" | Control
* '''Use on:''' Control
|-
* '''Returns:''' Returns the control, the x and y coordinates relative to the controls parent and mouseOver.<br>If the controls parent is its display then x and y will be the same as [[getMousePosition]] else it will be relative to its parent control (for instance if inside a [[CT_CONTROLS_GROUP]]).
|  class="priority" | 1
<sqf>params ["_control", "_xPos", "_yPos", "_mouseOver"];</sqf>
|  class="event" | onButtonClicked
<hr />
|  class="fired" | The attached button action is performed.
* '''Use on:''' Display
|  class="notes" | Returns control.
* '''Returns:''' Returns the display, and ''some kind of'' x and y delta position.
| class="scope" | Button
<sqf>params ["_display", "_xPos", "_yPos"];</sqf>
|- <span idonButtonDown"/>
 
|  class="priority" | 1
==== onMouseHolding ====
|  class="event" | onButtonDown
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
|  class="fired" | The left mouse button is pressed over the button area or a key on the keyboard is pressed.
<hr />
|  class="notes" | Returns control.
* '''Use on:''' Control
|  class="scope" | Button
* '''Returns:''' Returns the control, the x and y coordinates relative to the controls parent and mouseOver.<br>If the controls parent is its display then x and y will be the same as [[getMousePosition]] else it will be relative to its parent control (for instance if inside a [[CT_CONTROLS_GROUP]]).
|- <span idonButtonUp"/>
<sqf>params ["_control", "_xPos", "_yPos", "_mouseOver"];</sqf>
|  class="priority" | 1
<hr />
|  class="event" | onButtonUp
* '''Use on:''' Display
|  class="fired" | The left mouse buttons is released outside the button area and the attached button action is not performed.
* '''Returns:''' Returns the display, and ''some kind of'' x and y delta position.
|  class="notes" | Returns control.
<sqf>params ["_display", "_xPos", "_yPos"];</sqf>
|  class="scope" | Button
 
|-
==== onMouseZChanged ====
|  class="priority" | 2
* '''Use on:''' Display, Control
|  class="event" | onLBSelChanged
* '''Fired on:''' Fires when mouse wheel position is changed. Does not fire on disabled control.
|  class="fired" | The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
* '''Returns:''' Returns the display or control and the change of the scrollwheel.
|  class="notes" | Returns the control and the selected element index.
<sqf>params ["_displayOrControl", "_scroll"];</sqf>
|  class="scope" | Listbox
 
|-
==== onCanDestroy ====
|  class="priority" | 2
* '''Use on:''' Control
|  class="event" | onLBListSelChanged
* '''Fired on:''' Ask this control if dialog can be closed (used for validation of contained data).
|  class="fired" | Selection in XCombo box changed (but value is not stored yet).
* '''Returns:''' Returns the control and exit code.
|  class="notes" | Returns the control and the selected element index.
<sqf>params ["_control", "_exitCode"];</sqf>
|  class="scope" | Listbox
 
|-
==== onDestroy ====
|  class="priority" | 2
* '''Use on:''' Control
|  class="event" | onLBDblClick
* '''Fired on:''' Destroying control
|  class="fired" | Double click on some row in listbox.
* '''Returns:''' Returns the control and exit code.
|  class="notes" | Returns the control and the selected element index.
<sqf>params ["_control", "_exitCode"];</sqf>
|  class="scope" | Listbox
{{ConfigPage|end}}
|-
 
|  class="priority" | 2
 
|  class="event" | onLBDrag
=== Button Events ===
|  class="fired" | Drag & drop operation started.
 
|  class="notes" | Returns the control and the selected element index.
{{ConfigPage|start}}
|  class="scope" | Listbox
{{ConfigPage|abc}}
|-
==== onButtonClick ====
|  class="priority" | 2
* '''Use on:''' Button
|  class="event" | onLBDragging
* '''Fired on:''' The attached button action is performed. When returned value is [[true]], the engine behaviour is overridden.
|  class="fired" | Drag & drop operation is in progress.
* '''Returns:''' Returns control.
|  class="notes" | Returns the control and the x and y coordinates.
<sqf>params ["_control"];</sqf>
|  class="scope" | Listbox
 
|-
{{ArgTitle|4|onButtonDblClick|{{GVI|arma3|1.00}}}}
|  class="priority" | 2
* '''Use on:''' Button
|  class="event" | onLBDrop
* '''Fired on:''' Button double clicked.
|  class="fired" | Drag & drop operation finished.
* '''Returns:''' Returns control.
|  class="notes" | Returns the control and the x and y coordinates.
<sqf>params ["_control"];</sqf>
|  class="scope" | Listbox
 
|-
==== onButtonDown ====
|  class="priority" | 2
* '''Use on:''' Button
|  class="event" | onTreeSelChanged
* '''Fired on:''' The left mouse button is pressed over the button area or a key on the keyboard is pressed.
|  class="fired" | Changing the selection in a tree.
* '''Returns:''' Returns control.
|  class="notes" | Returns the control.
<sqf>params ["_control"];</sqf>
|  class="scope" | Tree
 
|-
==== onButtonUp ====
|  class="priority" | 2
* '''Use on:''' Button
|  class="event" | onTreeDblClick
* '''Fired on:''' The left mouse button is released outside the button area and the attached button action '''is not performed'''.
|  class="fired" | Pressing and releasing twice on a tree.
* '''Returns:''' Returns control.
|  class="notes" | Returns the control.
<sqf>params ["_control"];</sqf>
|  class="scope" | Tree
{{ConfigPage|end}}
|-
 
|  class="priority" | 3
 
| class="event" | onTreeExpanded
=== Listbox Events ===
|  class="fired" | The tree folder structure has been expanded.
 
|  class="notes" | Returns the control.
{{ConfigPage|start}}
|  class="scope" | Tree
{{ConfigPage|abc}}
|-
==== onLBSelChanged ====
| class="priority" | 3
* '''Use on:''' Listbox, Combobox, Table
| class="event" | onTreeCollapsed
* '''Fired on:''' The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
| class="fired" | The tree folder structure has been collapsed.
{{Feature|warning|This EH will fire even if no new selection was made and the user clicked on existing selection}}
|  class="notes" | Returns the control.
{{Feature|informative|Since {{GVI|arma3|2.11}} controls with the LB_MULTI style pass an additional <var>_lbSelection</var> parameter to the EH script (see [[lbCurSel]], [[lbSelection]]).}}
|  class="scope" | Tree
* '''Returns:''' Returns the control and the selected element index.
|-
<sqf>params ["_control", "_lbCurSel", "_lbSelection"];</sqf>
|  class="priority" | 2
 
|  class="event" | onToolBoxSelChanged
==== onLBListSelChanged ====
|  class="fired" | Changed the selection in a toolbox.
* '''Use on:''' Combobox
|  class="notes" | Returns the control and the selected element index.
* '''Fired on:''' Selection in XCombo box changed (but value is not stored yet).
|  class="scope" | Toolbox
* '''Returns:''' Returns the control and the selected element index.
|-
<sqf>params ["_control", "_selectedIndex"];</sqf>
|  class="priority" | 2
 
|  class="event" | onCheckBoxesSelChanged
==== onLBDblClick ====
|  class="fired" | Changed the selection in a checkbox.
* '''Use on:''' Listbox
|  class="notes" | Returns the control, the selected element index and the current state.
* '''Fired on:''' Double click on some row in listbox.
|  class="scope" | Checkbox
* '''Returns:''' Returns the control and the selected element index.
|-
<sqf>params ["_control", "_selectedIndex"];</sqf>
|  class="priority" | 2
 
|  class="event" | onHTMLLink
==== onLBDrag ====
| class="fired" | Pressing and releasing a HTML link.
* '''Use on:''' Listbox
|  class="notes" | Returns the control and href.
* '''Fired on:''' Drag & drop operation started.
|  class="scope" | HTML
* '''Returns:''' Returns the control and an array of arrays of information on the dragged item(s) (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).<br>Control must have unique IDC and {{hl|canDrag}} parameter enabled in its class in order to work.
|-
<sqf>
|  class="priority" | 2
params ["_control", "_listboxInfo"];
|  class="event" | onSliderPosChanged
// Get info of first item being dragged:
|  class="fired" | Changing the position of a slider.
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];
| class="notes" | Returns the control and the change.
</sqf>
| class="scope" | Slider
 
|-
==== onLBDragging ====
| class="priority" | 2
* '''Use on:''' Listbox
|  class="event" | onObjectMoved
* '''Fired on:''' Drag & drop operation is in progress.
|  class="fired" | Moving an object.
* '''Returns:''' Returns the control, the x and y coordinates in screen space, listbox IDC where item(s) were dragged from and an array of arrays of information on the dragged item(s) (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).
|  class="notes" | Returns the control and the offset on the x,y and z axes.
<sqf>
|  class="scope" | Object
params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"];
|-
// Get info of first item being dragged:
|  class="priority" | 2
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];
|  class="event" | onMenuSelected
</sqf>
|  class="fired" | Some item in context menu (used now only in new mission editor) was selected.
 
|  class="notes" | Returns the control and the command id.
==== onLBDrop ====
|  class="scope" | Context menu
* '''Use on:''' Listbox, Combobox, Textbox, ActiveText, Button, ControlsGroup
|}
* '''Fired on:''' Drag & drop operation finished.
* '''Returns:''' Returns the control, the x and y coordinates in screen space, listbox IDC where item(s) were dragged from and an array of arrays of information on the dropped item(s) (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).<br>When the Listbox is inside a [[CT_CONTROLS_GROUP]] the Event Handler needs to be added to the [[CT_CONTROLS_GROUP]].<br>Will not work for [[CT_CONTROLS_GROUP]] that is subordinate to another group.
<sqf>
params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"];
//Get info of first item being dropped:
(_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];
</sqf>
{{ConfigPage|end}}
 
 
=== Tree Events ===
 
{{ConfigPage|start}}
{{ConfigPage|abc}}
==== onTreeSelChanged ====
* '''Use on:''' Tree
* '''Fired on:''' Changing the selection in a tree.
* '''Returns:''' Returns the control and the new selection path.
<sqf>params ["_control", "_selectionPath"];</sqf>
 
==== onTreeLButtonDown ====
* '''Use on:''' Tree
* '''Fired on:''' Pressing and releasing left mouse button on a tree.
* '''Returns:''' Returns the control.
<sqf>params ["_control"];</sqf>
 
==== onTreeDblClick ====
* '''Use on:''' Tree
* '''Fired on:''' Pressing and releasing twice on a tree entry.
* '''Returns:''' Returns the control and the current selection path.
<sqf>params ["_control", "_selectionPath"];</sqf>
 
==== onTreeExpanded ====
* '''Use on:''' Tree
* '''Fired on:''' The tree folder structure has been expanded.
* '''Returns:''' Returns the control and path.
<sqf>params ["_control", "_selectionPath"];</sqf>
 
==== onTreeCollapsed ====
* '''Use on:''' Tree
* '''Fired on:''' The tree folder structure has been collapsed.
* '''Returns:''' Returns the control and path.
<sqf>params ["_control", "_selectionPath"];</sqf>
 
==== onTreeMouseMove ====
* '''Use on:''' Tree
* '''Fired on:''' Fires continuously while moving the mouse with a certain interval.
* '''Returns:''' Returns the control. Also returns the path, probably since [[:Category:Eden Editor|Eden Editor]] update.
<sqf>params ["_control", "_path"];</sqf>
 
==== onTreeMouseHold ====
* '''Use on:''' Tree
* '''Fired on:''' Fires continuously while mouse is not moving with a certain interval.
* '''Returns:''' Returns the control. Also returns the path, probably since [[:Category:Eden Editor|Eden Editor]] update.
<sqf>params ["_control", "_path"];</sqf>
 
==== onTreeMouseExit ====
* '''Use on:''' Tree
* '''Fired on:''' The mouse pointer exits the tree control area
* '''Returns:''' Returns the control.
<sqf>params ["_control"];</sqf>
 
{{ArgTitle|4|onTreeFilterUpdated|{{GVI|arma3|2.12}}}}
* '''Use on:''' Tree
* '''Fired on:''' A search/filter done on the tree
* '''Returns:''' Returns the control.
<sqf>params ["_treeControl", "_searchControl", "_searchString"];</sqf>
{{ConfigPage|end}}
 
 
=== Checkbox Events ===
 
{{ConfigPage|start}}
{{ConfigPage|abc}}
{{ArgTitle|4|onChecked|{{GVI|arma3|1.00}}}}
* '''Use on:''' Checkbox ([[CT_CHECKBOX]]).
* '''Fired on:''' N/A
* '''Returns:''' N/A
{{Feature | Informative | This feature has not been implemented.}}
 
{{ArgTitle|4|onCheckedChanged|{{GVI|arma3|1.00}}}}
* '''Use on:''' Checkbox ([[CT_CHECKBOX]]).
* '''Fired on:''' Checked state of CheckBox changed.
* '''Returns:''' Returns control and the checked state (0 or 1, not boolean).
<sqf>params ["_control", "_checked"];</sqf>
 
==== onCheckBoxesSelChanged ====
* '''Use on:''' Checkboxes ([[CT_CHECKBOXES]]).
* '''Fired on:''' Changed the selection of checkboxes.
* '''Returns:''' Returns the control, the selected element index and the current state.
<sqf>params ["_control", "_selectedIndex", "_currentState"];</sqf>
{{ConfigPage|end}}
 
 
=== Misc. Events ===
 
{{ConfigPage|start}}
{{ConfigPage|abc}}
==== onToolBoxSelChanged ====
* '''Use on:''' Toolbox
* '''Fired on:''' Changed the selection in a toolbox.
* '''Returns:''' Returns the control and the selected element index.
<sqf>params ["_control", "_selectedIndex"];</sqf>
 
==== onHTMLLink ====
* '''Use on:''' HTML
* '''Fired on:''' Pressing and releasing a HTML link.
* '''Returns:''' Returns the control and href.
<sqf>params ["_control", "_url"];</sqf>
 
==== onSliderPosChanged ====
* '''Use on:''' Slider
* '''Fired on:''' Changing the position of a slider.
* '''Returns:''' Returns the control and the change.
<sqf>params ["_control", "_newValue"];</sqf>
 
==== onObjectMoved ====
* '''Use on:''' Object
* '''Fired on:''' Moving an object.
* '''Returns:''' Returns the control and the offset on the x, y and z axes.
<sqf>params ["_control", "_offset"];</sqf>
 
==== onMenuSelected ====
* '''Use on:''' Context menu
* '''Fired on:''' Some item in context menu (used now only in new mission editor) was selected.
* '''Returns:''' Returns the control and the command id.
<sqf>params ["_control", "_commandId"];</sqf>
 
==== onDraw ====
* '''Use on:''' Map, Display (only on [[Procedural_Textures#UI_On_Texture|UIOnTexture]] Display {{GVI|arma3|2.12}})
* '''Fired on:''' Fires when the map is drawn or the UI On Texture Display received a [[displayUpdate|draw request]] (can occur more than once per second).
* '''Returns:''' Returns the map control.
{{Feature | important | Saving and loading of the game has no effect on this Event Handler. It does not get saved, loaded or reset on game loading from save like some other Event Handlers do.}}
<sqf>params ["_controlOrDisplay"];</sqf>
 
{{ArgTitle|4|onVideoStopped|{{GVI|arma2oa|1.56}}}}
* '''Use on:''' Control
* '''Fired on:''' Activated every time the video ends (when looped, handler is executed after every finished loop).
* '''Returns:''' Returns the control.
<sqf>params ["_control"];</sqf>
{{ConfigPage|end}}
 
 
{{Sticky|
{{Feature|warning|When using the event names via [[:Category:Command Group: GUI Control - Event_Handlers|GUI scripting commands]] (e.g [[ctrlAddEventHandler]], [[displayAddEventHandler]]), the prefix "on" in the name '''must be removed''' (e.g. {{hl|ButtonDown}} instead of {{hl|onButtonDown}})!}}
|bottom}}
</div><!-- Used to limit Sticky range -->
 
 
== Event Parameters ==
 
The Event Handlers receive parameters through the [[Magic Variables|magic variable]] <var>_this</var>. Each event passes a different set of parameters (listed above) in an array. The control or display that the event was assigned to is always found in <sqf inline>_this select 0</sqf>.
 
 
== Scope ==
 
{{GVI|arma1|1.00}} In {{arma1}}, most control-specific events work for controls and do not work for displays. The two exceptions being: {{hl|onKeyDown}} and {{hl|onKeyUp}}.<br>
{{GVI|arma2|1.00}} Since {{arma2}}, most control-specific events work for both displays and controls.
 
 
== Defining Events ==
 
User Interface Event Handlers can be assigned in two ways: Via class property definitions or via [[:Category:Scripting Commands|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 found within a control or dialog class):
<syntaxhighlight lang="cpp">
onMouseButtonDown = "hint str _this";
</syntaxhighlight>
 
Full Example:
<syntaxhighlight lang="cpp">
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;
autoScrollSpeed = -1;
autoScrollDelay = 5;
autoScrollRewind = 0;
};
 
class HScrollbar
{
color[] = { 1, 1, 1, 1 };
height = 0.028;
};
 
class ScrollBar // >= Arma 2
{
color[] = { 1, 1, 1, 0.6 };
colorActive[] = { 1, 1, 1, 1 };
colorDisabled[] = { 1, 1, 1, 0.3 };
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 myEventFunction";
onMouseButtonDown = "[1, _this] call myEventFunction";
onMouseButtonUp = "[2, _this] call myEventFunction";
onMouseZChanged = "[3, _this] call myEventFunction";
onMouseEnter = "[4, _this] call myEventFunction";
idc = 123;
x = 0.0;
y = 0.0;
w = 1.0;
h = 1.0;
colorBackground[] = { 0.2, 0.0, 0.0, 0.0 };
};
</syntaxhighlight>
 
=== Script-Defined Events ===
 
These events can also be given to dialogs and controls using the [[displayAddEventHandler]] and [[ctrlAddEventHandler]] commands. The control has to be enabled for the Event Handler in order for Event Handlers to fire (see [[ctrlEnable]]).
 
<sqf>
// Add Event Handler:
(findDisplay 46) displayAddEventHandler ["KeyDown", {
_this call functionName_keyDown;
}];
 
// Function definition:
functionName_keyDown = {
params ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
private _handled = false;
 
if (!_shift && !_ctrlKey && !_alt) then {
if (_dikCode in (actionKeys "NetworkStats")) then {
systemChat format ["EH fired for %1", _ctrl];
_handled = true;
};
};
 
_handled
};
</sqf>
 


[[Category:ArmA: Mission Editing]]
[[Category:Event Handlers]]
[[Category:Event Handlers]]
[[Category:GUI Topics|GUI Topics]]

Revision as of 01:25, 2 February 2024

User Interface Event Handlers are used to execute code when events related to GUI components (i.e. Displays and Controls) occur.

Deleting a display or control from within a UI Event Handler will crash the game if deleting is not the last line in the Event Handler's script. Alternatively, the code can also be spawned to circumvent this issue.
onButtonClick = "ctrlDelete (_this select 0); systemChat 'You will never see this';";			// Crashes the game
onButtonClick = "systemChat 'Bye bye button!'; ctrlDelete (_this select 0);";					// Works fine
onButtonClick = "_this spawn { ctrlDelete (_this select 0); systemChat 'Bye bye button!'; };";	// Works fine


Reference List

Generic Events

onLoad

  • Use on: Display, Control
  • Fired on: Fires when UI container is created, but no action is taken. The onLoad event for display fires after the onLoad events for all controls it contains are fired.
  • Returns: Display or control, for controls it also returns the control's config (since Arma 3 logo black.png1.56).

params ["_displayOrControl", ["_config", configNull]];

The order of initialisation is as follows:
  1. Topmost config class (control class)
  2. Last config class
  3. Display
This means that during the onLoad event of the upper controls the lower controls do not exist!

onUnload

  • Use on: Display
  • Fired on: Display is closed, but no controls are destroyed yet.
  • Returns: Returns the display and exit code.

params ["_display", "_exitCode"];

The onUnload event does not fire for RscTitles displays created with cutRsc.
Code or function should be called, otherwise controls might be destroyed before spawned code is executed!

onChildDestroyed

  • Use on: Display
  • Fired on: Child display is closed.
  • Returns: Returns the display, which child display was closed and exit code.

params ["_display", "_closedChildDisplay", "_exitCode"];

onCommitted

params ["_control", "_animType", "_animTime"];

onEditChanged

  • Use on: Control
  • Fired on: Any changes to the CT_EDIT text field content.
  • Returns: Returns the control and the changed text.

params ["_control", "_newText"];

onMouseEnter

  • Use on: Control
  • Fired on: The mouse pointer enters the control area.
  • Returns: Returns control.

params ["_control"];

The onMouseEnter event does not fire for disabled buttons (see ctrlEnable).

onMouseExit

  • Use on: Control
  • Fired on: The mouse pointer exits the control area.
  • Returns: Returns control.

params ["_control"];

onSetFocus

  • Use on: Control
  • Fired on: Input focus is on control. It now begins to accept keyboard input.
  • Returns: Returns control.

params ["_control"];

onKillFocus

  • Use on: Control
  • Fired on: Input focus is no longer on control. It no longer accepts keyboard input.
  • Returns: Returns control.

params ["_control"];

onTimer

  • Use on: Control
  • Fired on: N/A.
  • Returns: N/A.
This feature has not been implemented.

onKeyDown

  • Use on: Display, Control
  • Fired on: Pressing any keyboard key. Fired before the onKeyUp event.
  • Returns: Returns the display or control, the keyboard code and the state of ⇧ Shift, Ctrl and Alt.

params ["_displayOrControl", "_key", "_shift", "_ctrl", "_alt"]; true // Intercepts the default action, e.g. pressing Escape won't close the dialog.

In Arma 3, in order to be able to intercept key events during gameplay, the Event Handler should be added to Display 46:

In general, one should never return true in the onKeyDown EH, especially if it's added to Display 46 - otherwise all input is overridden and there is no way to do anything in the game anymore.

Pressing and holding key triggers 'autorepeat' action on Windows, which in turn will make this EH fire repeatedly as well.

onKeyUp

  • Use on: Display, Control
  • Fired on: Releasing any keyboard key. Fired after the onKeyDown event.
  • Returns: Returns the display or control, the keyboard code and the state of ⇧ Shift, Ctrl and Alt.

params ["_displayOrControl", "_key", "_shift", "_ctrl", "_alt"];

onChar

  • Use on: Display, Control
  • Fired on: When some readable characters is recognised.
  • Returns: Returns the display or control and the char code.

params ["_displayOrControl", "_charCode"];

onIMEChar

  • Use on: Control
  • Fired on: When IME character is recognized (used in Korean and other eastern languages).
  • Returns: Returns the control and the char code.

params ["_control", "_charCode"];

onIMEComposition

  • Use on: Control
  • Fired on: When partial IME character is recognized (used in Korean and other eastern languages).
  • Returns: Returns the control and the char code.

params ["_control", "_charCode"];

onMouseButtonDown

  • Use on: Display, Control
  • Fired on: Pressing a mouse button. Followed by the onMouseButtonUp event.
  • Returns: Returns the display or control, the pressed button, the x and y coordinates and the state of ⇧ Shift, Ctrl and Alt.

params ["_displayOrControl", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];

onMouseButtonUp

  • Use on: Display, Control
  • Fired on: Releasing a mouse button. Follows the onMouseButtonDown event.
  • Returns: Returns the display or control, the pressed button, the x and y coordinates and the state of ⇧ Shift, Ctrl and Alt.

params ["_displayOrControl", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];

onMouseButtonClick

  • Use on: ListBox, ComboBox, TextBox, Button, ActiveText
  • Fired on: Pressing and releasing a mouse button.
  • Returns: Returns the control, the pressed button, the x and y coordinates and the state of ⇧ Shift, Ctrl and Alt.

params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];

onMouseButtonDblClick

  • Use on: Control
  • Fired on: Pressing and releasing a mouse button twice within very short time.
  • Returns: Returns the control, the pressed button, the x and y coordinates and the state of ⇧ Shift, Ctrl and Alt.

params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];

onMouseMoving

  • Fired on: Fires continuously while moving the mouse with a certain interval.

  • Use on: Control
  • Returns: Returns the control, the x and y coordinates relative to the controls parent and mouseOver.
    If the controls parent is its display then x and y will be the same as getMousePosition else it will be relative to its parent control (for instance if inside a CT_CONTROLS_GROUP).

params ["_control", "_xPos", "_yPos", "_mouseOver"];


  • Use on: Display
  • Returns: Returns the display, and some kind of x and y delta position.

params ["_display", "_xPos", "_yPos"];

onMouseHolding

  • Fired on: Fires continuously while mouse is not moving with a certain interval.

  • Use on: Control
  • Returns: Returns the control, the x and y coordinates relative to the controls parent and mouseOver.
    If the controls parent is its display then x and y will be the same as getMousePosition else it will be relative to its parent control (for instance if inside a CT_CONTROLS_GROUP).

params ["_control", "_xPos", "_yPos", "_mouseOver"];


  • Use on: Display
  • Returns: Returns the display, and some kind of x and y delta position.

params ["_display", "_xPos", "_yPos"];

onMouseZChanged

  • Use on: Display, Control
  • Fired on: Fires when mouse wheel position is changed. Does not fire on disabled control.
  • Returns: Returns the display or control and the change of the scrollwheel.

params ["_displayOrControl", "_scroll"];

onCanDestroy

  • Use on: Control
  • Fired on: Ask this control if dialog can be closed (used for validation of contained data).
  • Returns: Returns the control and exit code.

params ["_control", "_exitCode"];

onDestroy

  • Use on: Control
  • Fired on: Destroying control
  • Returns: Returns the control and exit code.

params ["_control", "_exitCode"];


Button Events

onButtonClick

  • Use on: Button
  • Fired on: The attached button action is performed. When returned value is true, the engine behaviour is overridden.
  • Returns: Returns control.

params ["_control"];

onButtonDblClick

  • Use on: Button
  • Fired on: Button double clicked.
  • Returns: Returns control.

params ["_control"];

onButtonDown

  • Use on: Button
  • Fired on: The left mouse button is pressed over the button area or a key on the keyboard is pressed.
  • Returns: Returns control.

params ["_control"];

onButtonUp

  • Use on: Button
  • Fired on: The left mouse button is released outside the button area and the attached button action is not performed.
  • Returns: Returns control.

params ["_control"];


Listbox Events

onLBSelChanged

  • Use on: Listbox, Combobox, Table
  • Fired on: The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.
This EH will fire even if no new selection was made and the user clicked on existing selection
Since Arma 3 logo black.png2.11 controls with the LB_MULTI style pass an additional _lbSelection parameter to the EH script (see lbCurSel, lbSelection).
  • Returns: Returns the control and the selected element index.

params ["_control", "_lbCurSel", "_lbSelection"];

onLBListSelChanged

  • Use on: Combobox
  • Fired on: Selection in XCombo box changed (but value is not stored yet).
  • Returns: Returns the control and the selected element index.

params ["_control", "_selectedIndex"];

onLBDblClick

  • Use on: Listbox
  • Fired on: Double click on some row in listbox.
  • Returns: Returns the control and the selected element index.

params ["_control", "_selectedIndex"];

onLBDrag

  • Use on: Listbox
  • Fired on: Drag & drop operation started.
  • Returns: Returns the control and an array of arrays of information on the dragged item(s) (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).
    Control must have unique IDC and canDrag parameter enabled in its class in order to work.

params ["_control", "_listboxInfo"]; // Get info of first item being dragged: (_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];

onLBDragging

  • Use on: Listbox
  • Fired on: Drag & drop operation is in progress.
  • Returns: Returns the control, the x and y coordinates in screen space, listbox IDC where item(s) were dragged from and an array of arrays of information on the dragged item(s) (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).

params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"]; // Get info of first item being dragged: (_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];

onLBDrop

  • Use on: Listbox, Combobox, Textbox, ActiveText, Button, ControlsGroup
  • Fired on: Drag & drop operation finished.
  • Returns: Returns the control, the x and y coordinates in screen space, listbox IDC where item(s) were dragged from and an array of arrays of information on the dropped item(s) (if listbox is of style LB_MULTI then multiple items can be dragged and dropped at the same time).
    When the Listbox is inside a CT_CONTROLS_GROUP the Event Handler needs to be added to the CT_CONTROLS_GROUP.
    Will not work for CT_CONTROLS_GROUP that is subordinate to another group.

params ["_control", "_xPos", "_yPos", "_listboxIDC", "_listboxInfo"]; //Get info of first item being dropped: (_listboxInfo select 0) params ["_lbText", "_lbValue", "_lbData"];


Tree Events

onTreeSelChanged

  • Use on: Tree
  • Fired on: Changing the selection in a tree.
  • Returns: Returns the control and the new selection path.

params ["_control", "_selectionPath"];

onTreeLButtonDown

  • Use on: Tree
  • Fired on: Pressing and releasing left mouse button on a tree.
  • Returns: Returns the control.

params ["_control"];

onTreeDblClick

  • Use on: Tree
  • Fired on: Pressing and releasing twice on a tree entry.
  • Returns: Returns the control and the current selection path.

params ["_control", "_selectionPath"];

onTreeExpanded

  • Use on: Tree
  • Fired on: The tree folder structure has been expanded.
  • Returns: Returns the control and path.

params ["_control", "_selectionPath"];

onTreeCollapsed

  • Use on: Tree
  • Fired on: The tree folder structure has been collapsed.
  • Returns: Returns the control and path.

params ["_control", "_selectionPath"];

onTreeMouseMove

  • Use on: Tree
  • Fired on: Fires continuously while moving the mouse with a certain interval.
  • Returns: Returns the control. Also returns the path, probably since Eden Editor update.

params ["_control", "_path"];

onTreeMouseHold

  • Use on: Tree
  • Fired on: Fires continuously while mouse is not moving with a certain interval.
  • Returns: Returns the control. Also returns the path, probably since Eden Editor update.

params ["_control", "_path"];

onTreeMouseExit

  • Use on: Tree
  • Fired on: The mouse pointer exits the tree control area
  • Returns: Returns the control.

params ["_control"];

onTreeFilterUpdated

  • Use on: Tree
  • Fired on: A search/filter done on the tree
  • Returns: Returns the control.

params ["_treeControl", "_searchControl", "_searchString"];


Checkbox Events

onChecked

  • Use on: Checkbox (CT_CHECKBOX).
  • Fired on: N/A
  • Returns: N/A
This feature has not been implemented.

onCheckedChanged

  • Use on: Checkbox (CT_CHECKBOX).
  • Fired on: Checked state of CheckBox changed.
  • Returns: Returns control and the checked state (0 or 1, not boolean).

params ["_control", "_checked"];

onCheckBoxesSelChanged

  • Use on: Checkboxes (CT_CHECKBOXES).
  • Fired on: Changed the selection of checkboxes.
  • Returns: Returns the control, the selected element index and the current state.

params ["_control", "_selectedIndex", "_currentState"];


Misc. Events

onToolBoxSelChanged

  • Use on: Toolbox
  • Fired on: Changed the selection in a toolbox.
  • Returns: Returns the control and the selected element index.

params ["_control", "_selectedIndex"];

onHTMLLink

  • Use on: HTML
  • Fired on: Pressing and releasing a HTML link.
  • Returns: Returns the control and href.

params ["_control", "_url"];

onSliderPosChanged

  • Use on: Slider
  • Fired on: Changing the position of a slider.
  • Returns: Returns the control and the change.

params ["_control", "_newValue"];

onObjectMoved

  • Use on: Object
  • Fired on: Moving an object.
  • Returns: Returns the control and the offset on the x, y and z axes.

params ["_control", "_offset"];

onMenuSelected

  • Use on: Context menu
  • Fired on: Some item in context menu (used now only in new mission editor) was selected.
  • Returns: Returns the control and the command id.

params ["_control", "_commandId"];

onDraw

  • Use on: Map, Display (only on UIOnTexture Display Arma 3 logo black.png2.12)
  • Fired on: Fires when the map is drawn or the UI On Texture Display received a draw request (can occur more than once per second).
  • Returns: Returns the map control.
Saving and loading of the game has no effect on this Event Handler. It does not get saved, loaded or reset on game loading from save like some other Event Handlers do.

params ["_controlOrDisplay"];

onVideoStopped

  • Use on: Control
  • Fired on: Activated every time the video ends (when looped, handler is executed after every finished loop).
  • Returns: Returns the control.

params ["_control"];


When using the event names via GUI scripting commands (e.g ctrlAddEventHandler, displayAddEventHandler), the prefix "on" in the name must be removed (e.g. ButtonDown instead of onButtonDown)!


Event Parameters

The Event Handlers receive parameters through the magic variable _this. Each event passes a different set of parameters (listed above) in an array. The control or display that the event was assigned to is always found in _this select 0.


Scope

Logo A1 black.png1.00 In Armed Assault, most control-specific events work for controls and do not work for displays. The two exceptions being: onKeyDown and onKeyUp.
Logo A2.png1.00 Since Arma 2, most control-specific events 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 found within a control or dialog class):

onMouseButtonDown = "hint str _this";

Full 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;
		autoScrollSpeed		= -1;
		autoScrollDelay		= 5;
		autoScrollRewind	= 0;
	};

	class HScrollbar
	{
		color[]	= { 1, 1, 1, 1 };
		height	= 0.028;
	};

	
	class ScrollBar		// >= Arma 2
	{
		color[]			= { 1, 1, 1, 0.6 };
		colorActive[]	= { 1, 1, 1, 1 };
		colorDisabled[]	= { 1, 1, 1, 0.3 };
		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 myEventFunction";
	onMouseButtonDown	= "[1, _this] call myEventFunction";
	onMouseButtonUp		= "[2, _this] call myEventFunction";
	onMouseZChanged		= "[3, _this] call myEventFunction";
	onMouseEnter		= "[4, _this] call myEventFunction";
	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 and controls using the displayAddEventHandler and ctrlAddEventHandler commands. The control has to be enabled for the Event Handler in order for Event Handlers to fire (see ctrlEnable).

// Add Event Handler: (findDisplay 46) displayAddEventHandler ["KeyDown", { _this call functionName_keyDown; }]; // Function definition: functionName_keyDown = { params ["_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"]; private _handled = false; if (!_shift && !_ctrlKey && !_alt) then { if (_dikCode in (actionKeys "NetworkStats")) then { systemChat format ["EH fired for %1", _ctrl]; _handled = true; }; }; _handled };