Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Add function to check if action with modifier being pressed #9594

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PREP(cbaSettings_settingChanged);
PREP(cbaSettings_transferUserSettings);
PREP(readSettingsFromParamsArray);

PREP(actionKeyPressed);
PREP(actionKeysNamesConverted);
PREP(addCanInteractWithCondition);
PREP(addLineToDebugDraw);
Expand Down
48 changes: 48 additions & 0 deletions addons/common/functions/fnc_actionKeyPressed.sqf
Original file line number Diff line number Diff line change
@@ -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 <STRING>
* 1: Key <NUMBER>
* 2: Shift <BOOL>
* 3: Ctrl <BOOL>
* 4: Alt <BOOL>
*
* Return Value:
* <BOOL>
*
* 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"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&& {_mainDevice == "KEYBOARD"}
&& _mainDevice isEqualTo "KEYBOARD"

If the correct casing is always returns.

And surely the lazy eval doesn't save anything with such a cheap check.

&& (if (_comboKeyArray isEqualTo []) then {
(!_shift) && {!_ctrl} && {!_alt}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And surely the lazy eval doesn't save anything with such a cheap check.

Suggested change
(!_shift) && {!_ctrl} && {!_alt}
!_shift && !_ctrl && !_alt

} else {
_comboKeyArray params ["_comboDik", "_comboDevice"];
(_comboDevice == "KEYBOARD")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(_comboDevice == "KEYBOARD")
(_comboDevice isEqualTo "KEYBOARD")

If the correct casing is always returned.

&& {(_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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&& {!_isDoubleTap}
&& !_isDoubleTap

And surely the lazy eval doesn't save anything with such a cheap check.

) exitWith { _return = true };
} forEach _actionKeys;

_return
4 changes: 2 additions & 2 deletions addons/common/functions/fnc_disableUserInput.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down