Skip to content

Commit

Permalink
handle input gracefully in keybinding editKey ui function (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 committed Jul 12, 2018
1 parent 4c160a5 commit 3687f67
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions addons/keybinding/fnc_gui_editKey.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,38 @@ _ctrlKeyList setVariable [QGVAR(defaultKeybind), _defaultKeybind];

// --- record keys
_display displayAddEventHandler ["KeyDown", {
params ["_display", "_key", "_shift", "_control", "_alt"];
private _ctrlKeyList = _display displayCtrl IDC_CONFIGURE_ACTION_KEYS;
call {
params ["_display", "_key", "_shift", "_control", "_alt"];
private _ctrlKeyList = _display displayCtrl IDC_CONFIGURE_ACTION_KEYS;

if (_key <= DIK_ESCAPE) exitWith {};
if (_key in [DIK_LSHIFT, DIK_RSHIFT, DIK_LCONTROL, DIK_RCONTROL, DIK_LMENU, DIK_RMENU]) exitWith {};
if (!isNil {_ctrlKeyList getVariable QGVAR(lock)}) exitWith {};
if (_key <= DIK_ESCAPE) exitWith {false};
if (_key in [DIK_LSHIFT, DIK_RSHIFT, DIK_LCONTROL, DIK_RCONTROL, DIK_LMENU, DIK_RMENU]) exitWith {true};
if (!isNil {_ctrlKeyList getVariable QGVAR(lock)}) exitWith {true};

private _keybind = [_key, [_shift, _control, _alt]];
private _keyName = _keybind call CBA_fnc_localizeKey;
private _keybind = [_key, [_shift, _control, _alt]];
private _keyName = _keybind call CBA_fnc_localizeKey;

// if key already in list, remove instead
private _doAdd = true;
// if key already in list, remove instead
private _doAdd = true;

for "_index" from 0 to (lbSize _ctrlKeyList - 1) do {
if (_ctrlKeyList lbData _index == str _keybind) exitWith {
_ctrlKeyList lbDelete _index;
_doAdd = false;
for "_index" from 0 to (lbSize _ctrlKeyList - 1) do {
if (_ctrlKeyList lbData _index == str _keybind) exitWith {
_ctrlKeyList lbDelete _index;
_doAdd = false;
};
};
};

if (_doAdd) then {
private _index = _ctrlKeyList lbAdd _keyName;
_ctrlKeyList lbSetData [_index, str _keybind];
_ctrlKeyList lbSetCurSel _index;
};
if (_doAdd) then {
private _index = _ctrlKeyList lbAdd _keyName;
_ctrlKeyList lbSetData [_index, str _keybind];
_ctrlKeyList lbSetCurSel _index;
};

_ctrlKeyList call (_ctrlKeyList getVariable QFUNC(showDuplicates));
_ctrlKeyList call (_ctrlKeyList getVariable QFUNC(showDuplicates));

_ctrlKeyList setVariable [QGVAR(lock), true];
_ctrlKeyList setVariable [QGVAR(lock), true];
true
};
}];

_display displayAddEventHandler ["KeyUp", {
Expand Down

0 comments on commit 3687f67

Please sign in to comment.