refactor: converted keycodes into an enum
This commit is contained in:
parent
2cae1eced7
commit
e3f6db7ae5
15 changed files with 58 additions and 19 deletions
|
@ -3,6 +3,40 @@ using System.Linq;
|
||||||
using Domain.Input;
|
using Domain.Input;
|
||||||
|
|
||||||
namespace Domain {
|
namespace Domain {
|
||||||
|
public enum VKeyCode {
|
||||||
|
A = 0x41,
|
||||||
|
B = 0x42,
|
||||||
|
C = 0x43,
|
||||||
|
D = 0x44,
|
||||||
|
E = 0x45,
|
||||||
|
F = 0x46,
|
||||||
|
G = 0x47,
|
||||||
|
H = 0x48,
|
||||||
|
I = 0x49,
|
||||||
|
J = 0x4A,
|
||||||
|
K = 0x4B,
|
||||||
|
L = 0x4C,
|
||||||
|
M = 0x4D,
|
||||||
|
N = 0x4E,
|
||||||
|
O = 0x4F,
|
||||||
|
P = 0x50,
|
||||||
|
Q = 0x51,
|
||||||
|
R = 0x52,
|
||||||
|
S = 0x53,
|
||||||
|
T = 0x54,
|
||||||
|
U = 0x55,
|
||||||
|
V = 0x56,
|
||||||
|
W = 0x57,
|
||||||
|
X = 0x58,
|
||||||
|
Y = 0x59,
|
||||||
|
Z = 0x5A,
|
||||||
|
Interpunct = 0x33,
|
||||||
|
Cedilla = 0xBF,
|
||||||
|
AccentOpen = 0xBA,
|
||||||
|
AccentClosed = 0xDE,
|
||||||
|
Shift = 0x10
|
||||||
|
}
|
||||||
|
|
||||||
public class CustomInput {
|
public class CustomInput {
|
||||||
private readonly List<InputReader> _readers = new();
|
private readonly List<InputReader> _readers = new();
|
||||||
private readonly KeyHistory _history;
|
private readonly KeyHistory _history;
|
||||||
|
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class AObertaReader : InputReader {
|
public class AObertaReader : InputReader {
|
||||||
public AObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x41 }, 0x10, false) { }
|
public AObertaReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.AccentOpen, (int)VKeyCode.A }, (int)VKeyCode.Shift, false) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class CedillaReader : InputReader {
|
public class CedillaReader : InputReader {
|
||||||
public CedillaReader(KeyHistory history) : base(history, new List<int>{ 0xBF }) { }
|
public CedillaReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.Cedilla }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class EObertaReader : InputReader {
|
public class EObertaReader : InputReader {
|
||||||
public EObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x45 }, 0x10, false) { }
|
public EObertaReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.AccentOpen, (int)VKeyCode.E }, (int)VKeyCode.Shift, false) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class GeminadaReader : InputReader {
|
public class GeminadaReader : InputReader {
|
||||||
public GeminadaReader(KeyHistory history) : base(history, new List<int>{ 76, 0x33, 76 }) { }
|
public GeminadaReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.L, (int)VKeyCode.Interpunct, (int)VKeyCode.L }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class IDieresiReader : InputReader {
|
public class IDieresiReader : InputReader {
|
||||||
public IDieresiReader(KeyHistory history) : base(history, new List<int>{ 0xDE, 0x49 }, 0x10, true) { }
|
public IDieresiReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.AccentClosed, (int)VKeyCode.I }, (int)VKeyCode.Shift, true) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class IxReader : InputReader {
|
public class IxReader : InputReader {
|
||||||
public IxReader(KeyHistory history) : base(history, new List<int>{ 0x49, 0x58 }) { }
|
public IxReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.I, (int)VKeyCode.X }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class LlReader : InputReader {
|
public class LlReader : InputReader {
|
||||||
public LlReader(KeyHistory history) : base(history, new List<int>{ 0x4C, 0x4C }) { }
|
public LlReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.L, (int)VKeyCode.L }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class NyReader : InputReader {
|
public class NyReader : InputReader {
|
||||||
public NyReader(KeyHistory history) : base(history, new List<int>{ 0x4E, 0x59 }) { }
|
public NyReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.N, (int)VKeyCode.Y }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class OObertaReader : InputReader {
|
public class OObertaReader : InputReader {
|
||||||
public OObertaReader(KeyHistory history) : base(history, new List<int>{ 0xBA, 0x4F }, 0x10, false) { }
|
public OObertaReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.AccentOpen, (int)VKeyCode.O }, (int)VKeyCode.Shift, false) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class SsReader : InputReader {
|
public class SsReader : InputReader {
|
||||||
public SsReader(KeyHistory history) : base(history, new List<int>{ 0x53, 0x53 }) { }
|
public SsReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.S, (int)VKeyCode.S }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class TgReader : InputReader {
|
public class TgReader : InputReader {
|
||||||
public TgReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x47 }) { }
|
public TgReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.T, (int)VKeyCode.G }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class TjReader : InputReader {
|
public class TjReader : InputReader {
|
||||||
public TjReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x4A }) { }
|
public TjReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.T, (int)VKeyCode.J }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ using System.Linq;
|
||||||
|
|
||||||
namespace Domain.Input {
|
namespace Domain.Input {
|
||||||
public class TxReader : InputReader {
|
public class TxReader : InputReader {
|
||||||
public TxReader(KeyHistory history) : base(history, new List<int>{ 0x54, 0x58 }) { }
|
public TxReader(KeyHistory history) : base(history, new List<int>{ (int)VKeyCode.T, (int)VKeyCode.X }) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,8 +11,13 @@ namespace Domain {
|
||||||
private const int CustomKeysSize = 5;
|
private const int CustomKeysSize = 5;
|
||||||
private const int SpecialKeysSize = 1;
|
private const int SpecialKeysSize = 1;
|
||||||
|
|
||||||
private readonly int[] _customKeys = { 191, 51, 222, 186 };
|
private readonly VKeyCode[] _customKeys = {
|
||||||
private readonly int[] _specialKeys = { 0x10 };
|
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[] _isPressed = new bool[AlphabetSize + CustomKeysSize + SpecialKeysSize];
|
||||||
private readonly bool[] _wasPressed = 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++) {
|
for (int i = 0; i < _customKeys.Length; i++) {
|
||||||
int pressIndex = AlphabetSize + i;
|
int pressIndex = AlphabetSize + i;
|
||||||
_wasPressed[pressIndex] = _isPressed[pressIndex];
|
_wasPressed[pressIndex] = _isPressed[pressIndex];
|
||||||
short state = Win32API.GetAsyncKeyState(_customKeys[i]);
|
short state = Win32API.GetAsyncKeyState((int)_customKeys[i]);
|
||||||
|
|
||||||
if (!_wasPressed[pressIndex] && state != 0) {
|
if (!_wasPressed[pressIndex] && state != 0) {
|
||||||
_isPressed[pressIndex] = true;
|
_isPressed[pressIndex] = true;
|
||||||
KeyPressed(_customKeys[i]);
|
KeyPressed((int)_customKeys[i]);
|
||||||
}else if (_isPressed[pressIndex] && state == 0) {
|
}else if (_isPressed[pressIndex] && state == 0) {
|
||||||
_isPressed[pressIndex] = false;
|
_isPressed[pressIndex] = false;
|
||||||
}
|
}
|
||||||
|
@ -54,11 +59,11 @@ namespace Domain {
|
||||||
for (int i = 0; i < _specialKeys.Length; i++) {
|
for (int i = 0; i < _specialKeys.Length; i++) {
|
||||||
int pressIndex = AlphabetSize + CustomKeysSize + i;
|
int pressIndex = AlphabetSize + CustomKeysSize + i;
|
||||||
_wasPressed[pressIndex] = _isPressed[pressIndex];
|
_wasPressed[pressIndex] = _isPressed[pressIndex];
|
||||||
short state = Win32API.GetAsyncKeyState(_specialKeys[i]);
|
short state = Win32API.GetAsyncKeyState((int)_specialKeys[i]);
|
||||||
|
|
||||||
if (!_wasPressed[pressIndex] && state != 0) {
|
if (!_wasPressed[pressIndex] && state != 0) {
|
||||||
_isPressed[pressIndex] = true;
|
_isPressed[pressIndex] = true;
|
||||||
KeyPressed(_specialKeys[i], true);
|
KeyPressed((int)_specialKeys[i], true);
|
||||||
}else if (_isPressed[pressIndex] && state == 0) {
|
}else if (_isPressed[pressIndex] && state == 0) {
|
||||||
_isPressed[pressIndex] = false;
|
_isPressed[pressIndex] = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue