Matty Smith/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "{{Feature|Warning|" to "{{Feature|warning|")
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Sandbox]]
<!--
{{GameCategory|arma3|Editing}}
[[Category:Introduced with {{arma3}} version 2.06]]
-->
{{TOC|side}}
{{TOC|side}}


Line 17: Line 22:
};
};
</syntaxhighlight>
</syntaxhighlight>


== Adding a new key ==
== Adding a new key ==
=== Defining a new action in CfgUserActions ===
=== Defining a new action in CfgUserActions ===
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
class CfgUserActions
class CfgUserActions
Line 36: Line 44:


=== Defining a default keybind in CfgDefaultKeysPresets ===
=== Defining a default keybind in CfgDefaultKeysPresets ===
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
class CfgDefaultKeysPresets
class CfgDefaultKeysPresets
Line 52: Line 61:
};
};
</syntaxhighlight>
</syntaxhighlight>
{{Feature|Warning|If the key code is large enough, for example {{ic|0x1D130023}} ({{KeyboardShortcut|Ctrl|H}}), then adding values may lead to a wrong result due to rounding errors (see {{HashLink|Number#Floating-point Precision}}). As such, it is recommended to do the calculation manually and use that value instead.}}
{{Feature|warning|If the key code is large enough, for example {{hl|0x1D130023}} ({{Controls|Ctrl|H}}), then adding values may lead to a wrong result due to rounding errors (see {{Link|Number#Floating-point Precision}}). As such, it is recommended to do the calculation manually and use that value instead.}}


=== Adding a keybind to the keybind options dialog ===
=== Adding a keybind to the keybind options dialog ===
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
class UserActionGroups
class UserActionGroups
Line 68: Line 78:


=== Setting up a collision group (optional) ===
=== Setting up a collision group (optional) ===
Class UserActionsConflictGroups provides the ability to configure checks for keybinding collisions. The following example demonstrates how to ensure that the input does not conflict with car movement keybindings:
Class UserActionsConflictGroups provides the ability to configure checks for keybinding collisions. The following example demonstrates how to ensure that the input does not conflict with car movement keybindings:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
Line 90: Line 101:


== Scripted Event Handlers ==
== Scripted Event Handlers ==
<code>[[addUserActionEventHandler]] ["ReloadMagazine", "Activate", {
 
[[systemChat]] "Reloading!";
<sqf>
[[removeUserActionEventHandler]] ["ReloadMagazine", "Activate", [[Magic Variables#thisEventHandler|_thisEventHandler]]];
addUserActionEventHandler ["ReloadMagazine", "Activate", {
}];</code>
systemChat "Reloading!";
removeUserActionEventHandler ["ReloadMagazine", "Activate", _thisEventHandler];
}];
</sqf>
The persistence of these EHs is the same as that of [[Arma 3: Mission Event Handlers|Mission Event Handlers]] - they are scoped per mission and get removed when the mission ends.
The persistence of these EHs is the same as that of [[Arma 3: Mission Event Handlers|Mission Event Handlers]] - they are scoped per mission and get removed when the mission ends.


Line 107: Line 121:


{| class="wikitable"
{| class="wikitable"
!{{ic|0x}}
! {{hl|0x}}
!{{ic|aa}}
! {{hl|aa}}
!{{ic|bb}}
! {{hl|bb}}
!{{ic|cc}}
! {{hl|cc}}
!{{ic|dd}}
! {{hl|dd}}
! rowspan="3" | Result
|-
|-
|Description
| Description
|Combo key
| Combo key
|Device types
| Device types
|Main key additional info
| Main key additional info
|Main key
| Main key
|-
|-
!colspan="5"| Examples
! colspan="5" | Examples
!Result


|-
|-
|1. {{KeyboardShortcut|A|2×B}}
| 1. {{Controls|A|2×B}}
|DIK_A ({{ic|0x1E}})
| DIK_A ({{hl|0x1E}})
|INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_KB ({{ic|0x13}})
| INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_KB ({{hl|0x13}})
|DOUBLE TAP ({{ic|0x10}})
| DOUBLE TAP ({{hl|0x10}})
|DIK_B ({{ic|0x30}})
| DIK_B ({{hl|0x30}})
|{{ic|0x1E130130}}
|{{hl|0x1E130130}}


|-
|-
|2. {{KeyboardShortcut|A|MMB click}}
| 2. {{Controls|A|MMB click}}
|DIK_A ({{ic|0x1E}})
| DIK_A ({{hl|0x1E}})
|INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_MB ({{ic|0x11}})
| INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_MB ({{hl|0x11}})
|None ({{ic|0x00}})
| None ({{hl|0x00}})
|MOUSE_BUTTONS_MIDDLE + MOUSE_CLICK_OFFSET ({{ic|0x82}})
| MOUSE_BUTTONS_MIDDLE + MOUSE_CLICK_OFFSET ({{hl|0x82}})
|{{ic|0x1E110002}}
| {{hl|0x1E110002}}


|-
|-
|3. {{KeyboardShortcut|A}} + Mouse Left (Move)
| 3. {{Controls|A}} + Mouse Left (Move)
|DIK_A ({{ic|0x1E}})
| DIK_A ({{hl|0x1E}})
|INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_MB ({{ic|0x11}})
| INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_MB ({{hl|0x11}})
|None ({{ic|0x00}})
| None ({{hl|0x00}})
|MOUSE_AXIS_LEFT ({{ic|0x00}})
| MOUSE_AXIS_LEFT ({{hl|0x00}})
|{{ic|0x1E110000}}
| {{hl|0x1E110000}}


|-
|-
|4. {{KeyboardShortcut|LMB click|MMB click}}
| 4. {{Controls|LMB click|MMB click}}
|MOUSE_BUTTONS_MIDDLE + MOUSE_CLICK_OFFSET ({{ic|0x82}})
| MOUSE_BUTTONS_MIDDLE + MOUSE_CLICK_OFFSET ({{hl|0x82}})
|INPUT_DEVICE_COMBO_MB + INPUT_DEVICE_MAIN_MB ({{ic|0x31}})
| INPUT_DEVICE_COMBO_MB + INPUT_DEVICE_MAIN_MB ({{hl|0x31}})
|None ({{ic|0x00}})
| None ({{hl|0x00}})
|MOUSE_BUTTONS_LEFT + MOUSE_CLICK_OFFSET ({{ic|0x80}})
| MOUSE_BUTTONS_LEFT + MOUSE_CLICK_OFFSET ({{hl|0x80}})
|{{ic|0x02310000}}
|{{hl|0x02310000}}


|}
|}
Line 160: Line 174:
This is the exact same as [[#dd - Main key]], but for the combo key.
This is the exact same as [[#dd - Main key]], but for the combo key.


If there is not a combo key, use {{ic|0x00}}.
If there is not a combo key, use {{hl|0x00}}.


=== bb - Device types ===
=== bb - Device types ===
Line 166: Line 180:
This specifies the type of the main key, and optionally the combo key.
This specifies the type of the main key, and optionally the combo key.


For a single keybind, use {{ic|INPUT_DEVICE_SOLO_xx}}, but for a combo keybind add together the results of {{ic|INPUT_DEVICE_COMBO_xx}} and {{ic|INPUT_DEVICE_MAIN_xx}}.
For a single keybind, use {{hl|INPUT_DEVICE_SOLO_xx}}, but for a combo keybind add together the results of {{hl|INPUT_DEVICE_COMBO_xx}} and {{hl|INPUT_DEVICE_MAIN_xx}}.


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
Line 174: Line 188:
#define INPUT_DEVICE_COMBO_JB 0x00500000 // Joystick button
#define INPUT_DEVICE_COMBO_JB 0x00500000 // Joystick button
#define INPUT_DEVICE_COMBO_JP 0x00600000 // Joystick POV
#define INPUT_DEVICE_COMBO_JP 0x00600000 // Joystick POV
#define INPUT_DEVICE_COMBO_XI 0x00900000 // XBox controller (XInput)
#define INPUT_DEVICE_COMBO_XI 0x00900000 // Xbox controller (XInput)


// Main combo types:
// Main combo types:
Line 183: Line 197:
#define INPUT_DEVICE_MAIN_JA 0x00050000 // Joystick axis
#define INPUT_DEVICE_MAIN_JA 0x00050000 // Joystick axis
#define INPUT_DEVICE_MAIN_JP 0x00060000 // Joystick POV
#define INPUT_DEVICE_MAIN_JP 0x00060000 // Joystick POV
#define INPUT_DEVICE_MAIN_XI 0x00070000 // XBox controller (XInput)
#define INPUT_DEVICE_MAIN_XI 0x00070000 // Xbox controller (XInput)
#define INPUT_DEVICE_MAIN_TR 0x00080000 // Movement tracking device
#define INPUT_DEVICE_MAIN_TR 0x00080000 // Movement tracking device


Line 231: Line 245:
};
};


#define MOUSE_HOLD_OFFSET         0x00
#define MOUSE_HOLD_OFFSET 0x00
#define MOUSE_CLICK_OFFSET         0x80   // Offset for mouse button click (compared to hold)
#define MOUSE_CLICK_OFFSET 0x80 // Offset for mouse button click (compared to hold)
</syntaxhighlight>
</syntaxhighlight>


Line 261: Line 275:
TRACK_X = 3, // Left / right move
TRACK_X = 3, // Left / right move
TRACK_Y = 4, // Up / down move
TRACK_Y = 4, // Up / down move
TRACK_Z = 5     // Forward / backward move
TRACK_Z = 5 // Forward / backward move
};
};
</syntaxhighlight>
</syntaxhighlight>


==== Joysticks ====
==== Joysticks ====
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
#define N_JOYSTICK_AXES 8 // 3 normal, 3 rotate, 2 sliders
#define N_JOYSTICK_AXES 8 // 3 normal, 3 rotate, 2 sliders
Line 272: Line 285:
</syntaxhighlight>
</syntaxhighlight>
There are up to 256 joystick buttons available.
There are up to 256 joystick buttons available.
{{GameCategory|arma3|Editing}}
[[Category:Introduced with {{arma3}} version 2.06]]

Latest revision as of 00:26, 2 February 2024

As of Arma 3 logo black.png2.06, mods are able to define keys that can be bound by the user in the keybindings.

class CfgUserActions
{
	class TAG_MyActionName // This class name is used for internal representation and also for the inputAction command.
	{
		displayName = "";
		tooltip = "";
		onActivate = "['TAG_MyActionName', true] call TAG_fnc_MyHandler";		// _this is always true.
		onDeactivate = "['TAG_MyActionName', false] call TAG_fnc_MyHandler";	// _this is always false.
		onAnalog = "['TAG_MyActionName', _this] call TAG_fnc_MyAnalogHandler";	// _this is the scalar analog value.
		analogChangeThreshold = 0.01; // Minimum change required to trigger the onAnalog EH (default: 0.01).
	};
};


Adding a new key

Defining a new action in CfgUserActions

class CfgUserActions
{
	class TAG_MyActionName // This class name is used for internal representation and also for the inputAction command.
	{
		displayName = "My Test Action";
		tooltip = "This action is for testing.";
		onActivate = "_this call TAG_fnc_MyHandler";		// _this is always true.
		onDeactivate = "_this call TAG_fnc_MyHandler";		// _this is always false.
		onAnalog = "_this call TAG_fnc_MyAnalogHandler";	// _this is the scalar analog value.
		analogChangeThreshold = 0.1; // Minimum change required to trigger the onAnalog EH (default: 0.01).
	};
};

Defining a default keybind in CfgDefaultKeysPresets

class CfgDefaultKeysPresets
{
	class Arma2 // Arma2 is inherited by all other presets.
	{
		class Mappings
		{
			TAG_MyActionName[] = {
				0x25, // DIK_K
				"256 + 0x25", // 256 is the bitflag for "doubletap", 0x25 is the DIK code for K.
				"0x00010000 + 2" // 0x00010000 is the bitflag for "mouse button".
			};
		};
	};
};
If the key code is large enough, for example 0x1D130023 (Ctrl + H), then adding values may lead to a wrong result due to rounding errors (see Number - Floating-point Precision). As such, it is recommended to do the calculation manually and use that value instead.

Adding a keybind to the keybind options dialog

class UserActionGroups
{
	class ModSection // Unique classname of your category.
	{
		name = "Mod Section"; // Display name of your category.
		isAddon = 1;
		group[] = {"TAG_MyActionName"};
	};
};

Setting up a collision group (optional)

Class UserActionsConflictGroups provides the ability to configure checks for keybinding collisions. The following example demonstrates how to ensure that the input does not conflict with car movement keybindings:

class UserActionsConflictGroups
{
	class ActionGroups
	{
		TAG_MyActionGroup[] = {"TAG_MyActionName"};
	};

	class CollisionGroups
	{
		// Add your group to an existing collision group:
		carMove[] += {"TAG_MyActionGroup"};

		// Or alternatively add your own collision group (which is usually preferrable):
		TAG_MyActionGroupCollisions[] = {"basic", "vehBasic", "HeadMove", "TAG_MyActionGroup"};
	};
};


Scripted Event Handlers

addUserActionEventHandler ["ReloadMagazine", "Activate", { systemChat "Reloading!"; removeUserActionEventHandler ["ReloadMagazine", "Activate", _thisEventHandler]; }];

The persistence of these EHs is the same as that of Mission Event Handlers - they are scoped per mission and get removed when the mission ends.

See Also:


Defining key codes

A key code is defined by 4 bytes (2 hexadecimal digits), each containing a different part of the keycode:

0x aa bb cc dd Result
Description Combo key Device types Main key additional info Main key
Examples
1. A + 2×B DIK_A (0x1E) INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_KB (0x13) DOUBLE TAP (0x10) DIK_B (0x30) 0x1E130130
2. A + MMB click DIK_A (0x1E) INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_MB (0x11) None (0x00) MOUSE_BUTTONS_MIDDLE + MOUSE_CLICK_OFFSET (0x82) 0x1E110002
3. A + Mouse Left (Move) DIK_A (0x1E) INPUT_DEVICE_COMBO_KB + INPUT_DEVICE_MAIN_MB (0x11) None (0x00) MOUSE_AXIS_LEFT (0x00) 0x1E110000
4. LMB click + MMB click MOUSE_BUTTONS_MIDDLE + MOUSE_CLICK_OFFSET (0x82) INPUT_DEVICE_COMBO_MB + INPUT_DEVICE_MAIN_MB (0x31) None (0x00) MOUSE_BUTTONS_LEFT + MOUSE_CLICK_OFFSET (0x80) 0x02310000

aa - Combo key

This is the exact same as #dd - Main key, but for the combo key.

If there is not a combo key, use 0x00.

bb - Device types

This specifies the type of the main key, and optionally the combo key.

For a single keybind, use INPUT_DEVICE_SOLO_xx, but for a combo keybind add together the results of INPUT_DEVICE_COMBO_xx and INPUT_DEVICE_MAIN_xx.

// Secondary combo types:
#define INPUT_DEVICE_COMBO_KB 0x00100000 // Keyboard button (key)
#define INPUT_DEVICE_COMBO_MB 0x00300000 // Mouse button
#define INPUT_DEVICE_COMBO_JB 0x00500000 // Joystick button
#define INPUT_DEVICE_COMBO_JP 0x00600000 // Joystick POV
#define INPUT_DEVICE_COMBO_XI 0x00900000 // Xbox controller (XInput)

// Main combo types:
#define INPUT_DEVICE_MAIN_MB 0x00010000 // Mouse button
#define INPUT_DEVICE_MAIN_MA 0x00020000 // Mouse axis
#define INPUT_DEVICE_MAIN_KB 0x00030000 // Keyboard button (key)
#define INPUT_DEVICE_MAIN_JB 0x00040000 // Joystick button
#define INPUT_DEVICE_MAIN_JA 0x00050000 // Joystick axis
#define INPUT_DEVICE_MAIN_JP 0x00060000 // Joystick POV
#define INPUT_DEVICE_MAIN_XI 0x00070000 // Xbox controller (XInput)
#define INPUT_DEVICE_MAIN_TR 0x00080000 // Movement tracking device

// Device types:
#define INPUT_DEVICE_SOLO_KB 0x00000000 // Keyboard button (key)
#define INPUT_DEVICE_SOLO_MB 0x00010000 // Mouse button
#define INPUT_DEVICE_SOLO_JB 0x00020000 // Joystick button
#define INPUT_DEVICE_SOLO_JA 0x00030000 // Joystick axis
#define INPUT_DEVICE_SOLO_JP 0x00040000 // Joystick POV
#define INPUT_DEVICE_SOLO_XI 0x00050000 // XInput device
#define INPUT_DEVICE_SOLO_TR 0x00080000 // EyeXTracker, TrackIR, FreeTrack, ... exclusive, in this preference
#define INPUT_DEVICE_SOLO_MA 0x00100000 // Mouse axis

cc - Main key additional info

Depending on what the main key is, this can provide additional parameters to the main key

The most common is double tap.

#define MAIN_INFO_NONE 0x00000000
#define MAIN_INFO_DOUBLE_TAP 0x00000100

dd - Main key

Keyboard Input

For keyboard input, the main key is the DIK keycode of the corresponding key.

Mouse Button

For mouse button input, you use the following value, added to an offset depending on if you would like a click or a hold.

enum MouseButtons
{
	MOUSE_BUTTONS_LEFT		= 0,
	MOUSE_BUTTONS_RIGHT		= 1,
	MOUSE_BUTTONS_MIDDLE	= 2,
	MOUSE_BUTTONS_CUSTOM_1	= 3,
	MOUSE_BUTTONS_CUSTOM_2	= 4,
	MOUSE_BUTTONS_CUSTOM_3	= 5,
	MOUSE_BUTTONS_CUSTOM_4	= 6,
	MOUSE_BUTTONS_CUSTOM_5	= 7
};

#define MOUSE_HOLD_OFFSET	0x00
#define MOUSE_CLICK_OFFSET	0x80 // Offset for mouse button click (compared to hold)

Mouse Axis

enum MouseAxis
{
	MOUSE_AXIS_LEFT = 0,
	MOUSE_AXIS_RIGHT = 1,
	MOUSE_AXIS_UP = 2,
	MOUSE_AXIS_DOWN = 3, // Last actual mouse axis, change N_MOUSE_AXES if adding new axis
	MOUSE_AXIS_WHEEL_UP = 4,
	MOUSE_AXIS_WHEEL_DOWN = 5
};

Head Tracker

For head tracker or mouse axis input, the following constants are available:

enum MovementTrackerAxis
{
	TRACK_PITCH = 0,	// Up / down rotation
	TRACK_YAW = 1,		// Left / right rotation
	TRACK_ROLL = 2,		// Side roll
	TRACK_X = 3,		// Left / right move
	TRACK_Y = 4,		// Up / down move
	TRACK_Z = 5		 // Forward / backward move
};

Joysticks

#define N_JOYSTICK_AXES		8 // 3 normal, 3 rotate, 2 sliders
#define N_JOYSTICK_POV		8 // 8 directional stick

There are up to 256 joystick buttons available.