diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 25899db1ae9..bc4c9912478 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -7,6 +7,7 @@ PREP(cbaSettings_settingChanged); PREP(cbaSettings_transferUserSettings); PREP(readSettingsFromParamsArray); +PREP(actionKeyPressed); PREP(actionKeysNamesConverted); PREP(addCanInteractWithCondition); PREP(addLineToDebugDraw); diff --git a/addons/common/functions/fnc_actionKeyPressed.sqf b/addons/common/functions/fnc_actionKeyPressed.sqf new file mode 100644 index 00000000000..c4ab3a39c3f --- /dev/null +++ b/addons/common/functions/fnc_actionKeyPressed.sqf @@ -0,0 +1,48 @@ +#include "..\script_component.hpp" +#include "\a3\ui_f\hpp\defineDIKCodes.inc" +/* + * Author: PabstMirror + * Checks if actionName is being pressed (from ui "KeyDown" event data) + * Limitations: Does not check joysticks, different left/right modifier keys, double tap binds + * + * Arguments: + * 0: Action Name + * 1: Key + * 2: Shift + * 3: Ctrl + * 4: Alt + * + * Return Value: + * + * + * Example: + * ["Watch", 24, false, false, false] call ace_common_fnc_actionKeyPressed + * ["TeamSwitch", 22, false, true, false] call ace_common_fnc_actionKeyPressed + * + * Public: No + */ + + params [["_actionName", "", [""]], ["_key", -1, [0]], ["_shift", false, [false]], ["_ctrl", false, [false]], ["_alt", false, [false]]]; + +private _return = false; +private _actionKeys = actionKeysEx _actionName; +{ + _x params [["_mainKeyArray", []], ["_comboKeyArray", []], ["_isDoubleTap", false]]; + _mainKeyArray params ["_mainDik", "_mainDevice"]; + if ( + (_mainDik == _key) + && {_mainDevice == "KEYBOARD"} + && (if (_comboKeyArray isEqualTo []) then { + (!_shift) && {!_ctrl} && {!_alt} + } else { + _comboKeyArray params ["_comboDik", "_comboDevice"]; + (_comboDevice == "KEYBOARD") + && {(_shift) isEqualTo (_comboDik in [DIK_LSHIFT,DIK_RSHIFT])} + && {(_ctrl) isEqualTo (_comboDik in [DIK_LCONTROL,DIK_RCONTROL])} + && {(_alt) isEqualTo (_comboDik in [DIK_LALT, DIK_RALT])} + }) + && {!_isDoubleTap} + ) exitWith { _return = true }; +} forEach _actionKeys; + +_return diff --git a/addons/common/functions/fnc_disableUserInput.sqf b/addons/common/functions/fnc_disableUserInput.sqf index 629d5b42e54..95e7d251dbc 100644 --- a/addons/common/functions/fnc_disableUserInput.sqf +++ b/addons/common/functions/fnc_disableUserInput.sqf @@ -46,7 +46,7 @@ if (_state) then { _map ctrlMapCursor ["", QGVAR(blank)]; _display displayAddEventHandler ["KeyDown", { - params ["", "_key"]; + params ["", "_key", "_shift", "_ctrl", "_alt"]; if (_key == 1 && {alive player}) then { createDialog (["RscDisplayInterrupt", "RscDisplayMPInterrupt"] select isMultiplayer); @@ -76,7 +76,7 @@ if (_state) then { _ctrl ctrlSetTooltip "Respawn."; }; - if (_key in actionKeys "TeamSwitch" && {teamSwitchEnabled}) then { + if ((["TeamSwitch", _key, _shift, _ctrl, _alt] call FUNC(actionKeyPressed)) && {teamSwitchEnabled}) then { (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0; private _acc = accTime;