caps lock for keyboard driver

This commit is contained in:
MainSilent 2020-11-11 20:39:21 +03:30 committed by GitHub
parent 7aff64740e
commit a0677c643c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,22 +8,38 @@
#include <stdint.h>
#define BACKSPACE 0x0E
#define CapsLock 0x3A
#define ENTER 0x1C
static char key_buffer[256];
static int CapsLockStatus = 0;
#define SC_MAX 57
#define SC_MAX 58
/* UpperCase Chars */
const char *sc_name[] = { "ERROR", "Esc", "1", "2", "3", "4", "5", "6",
"7", "8", "9", "0", "-", "=", "Backspace", "Tab", "Q", "W", "E",
"R", "T", "Y", "U", "I", "O", "P", "[", "]", "Enter", "Lctrl",
"A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "`",
"LShift", "\\", "Z", "X", "C", "V", "B", "N", "M", ",", ".",
"/", "RShift", "Keypad *", "LAlt", "Spacebar"};
"/", "RShift", "Keypad *", "LAlt", "Spacebar", "CapsLock"};
const char sc_ascii[] = { '?', '?', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', '?', '?', 'Q', 'W', 'E', 'R', 'T', 'Y',
'U', 'I', 'O', 'P', '[', ']', '?', '?', 'A', 'S', 'D', 'F', 'G',
'H', 'J', 'K', 'L', ';', '\'', '`', '?', '\\', 'Z', 'X', 'C', 'V',
'B', 'N', 'M', ',', '.', '/', '?', '?', '?', ' '};
'B', 'N', 'M', ',', '.', '/', '?', '?', '?', ' ', '?'};
/* LowerCase Chars */
const char *Lsc_name[] = { "ERROR", "Esc", "1", "2", "3", "4", "5", "6",
"7", "8", "9", "0", "-", "=", "Backspace", "Tab", "q", "w", "e",
"r", "t", "y", "u", "i", "o", "p", "[", "]", "Enter", "Lctrl",
"a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "`",
"LShift", "\\", "z", "x", "c", "v", "b", "n", "m", ",", ".",
"/", "RShift", "Keypad *", "LAlt", "Spacebar", "CapsLock"};
const char Lsc_ascii[] = { '?', '?', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', '?', '?', 'q', 'w', 'e', 'r', 't', 'y',
'u', 'i', 'o', 'p', '[', ']', '?', '?', 'a', 's', 'd', 'f', 'g',
'h', 'j', 'k', 'l', ';', '\'', '`', '?', '\\', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '/', '?', '?', '?', ' ', '?'};
static void keyboard_callback(registers_t *regs) {
/* The PIC leaves us the scancode in port 0x60 */
@ -37,8 +53,16 @@ static void keyboard_callback(registers_t *regs) {
kprint("\n");
user_input(key_buffer); /* kernel-controlled function */
key_buffer[0] = '\0';
} else if (scancode == CapsLock) {
/* Toggle caps lock */
if (CapsLockStatus)
CapsLockStatus = 0;
else
CapsLockStatus = 1;
} else {
char letter = sc_ascii[(int)scancode];
if (CapsLockStatus == 0)
letter = Lsc_ascii[(int)scancode];
/* Remember that kprint only accepts char[] */
char str[2] = {letter, '\0'};
append(key_buffer, letter);