ctrlSetEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (added second example. updated note to try and make clearer dropping the On)
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(75 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma |= Game name
|game1= arma1
|version1= 1.00


|1.00|= Game version
|game2= arma2
____________________________________________________________________________________________
|version2= 1.00


| Sets given event handler of given control. |= Description
|game3= arma2oa
____________________________________________________________________________________________
|version3= 1.50


| control '''ctrlSetEventHandler''' [handler name, function] |= Syntax
|game4= tkoh
|version4= 1.00


|p1= control: [[Control]] |= Parameter 1
|game5= arma3
|version5= 0.50


|p2= [handler name, function]: [[Array]] |= Parameter 2
|gr1= GUI Control - Event Handlers
| [[Nothing]] |= Return value
|gr2= Event Handlers
____________________________________________________________________________________________
 
|x1= <pre>_control ctrlSetEventHandler ["KeyDown", ""]</pre> |= Example 1


|x2= <pre>(_display displayCtrl 108) ctrlSetEventHandler ["LBSelChanged", "[""ListChange"", _this] call FireEvents"];</pre> |= Example 2 (using call)
|descr= {{Feature|obsolete|Use [[ctrlAddEventHandler]] instead as it can stack event handlers.|arma2|1.00}}
Sets given event handler of given control: any previously added event handler is removed.


{{Feature|informative|
* See [[User Interface Event Handlers]] for the full list of handler names
* See also [[DIK KeyCodes]] for a list of key code constants relevant to key-related events like [[User_Interface_Event_Handlers#onKeyDown|KeyDown]] and [[User_Interface_Event_Handlers#onKeyUp|KeyUp]]
}}
{{Feature|important|When using the event names listed [[User Interface Event Handlers|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'''').}}
|s1= controlName [[ctrlSetEventHandler]] [handlerName, function]
|p1= controlName: [[Control]]
|p2= handlerName: [[String]]


____________________________________________________________________________________________
|p3= function: [[String]] - should return a [[Boolean]] indicating that the event has handled this event fully or not and whether the engine should execute its default code or not afterwards


| [[displaySetEventHandler]] |= See also
|r1= [[Nothing]]


}}
|x1= <sqf>_control ctrlSetEventHandler ["KeyDown", ""];</sqf>


<h3 style="display:none">Notes</h3>
|x2= <sqf>(_display displayCtrl 108) ctrlSetEventHandler ["LBSelChanged","['ListChange',_this] call FireEvents"];</sqf>
<dl class="command_description">
<!-- Note Section BEGIN -->
There is a listing of [[User Interface Event Handlers]] that will work with ctrlSetEventHandler, but when combining those UI event handlers you must drop the ''On'' part.
<br>Bad Example:
<code> _control ctrlSetEventHandler ["OnLBSelChanged", ""] </code>
<br>Good Example:
<code> _control ctrlSetEventHandler ["LBSelChanged", ""] </code>
<!-- Note Section END -->
</dl>


<h3 style="display:none">Bottom Section</h3>
|seealso= [[displaySetEventHandler]] [[ctrlAddEventHandler]] [[ctrlRemoveEventHandler]] [[User_Interface_Event_Handlers|UI Event Handlers]] [[DIK KeyCodes]]
}}


[[Category:Scripting Commands|CTRLSETEVENTHANDLER]]
{{Note
[[Category:Scripting Commands ArmA|CTRLSETEVENTHANDLER]]
|user= pierremgi
[[Category:Command_Group:_GUI_Control|{{uc:{{PAGENAME}}}}]]
|timestamp= 20210428195900
|text= This command doesn't work on map.
<sqf>
waitUntil { !isNull (findDisplay 12 displayCtrl 51) };
(findDisplay 12 displayCtrl 51) ctrlSetEventHandler ["MouseButtonDblClick", "hint str _this; true"]; // doesn't skip the marker dialog as it should.
</sqf>
}}

Latest revision as of 19:43, 3 September 2024

Hover & click on the images for description

Description

Description:
🕖
This information is obsolete as of Arma 2 v1.00. Reason: Use ctrlAddEventHandler instead as it can stack event handlers.

Sets given event handler of given control: any previously added event handler is removed.

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:
controlName ctrlSetEventHandler [handlerName, function]
Parameters:
controlName: Control
handlerName: String
function: String - should return a Boolean indicating that the event has handled this event fully or not and whether the engine should execute its default code or not afterwards
Return Value:
Nothing

Examples

Example 1:
_control ctrlSetEventHandler ["KeyDown", ""];
Example 2:
(_display displayCtrl 108) ctrlSetEventHandler ["LBSelChanged","['ListChange',_this] call FireEvents"];

Additional Information

See also:
displaySetEventHandler ctrlAddEventHandler ctrlRemoveEventHandler UI Event Handlers DIK KeyCodes

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
pierremgi - c
Posted on Apr 28, 2021 - 19:59 (UTC)
This command doesn't work on map.
waitUntil { !isNull (findDisplay 12 displayCtrl 51) }; (findDisplay 12 displayCtrl 51) ctrlSetEventHandler ["MouseButtonDblClick", "hint str _this; true"]; // doesn't skip the marker dialog as it should.