3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 unsigned char kbd_us
[128] =
29 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
30 '9', '0', '-', '=', '\b', /* Backspace */
32 'q', 'w', 'e', 'r', /* 19 */
33 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
35 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
36 '\'', '`', 0, /* Left shift */
37 '\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
38 'm', ',', '.', '/', 0, /* Right shift */
43 0, /* 59 - F1 key ... > */
44 0, 0, 0, 0, 0, 0, 0, 0,
64 0, /* All other keys are undefined */
67 static char kbd_buffer
[KBD_BUFFER_LEN
];
68 static unsigned char kbd_buffer_pos
;
70 unsigned char kbd_getkey ()
72 if (kbd_buffer_pos
> 0)
75 unsigned char c
= kbd_buffer
[kbd_buffer_pos
];
77 kbd_buffer
[kbd_buffer_pos
] = '\0';
84 int scancode
= getkey ();
86 /*if (scancode == keycode)
89 if (scancode == keycode+128)
95 if (scancode
>= 128 && kbd_buffer_pos
< KBD_BUFFER_LEN
) {
96 kbd_buffer
[kbd_buffer_pos
] = kbd_us
[scancode
- 128];
103 /* set socket "1" to non-blocking */
104 /*int oldFlag = fcntl (1, F_GETFL, 0);
105 if (fcntl (1, F_SETFL, oldFlag | O_NONBLOCK) == -1) {
106 printf ("Cant set socket to nonblocking mode\n");
111 memset (kbd_buffer
, 0, KBD_BUFFER_LEN
);