20#include <aquila/keyboard.h>
42static const char keys[128] = {
43 [0x02] =
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'-',
'=',
44 [0x10] =
'q',
'w',
'e',
'r',
't',
'y',
'u',
'i',
'o',
'p',
'[',
']',
45 [0x1E] =
'a',
's',
'd',
'f',
'g',
'h',
'j',
'k',
'l',
';',
'\'',
'`',
46 [0x2B] =
'\\',
'z',
'x',
'c',
'v',
'b',
'n',
'm',
',',
'.',
'/',
52 [0x02] =
'!',
'@',
'#',
'$',
'%',
'^',
'&',
'*',
'(',
')',
'_',
'+',
53 [0x10] =
'Q',
'W',
'E',
'R',
'T',
'Y',
'U',
'I',
'O',
'P',
'{',
'}',
54 [0x1E] =
'A',
'S',
'D',
'F',
'G',
'H',
'J',
'K',
'L',
':',
'"',
'~',
55 [0x2B] =
'|',
'Z',
'X',
'C',
'V',
'B',
'N',
'M',
'<',
'>',
'?',
62 "\033[[A",
"\033[[B",
"\033[[C",
"\033[[D",
"\033[[E",
"\033[17~",
63 "\033[18~",
"\033[19~",
"\033[20~",
"\033[21~",
"\033[23~",
"\033[24~",
70 "\033[1~",
"A",
"\033[5~",
NULL,
"D",
"\033[G",
"C",
NULL,
71 "\033[4~",
"B",
"\033[6~",
"\033[2~",
"\033[3~",
132 int shifted_table =
table & (1 << KG_SHIFT);
134 if (
table & ~((1 << KG_SHIFT) | (1 << KG_ALTGR)))
138 case SC_ESC:
return K(KT_LATIN, 0x1b);
139 case SC_BS:
return K(KT_LATIN, 0x7f);
140 case SC_TAB:
return K(KT_LATIN,
'\t');
144 case SC_ALT:
return K_ALT;
146 case SC_NUM:
return K_NUM;
147 case 0x46:
return K_HOLD;
149 case SC_F11:
return K(KT_FN, 10);
150 case SC_F12:
return K(KT_FN, 11);
153 case 96:
return K_PENTER;
154 case 97:
return K_CTRL;
155 case 98:
return K_PSLASH;
156 case 100:
return K_ALT;
157 case 102:
return K_FIND;
158 case 103:
return K_UP;
159 case 104:
return K_PGUP;
160 case 105:
return K_LEFT;
161 case 106:
return K_RIGHT;
162 case 107:
return K_SELECT;
163 case 108:
return K_DOWN;
164 case 109:
return K_PGDN;
165 case 110:
return K_INSERT;
166 case 111:
return K_REMOVE;
171 return K(KT_FN, keycode -
SC_F1);
175 K_P0 + 7, K_P0 + 8, K_P0 + 9, K_PMINUS, K_P0 + 4, K_P0 + 5, K_P0 + 6,
176 K_PPLUS, K_P0 + 1, K_P0 + 2, K_P0 + 3, K_P0, K_PDOT,
181 if (keycode < 0 || keycode >= 128)
184 char c = shifted_table ?
shifted[keycode] :
keys[keycode];
189 if ((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z'))
190 return K(KT_LETTER, c);
192 return K(KT_LATIN, (
unsigned char) c);
214 char buf[] = {c,
'\0'};
251 if (c >=
'a' && c <=
'z')
254 if (c >=
'A' && c <=
'Z')
258 case '@':
case '2':
case ' ':
case '`':
260 case '[':
case '3':
case '{':
262 case '\\':
case '4':
case '|':
264 case ']':
case '5':
case '}':
266 case '^':
case '6':
case '~':
268 case '_':
case '-':
case '/':
case '7':
case '?':
323 if (scancode == 0xE0) {
329 if (scancode == 0xE1) {
332 if (
mode == K_MEDIUMRAW) {
339 int code = scancode & 0x7f, release = scancode & 0x80, ext =
extended;
342 if (
mode != K_XLATE &&
mode != K_UNICODE) {
365 if (!release && !ext)
397 case 0x47:
send_key(
"\033[1~");
return;
399 case 0x49:
send_key(
"\033[5~");
return;
402 case 0x4F:
send_key(
"\033[4~");
return;
404 case 0x51:
send_key(
"\033[6~");
return;
405 case 0x52:
send_key(
"\033[2~");
return;
406 case 0x53:
send_key(
"\033[3~");
return;
435 if (
caps && ((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z')))
static const uint8_t e0_keycodes[128]
static int modifier(int code, int release, int ext)
Keeps track of Shift, Ctrl and Alt, in every mode, since they may be held while the mode changes.
static const char keypad_digits[]
static void editing_key(const char *s)
Sends a key of the editing block: its sequence, or a cursor key if it is one letter.
static int control(char c)
Returns the control character that Ctrl with a key sends, as the Linux console does (Ctrl+A is 1,...
static void send_byte(int c)
Sends one byte to the foreground terminal, as typed input.
static const char * fkeys[12]
static const char shifted[128]
static void cursor_key(char dir)
Sends a cursor key: ESC [ x, or ESC O x in the terminal's application cursor key mode (DECCKM).
static void send_key(const char *s)
Sends what a key sends, with ESC before it if Alt is held.
int vt_keymap(int table, int keycode)
Says what a key is, for KDGKBENT: programs that read key codes (K_MEDIUMRAW) use it to know what each...
static void send(const char *s)
Sends a string to the foreground terminal, as typed input.
static void send_char(char c)
Sends one character, with ESC before it if Alt is held.
static const char * keypad_keys[13]
static const char keys[128]
void vt_scancode(int scancode)
Takes a scancode from the keyboard, and sends what the key means to the foreground terminal,...
void vt_keyboard_reset(void)
Forgets a prefix or a sequence that a change of mode cut in the middle.
static uint64_t * table(paddr_t paddr)
Returns a page table, through the direct map.
void kernel_ctrlaltdel(void)
Handles Ctrl+Alt+Del from the keyboard, possibly in an interrupt: it restarts the machine,...
unsigned short int uint16_t
A virtual terminal: its screen, its emulator's state, and its tty.
void vt_input(const char *buf, size_t size)
Gives what keys sent to the foreground terminal, as input.
struct vt * vt_foreground(void)
Returns the terminal in the foreground.
void vt_switch(int id)
Switches to another terminal, for Alt+Fn and VT_ACTIVATE.
void vt_keypress(void)
Undoes, at a key press, the modes that a process which is gone had set on the foreground terminal: ot...