diff --git a/src/include/keyboard.h b/src/include/keyboard.h index 814c361..e015c99 100644 --- a/src/include/keyboard.h +++ b/src/include/keyboard.h @@ -2,6 +2,42 @@ #include +#define K_ESC '\x1b' +#define K_LSHIFT '\x0e' +#define K_RSHIFT '\x0f' +#define K_LCTRL '\x11' +#define K_RCTRL '\x12' +#define K_LALT '\x13' +#define K_NSTAR '\x01' +#define K_NPLUS '\x02' +#define K_NMINUS '\x03' +#define K_NDOT '\x04' +#define K_CAPS '\x05' +#define K_SCROLL '\x06' +#define K_NUM '\x07' +#define K_N0 '\xb0' +#define K_N1 '\xb1' +#define K_N2 '\xb2' +#define K_N3 '\xb3' +#define K_N4 '\xb4' +#define K_N5 '\xb5' +#define K_N6 '\xb6' +#define K_N7 '\xb7' +#define K_N8 '\xb8' +#define K_N9 '\xb9' +#define K_F1 '\xba' +#define K_F2 '\xbb' +#define K_F3 '\xbc' +#define K_F4 '\xbd' +#define K_F5 '\xbe' +#define K_F6 '\xbf' +#define K_F7 '\xc0' +#define K_F8 '\xc1' +#define K_F9 '\xc2' +#define K_F10 '\xc3' +#define K_F11 '\xc4' +#define K_F12 '\xc5' + namespace nov { namespace keyboard @@ -69,6 +105,7 @@ void keyboardInterruptCallback(); void assignPS2KeyboardController(PS2KeyboardController* controller); KeyState decodeScancode(uint8_t scancode, ScancodeSet scs); +bool isAlphaNumeric(char c); #define PS2_DATA_PORT 0x60 diff --git a/src/include/scancodes.h b/src/include/scancodes.h index fa85a01..f2dbfc1 100644 --- a/src/include/scancodes.h +++ b/src/include/scancodes.h @@ -1,42 +1,7 @@ #pragma once #include - -#define K_ESC '\x1b' -#define K_LSHIFT '\x0e' -#define K_RSHIFT '\x0f' -#define K_LCTRL '\x11' -#define K_RCTRL '\x12' -#define K_LALT '\x13' -#define K_NSTAR '\x01' -#define K_NPLUS '\x02' -#define K_NMINUS '\x03' -#define K_NDOT '\x04' -#define K_CAPS '\x05' -#define K_SCROLL '\x06' -#define K_NUM '\x07' -#define K_N0 '\xb0' -#define K_N1 '\xb1' -#define K_N2 '\xb2' -#define K_N3 '\xb3' -#define K_N4 '\xb4' -#define K_N5 '\xb5' -#define K_N6 '\xb6' -#define K_N7 '\xb7' -#define K_N8 '\xb8' -#define K_N9 '\xb9' -#define K_F1 '\xba' -#define K_F2 '\xbb' -#define K_F3 '\xbc' -#define K_F4 '\xbd' -#define K_F5 '\xbe' -#define K_F6 '\xbf' -#define K_F7 '\xc0' -#define K_F8 '\xc1' -#define K_F9 '\xc2' -#define K_F10 '\xc3' -#define K_F11 '\xc4' -#define K_F12 '\xc5' +#include static const char scan_code_set_1_char[256] { diff --git a/src/include/string.h b/src/include/string.h index 12661c3..82254a8 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -36,6 +36,7 @@ class String void resize(uint32_t new_capacity); void clear(); + void pop(uint32_t num = 1); const char* constStr() const; diff --git a/src/kernel_main.cpp b/src/kernel_main.cpp index 0abc205..dd55639 100644 --- a/src/kernel_main.cpp +++ b/src/kernel_main.cpp @@ -170,8 +170,10 @@ extern "C" void main(boot::OSHintTable* os_hint_table) keyboard::KeyState state = keyboard::decodeScancode(kb_byte, keyboard::ScancodeSet::SET_1); if (state.is_down) { - text_panel->text.append(state.key); - com_1 << "keyboard byte: " << (char)state.key << endl; + if (keyboard::isAlphaNumeric(state.key) || state.key == '\n') + text_panel->text.append(state.key); + if (state.key == '\b') + text_panel->text.pop(); } } } diff --git a/src/keyboard.cpp b/src/keyboard.cpp index d15f6b0..30fd4b1 100644 --- a/src/keyboard.cpp +++ b/src/keyboard.cpp @@ -39,6 +39,13 @@ KeyState decodeScancode(uint8_t scancode, ScancodeSet scs) return state; } +bool isAlphaNumeric(char c) +{ + if (c < ' ') return false; + if (c > '~') return false; + return true; +} + void PS2KeyboardController::queueInByte(uint8_t byte) { if (in_queue_end == in_queue_start - 1) diff --git a/src/string.cpp b/src/string.cpp index 18ec0d6..8534a1d 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -142,6 +142,12 @@ void String::clear() backing.clear(); } +void String::pop(uint32_t num) +{ + if (!num) return; + for (uint32_t i = 0; i < num; i++) backing.pop(); +} + uint32_t String::getLength() const { return backing.getLength();