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

add mouse button translations #652

Merged
merged 2 commits into from
May 1, 2017
Merged
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
4 changes: 4 additions & 0 deletions addons/events/XEH_preInit.sqf
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
16 changes: 16 additions & 0 deletions addons/keybinding/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ _supportedKeys = _supportedKeys apply {

GVAR(keyNamesHash) = [_supportedKeys] call CBA_fnc_hashCreate;

// manually add mouse key localizations to our inofficial DIK codes
{
[GVAR(keyNamesHash), str (_x select 0), parseSimpleArray format ["[%1]", keyName (_x select 1)] select 0] call CBA_fnc_hashSet;
} forEach [
[0xF0, 0x10000],
[0xF1, 0x10081],
[0xF2, 0x10002],
[0xF3, 0x10003],
[0xF4, 0x10004],
[0xF5, 0x10005],
[0xF6, 0x10006],
[0xF7, 0x10007],
[0xF8, 0x100004],
[0xF9, 0x100005]
];

GVAR(forbiddenKeys) = [
DIK_XBOX_LEFT_TRIGGER,
DIK_XBOX_RIGHT_TRIGGER,
Expand Down