-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathkeyboard.h
155 lines (144 loc) · 3.64 KB
/
keyboard.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*****************************************
NanoShell Operating System
(C) 2021 iProgramInCpp
Keyboard module header file
******************************************/
#ifndef _KEYBOARD_H
#define _KEYBOARD_H
#include <main.h>
#include <console.h>
typedef uint8_t KeyState;
#define KEY_PRESSED ((KeyState) 1)
#define KEY_HELD ((KeyState) 2)
#define KEY_RELEASED ((KeyState) 0)
// Keycode definitions:
#if 1
#define KEY_UNDEFINED_0 0
#define KEY_ESC 1
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_8 9
#define KEY_9 10
#define KEY_0 11
#define KEY_MINUS 12
#define KEY_HYPHEN KEY_MINUS
#define KEY_EQUALS 13
#define KEY_BACKSPACE 14
#define KEY_TAB 15
#define KEY_A 0x1e
#define KEY_B 0x30
#define KEY_C 0x2e
#define KEY_D 0x20
#define KEY_E 0x12
#define KEY_F 0x21
#define KEY_G 0x22
#define KEY_H 0x23
#define KEY_I 0x17
#define KEY_J 0x24
#define KEY_K 0x25
#define KEY_L 0x26
#define KEY_M 0x32
#define KEY_N 0x31
#define KEY_O 0x18
#define KEY_P 0x19
#define KEY_Q 0x10
#define KEY_R 0x13
#define KEY_S 0x1f
#define KEY_T 0x14
#define KEY_U 0x16
#define KEY_V 0x2f
#define KEY_W 0x11
#define KEY_X 0x2d
#define KEY_Y 0x15
#define KEY_Z 0x2c
#define KEY_BRACKET_LEFT 0x1a
#define KEY_BRACKET_RIGHT 0x1b
#define KEY_ENTER 0x1c
#define KEY_CONTROL 0x1d
#define KEY_CTRL KEY_CONTROL
#define KEY_SEMICOLON 0x27
#define KEY_APOSTROPHE 0x28
#define KEY_BACKTICK 0x29
#define KEY_LSHIFT 0x2a
#define KEY_BACKSLASH 0x2b
#define KEY_COMMA 0x33
#define KEY_DOT 0x34
#define KEY_SLASH 0x35
#define KEY_RSHIFT 0x36
#define KEY_PRINTSCREEN 0x37
#define KEY_ALT 0x38
#define KEY_SPACE 0x39
#define KEY_CAPSLOCK 0x3a
#define KEY_F1 0x3b
#define KEY_F2 0x3c
#define KEY_F3 0x3d
#define KEY_F4 0x3e
#define KEY_F5 0x3f
#define KEY_F6 0x40
#define KEY_F7 0x41
#define KEY_F8 0x42
#define KEY_F9 0x43
#define KEY_F10 0x44
#define KEY_NUMLOCK 0x45
#define KEY_SCROLLLOCK 0x46
#define KEY_HOME 0x47
#define KEY_ARROW_UP 0x48
#define KEY_PAGEUP 0x49
#define KEY_NUMPAD_MINUS 0x4a
#define KEY_NUMPAD_HYPHEN KEY_NUMPAD_MINUS
#define KEY_ARROW_LEFT 0x4b
#define KEY_LEFT KEY_ARROW_LEFT
#define KEY_UNDEFINED_4C 0x4c
#define KEY_ARROW_RIGHT 0x4d
#define KEY_RIGHT KEY_ARROW_RIGHT
#define KEY_NUMPAD_PLUS 0x4e
#define KEY_END 0x4f
#define KEY_ARROW_DOWN 0x50
#define KEY_DOWN KEY_ARROW_DOWN
#define KEY_PAGEDOWN 0x51
#define KEY_INSERT 0x52
#define KEY_DELETE 0x53
#define KEY_UNDEFINED_54 0x54
#define KEY_UNDEFINED_55 0x55
#define KEY_UNDEFINED_56 0x56
#define KEY_F11 0x57
#define KEY_F12 0x58
#define KEY_UP KEY_ARROW_UP
#define KEY_MENU 0x5D
#endif
#define KEYBOARD_DATA_PORT 0x60
#define KEYBOARD_STATUS_PORT 0x64
#define SCANCODE_RELEASE 0x80
#define SCANCODE_NOTREL 0x7f
// Maps an AT or PS/2 key code to ASCII
char KbMapAtCodeToChar(char c);
void KbInit();
void IrqKeyboard();
void KbAddKeyToBuffer(char key);
char KbGetKeyFromBuffer();
char KbWaitForKeyAndGet();
void KbFlushBuffer();
bool KbIsBufferEmpty();
KeyState KbGetKeyState(unsigned char keycode);
void SetFocusedConsole(Console *pConsole);
bool KbIsRawBufferEmpty();
char KbGetKeyFromRawBuffer();
enum
{
KBPROPERTY_DELAY_BEFORE_REPEAT,
KBPROPERTY_REPEAT_FREQUENCY,
KBPROPERTY_DELAY_BEFORE_REPEAT_MAX,
KBPROPERTY_REPEAT_FREQUENCY_MAX,
};
uint8_t GetKeyboardProperty(int index);
void SetKeyboardProperty(int index, uint8_t data);
void FlushKeyboardProperties();
void RevertKeyboardProperties();
// max_size is not optional, contrary to popular belief :)
void KbGetString(char* buffer, int max_size);
#endif//_KEYBOARD_H