42_KFS/src/terminal/get.c

31 lines
806 B
C

#include <stdbool.h>
#include "keyboard.h"
#include "sys/io.h"
#include "terminal.h"
struct key_event terminal_getkey(void)
{
static bool caps_mode = false;
struct key_event ev = {0};
u8 scan_code;
scan_code = inb(KEYBOARD_PORT);
if (scan_code == 0x3A || scan_code == 0x58) {
caps_mode = !caps_mode;
outb(0xED, (caps_mode << 2)); // turn on/off capslock led
} else if (scan_code == KEY_RIGHT_SHIFT || scan_code == KEY_LEFT_SHIFT)
caps_mode = true;
else if (scan_code == KEY_RIGHT_SHIFT + 128 ||
scan_code == KEY_LEFT_SHIFT + 128)
caps_mode = false;
if (scan_code < 128) {
if (keymap[scan_code])
ev.c = keymap[scan_code][caps_mode];
if (scan_code >= KEY_F1 && scan_code <= KEY_F10)
terminal_set_screen(scan_code - KEY_F1);
ev.scan_code = scan_code;
}
return ev;
}