-
Notifications
You must be signed in to change notification settings - Fork 11
/
steno_key_state.h
122 lines (105 loc) · 2.12 KB
/
steno_key_state.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//---------------------------------------------------------------------------
#pragma once
#include "stroke.h"
//---------------------------------------------------------------------------
enum class StenoKey : int8_t {
S1,
S2,
TL,
KL,
PL,
WL,
HL,
RL,
A,
O,
STAR1,
STAR2,
STAR3,
STAR4,
E,
U,
FR,
RR,
PR,
BR,
LR,
GR,
TR,
SR,
DR,
ZR,
NUM1,
NUM2,
NUM3,
NUM4,
NUM5,
NUM6,
NUM7,
NUM8,
NUM9,
NUM10,
NUM11,
NUM12,
FUNCTION, // X1
POWER, // X2
RES1, // X3
RES2, // X4
X1 = FUNCTION,
X2,
X3,
X4,
X5,
X6,
X7,
X8,
X9,
X10,
X11,
X12,
X13,
X14,
X15,
X16,
X17,
X18,
X19,
X20,
X21,
X22,
X23,
X24,
X25,
X26,
COUNT,
NONE = -1
};
static_assert(int(StenoKey::COUNT) == 64, "Expect StenoKey to have 64 bits");
//---------------------------------------------------------------------------
// This represents all of the steno keys, where different keys (e.g. number,
// star, S) are represented by the *different* bits.
class StenoKeyState {
public:
constexpr StenoKeyState(uint64_t keyState = 0) : keyState(keyState) {}
void Process(StenoKey keycode, bool isPress);
void Reset() { keyState = 0; }
bool IsEmpty() const { return keyState == 0; }
bool IsNotEmpty() const { return keyState != 0; }
bool operator==(const StenoKeyState &other) const = default;
StenoKeyState operator~() const { return StenoKeyState(~keyState); }
StenoKeyState operator&(const StenoKeyState &other) const {
return StenoKeyState(keyState & other.keyState);
}
StenoKeyState operator|(const StenoKeyState &other) const {
return StenoKeyState(keyState | other.keyState);
}
void operator&=(const StenoKeyState &other) { keyState &= other.keyState; }
void operator|=(const StenoKeyState &other) { keyState |= other.keyState; }
StenoStroke ToStroke() const;
uint64_t GetRawKeyState() const { return keyState; }
// Public so that config can overwrite S1 -> NUM1.
static int8_t STROKE_BIT_INDEX_LOOKUP[];
private:
uint64_t keyState;
};
//---------------------------------------------------------------------------