-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboard.cpp
More file actions
85 lines (70 loc) · 1.69 KB
/
Keyboard.cpp
File metadata and controls
85 lines (70 loc) · 1.69 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
80
81
82
83
84
85
#pragma once
#ifndef KEYBOARD
#define KEYBOARD
#include <cstdint>
#include <cstdlib>
#include "Keymap.h"
void keyboard_init() {
keyboardPtr = malloc(512);
}
void onKeyDown(void* keymap, uint8_t keyCode);
void onKeyUp(void* keymap, uint8_t keyCode);
class KeyBoard {
uint8_t last = 0;
public:
bool keys[128]{};
bool shift = false;
bool capsLock = false;
bool ctrl = false;
bool alt = false;
bool super = false;
KeyMap* keymap{};
static KeyBoard* getInstance() {
return static_cast<KeyBoard*>(keyboardPtr);
}
char getChar(const uint8_t code) const {
if (this->shift) {
return this->keymap->mapShifted[code];
}
return this->keymap->map[code];
}
void handle() {
uint8_t key = inb(0x60);
if (key == this->last) {
return;
}
this->last = key;
bool down;
if (key >= 0x80) {
key -= 0x80;
down = false;
} else {
down = true;
}
switch (key) {
case 0x2A:
case 0x36:
this->shift = down;
break;
case 0x1D:
this->ctrl = down;
break;
case 0x38:
this->alt = down;
break;
case 0x5B:
case 0x5C:
this->super = down;
break;
default:
if (down) {
this->keys[key] = true;
onKeyDown(this, key);
} else {
this->keys[key] = false;
onKeyUp(this, key);
}
}
}
};
#endif