-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboard.cpp
More file actions
79 lines (59 loc) · 1.6 KB
/
Copy pathKeyboard.cpp
File metadata and controls
79 lines (59 loc) · 1.6 KB
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
#include "Keyboard.h"
Keyboard::Keyboard() {
for (int i = 0; i < sizeof(this->keyStates); i++) {
this->keyStates[i] = false;
}
this->autoRepeatChars = false, this->autoRepeatKeys = false;
}
bool Keyboard::KeyIsPressed(const unsigned char keycode) {
return keyStates[keycode];
}
bool Keyboard::IsEventBufferEmpty() {
return eventBuffer.empty();
}
bool Keyboard::IsCharBufferEmpty() {
return charBuffer.empty();
}
KeyboardEvent Keyboard::ReadKey() {
if (this->eventBuffer.empty()) {
return KeyboardEvent();
}
KeyboardEvent e = this->eventBuffer.front(); // Storing the front event.
this->eventBuffer.pop(); // Removing the front event
return e;
}
unsigned char Keyboard::ReadChar() {
if (this->charBuffer.empty()) {
return 0u;
}
unsigned char c = this->charBuffer.front();
this->charBuffer.pop();
return c;
}
void Keyboard::OnKeyPressed(const unsigned char key) {
this->eventBuffer.push((KeyboardEvent(KeyboardEvent::EventType::Press, key)));
}
void Keyboard::OnKeyReleased(const unsigned char key) {
this->eventBuffer.push((KeyboardEvent(KeyboardEvent::EventType::Release, key)));
}
void Keyboard::OnChar(const unsigned char key) {
this->charBuffer.push(key);
}
void Keyboard::EnableAutoRepeatKeys() {
this->autoRepeatKeys = true;
}
void Keyboard::DisableAutoRepeatKeys() {
this->autoRepeatKeys = false;
}
void Keyboard::EnableAutoRepeatChars() {
this->autoRepeatChars = true;
}
void Keyboard::DisableAutoRepeatChars() {
this->autoRepeatChars = false;
}
bool Keyboard::IsKeysAutoRepeat() {
return this->autoRepeatKeys;
}
bool Keyboard::IsCharsAutoRepeat() {
return this->autoRepeatChars;
}