refactor: converted keycodes into an enum

This commit is contained in:
Gerard Gascón 2024-04-17 17:21:28 +02:00
parent 2cae1eced7
commit e3f6db7ae5
15 changed files with 58 additions and 19 deletions

View file

@ -11,8 +11,13 @@ namespace Domain {
private const int CustomKeysSize = 5;
private const int SpecialKeysSize = 1;
private readonly int[] _customKeys = { 191, 51, 222, 186 };
private readonly int[] _specialKeys = { 0x10 };
private readonly VKeyCode[] _customKeys = {
VKeyCode.Cedilla,
VKeyCode.Interpunct,
VKeyCode.AccentClosed,
VKeyCode.AccentOpen
};
private readonly VKeyCode[] _specialKeys = { VKeyCode.Shift };
private readonly bool[] _isPressed = new bool[AlphabetSize + CustomKeysSize + SpecialKeysSize];
private readonly bool[] _wasPressed = new bool[AlphabetSize + CustomKeysSize + SpecialKeysSize];
@ -41,11 +46,11 @@ namespace Domain {
for (int i = 0; i < _customKeys.Length; i++) {
int pressIndex = AlphabetSize + i;
_wasPressed[pressIndex] = _isPressed[pressIndex];
short state = Win32API.GetAsyncKeyState(_customKeys[i]);
short state = Win32API.GetAsyncKeyState((int)_customKeys[i]);
if (!_wasPressed[pressIndex] && state != 0) {
_isPressed[pressIndex] = true;
KeyPressed(_customKeys[i]);
KeyPressed((int)_customKeys[i]);
}else if (_isPressed[pressIndex] && state == 0) {
_isPressed[pressIndex] = false;
}
@ -54,11 +59,11 @@ namespace Domain {
for (int i = 0; i < _specialKeys.Length; i++) {
int pressIndex = AlphabetSize + CustomKeysSize + i;
_wasPressed[pressIndex] = _isPressed[pressIndex];
short state = Win32API.GetAsyncKeyState(_specialKeys[i]);
short state = Win32API.GetAsyncKeyState((int)_specialKeys[i]);
if (!_wasPressed[pressIndex] && state != 0) {
_isPressed[pressIndex] = true;
KeyPressed(_specialKeys[i], true);
KeyPressed((int)_specialKeys[i], true);
}else if (_isPressed[pressIndex] && state == 0) {
_isPressed[pressIndex] = false;
}