-
Notifications
You must be signed in to change notification settings - Fork 3
/
events.h
77 lines (66 loc) · 1.57 KB
/
events.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
#ifndef EVENTS_H
#define EVENTS_H
#include "key_map.h"
static const int kMaxEvents = 6;
static const int kMaxButtons = msd - mlc + 1;
struct Events {
Events() { Reset(); }
void Reset() {
modifiers = 0;
for (int i = 0; i < kMaxEvents; ++i) keys[i].key = 0;
for (int i = 0; i < kMaxButtons; ++i) buttons[i] = 0;
}
void AddTappedKey(int key) {
AddPressedKey(key, -1, -1);
}
bool ClearTapping() {
bool cleared = false;
for (int i = 0; i < kMaxEvents; ++i) {
if (keys[i].key && keys[i].row == -1) {
keys[i].key = 0;
cleared = true;
}
}
return cleared;
}
void AddPressedKey(int key, int row, int col) {
for (int i = 0; i < kMaxEvents; ++i) {
if (keys[i].key != 0 &&
keys[i].row == row && keys[i].col == col) return;
}
for (int i = 0; i < kMaxEvents; ++i) {
if (keys[i].key == 0) {
keys[i].key = key;
keys[i].row = row;
keys[i].col = col;
// Keyboard.println(key);
return;
}
}
}
void RemoveReleasedKey(int row, int col) {
for (int i = 0; i < kMaxEvents; ++i) {
if (keys[i].row == row && keys[i].col == col) {
// Keyboard.println(-keys[i].key);
keys[i].key = 0;
return;
}
}
}
bool HasAnyKey() const {
for (int i = 0; i < kMaxEvents; ++i) {
if (keys[i].key) return true;
}
return false;
}
int modifiers = 0;
struct {
int key;
int row;
int col;
bool repeated = false;
unsigned send_time;
} keys[kMaxEvents];
int buttons[msd - mlc + 1];
};
#endif