Skip to content

Commit

Permalink
fix keyHandler becoming unremovable if added to two different keys (#653
Browse files Browse the repository at this point in the history
)

* fix keyHandler becoming unremovable if added two different keys

* fix strange modifier key behavior (#654)

* fix strange modifier key behaviour

* disable modifier state in keyDown if released
  • Loading branch information
commy2 committed May 1, 2017
1 parent 8590630 commit e3e6300
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
4 changes: 4 additions & 0 deletions addons/events/XEH_preInit.sqf
Expand Up @@ -79,3 +79,7 @@ GVAR(keyHoldTimers) = call CBA_fnc_createNamespace;

false
}] call CBA_fnc_compileFinal;

GVAR(shift) = false;
GVAR(control) = false;
GVAR(alt) = false;
6 changes: 6 additions & 0 deletions addons/events/fnc_addKeyHandler.sqf
Expand Up @@ -69,6 +69,12 @@ if (_type isEqualTo "keydown") then {
};

private _hash = [GVAR(keyHandlersDown), GVAR(keyHandlersUp)] select (_type == "keyup");

// fix using addKeyHander twice on different keys makes old handler unremovable
if (!isNil {_hash getVariable _hashKey}) then {
[_hashKey, _type] call CBA_fnc_removeKeyHandler;
};

_hash setVariable [_hashKey, [_key, _settings, _code, _allowHold, _holdDelay]];

private _keyHandlers = [GVAR(keyDownStates), GVAR(keyUpStates)] select (_type == "keyup");
Expand Down
27 changes: 26 additions & 1 deletion addons/events/fnc_keyHandlerDown.sqf
Expand Up @@ -15,7 +15,32 @@ params ["", "_inputKey"];

if (_inputKey isEqualTo 0) exitWith {};

private _inputModifiers = _this select [2,3];
// handle modifiers
switch (true) do {
case (_inputKey in [DIK_LSHIFT, DIK_RSHIFT]): {
GVAR(shift) = true;
};
case (_inputKey in [DIK_LCONTROL, DIK_RCONTROL]): {
GVAR(control) = true;
};
case (_inputKey in [DIK_LMENU, DIK_RMENU]): {
GVAR(alt) = true;
};
};

if !(_this select 2) then {
GVAR(shift) = false;
};

if !(_this select 3) then {
GVAR(control) = false;
};

if !(_this select 4) then {
GVAR(alt) = false;
};

private _inputModifiers = [GVAR(shift), GVAR(control), GVAR(alt)];

private _blockInput = false;

Expand Down
13 changes: 13 additions & 0 deletions addons/events/fnc_keyHandlerUp.sqf
Expand Up @@ -15,6 +15,19 @@ params ["", "_inputKey"];

if (_inputKey isEqualTo 0) exitWith {};

// handle modifiers
switch (true) do {
case (_inputKey in [DIK_LSHIFT, DIK_RSHIFT]): {
GVAR(shift) = false;
};
case (_inputKey in [DIK_LCONTROL, DIK_RCONTROL]): {
GVAR(control) = false;
};
case (_inputKey in [DIK_LMENU, DIK_RMENU]): {
GVAR(alt) = false;
};
};

private _removeHandlers = [];

{
Expand Down
4 changes: 1 addition & 3 deletions addons/events/fnc_mouseHandlerDown.sqf
Expand Up @@ -13,6 +13,4 @@ SCRIPT(mouseHandlerDown);

params ["_display", "_inputButton"];

private _inputModifiers = _this select [4,3];

([_display, MOUSE_OFFSET + _inputButton] + _inputModifiers) call FUNC(keyHandlerDown);
[_display, MOUSE_OFFSET + _inputButton, GVAR(shift), GVAR(control), GVAR(alt)] call FUNC(keyHandlerDown);
4 changes: 1 addition & 3 deletions addons/events/fnc_mouseHandlerUp.sqf
Expand Up @@ -13,6 +13,4 @@ SCRIPT(mouseHandlerUp);

params ["_display", "_inputButton"];

private _inputModifiers = _this select [4,3];

([_display, MOUSE_OFFSET + _inputButton] + _inputModifiers) call FUNC(keyHandlerUp);
[_display, MOUSE_OFFSET + _inputButton, GVAR(shift), GVAR(control), GVAR(alt)] call FUNC(keyHandlerUp);
4 changes: 2 additions & 2 deletions addons/events/fnc_mouseWheelHandler.sqf
Expand Up @@ -15,5 +15,5 @@ params ["_display", "_inputDirection"];

private _inputDirection = [0, 1] select (_inputDirection < 0);

[_display, MOUSE_WHEEL_OFFSET + _inputDirection, false, false, false] call FUNC(keyHandlerDown);
[_display, MOUSE_WHEEL_OFFSET + _inputDirection, false, false, false] call FUNC(keyHandlerUp);
[_display, MOUSE_WHEEL_OFFSET + _inputDirection, GVAR(shift), GVAR(control), GVAR(alt)] call FUNC(keyHandlerDown);
[_display, MOUSE_WHEEL_OFFSET + _inputDirection, GVAR(shift), GVAR(control), GVAR(alt)] call FUNC(keyHandlerUp);

0 comments on commit e3e6300

Please sign in to comment.