From 8f1e13e7492a232e031a287c25ea82f3789f7ad8 Mon Sep 17 00:00:00 2001 From: Xnoe Date: Fri, 3 Sep 2021 12:02:37 +0100 Subject: [PATCH] Added caps lock support to readline --- keyboard.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/keyboard.c b/keyboard.c index 870f68c..fa66bf1 100644 --- a/keyboard.c +++ b/keyboard.c @@ -1,6 +1,5 @@ #include "keyboard.h" - char key_to_char[128] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0, @@ -60,31 +59,37 @@ void readline(int max, char* buffer) { int index = 0; - uint8_t scancode = current_scancode; - while (scancode != 0x1c || index == 0) { - while (scancode == current_scancode); + uint8_t scancode = 0; + while (scancode != 0x1c && index < max) { scancode = current_scancode; char decoded = 0; if ((scancode&0x7f) == 0x2a) shift_on = !(scancode&0x80); + + if (scancode == 0x3a) + caps_on ^= 1; if (scancode == 0x0e && index > 0) { set_curpos_raw(get_curpos()-1); non_moving_put(' '); - index--; + buffer[--index] = 0; } - if (!shift_on) - decoded = key_to_char[scancode&0x7f]; - else + if (shift_on) decoded = key_to_char_shift[scancode&0x7f]; + else if (caps_on) + decoded = key_to_char_caps[scancode&0x7f]; + else + decoded = key_to_char[scancode&0x7f]; if (decoded && scancode < 0x80) { buffer[index++] = decoded; printf("%c", decoded); } + + while (scancode == current_scancode); } printf("\n"); } \ No newline at end of file