Support numpad

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-08-22 02:17:14 +02:00
parent 96157c5378
commit 49c822bc42
3 changed files with 71 additions and 19 deletions

View file

@ -106,12 +106,60 @@ map_key_core (int code, int status, int *alt_gr_consumed)
return grub_current_layout->keyboard_map[code];
}
static int
map_high_key (int code, int status)
{
int ret = 0;
if (status & (GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT))
ret |= GRUB_TERM_SHIFT;
if (code == 0xb5)
return '/';
if (code == 0xb7)
return '*';
if (code == 0x9c)
return '\n';
if (code < 0xc7 || code > 0xd3 || code == 0xca || code == 0xce
|| code == 0xcc)
return ret;
/* GRUB keyboard codes are conveniently similar to AT codes. */
return ret | GRUB_TERM_EXTENDED | (code & ~0x80);
}
static int
map_num_key (int code, int state)
{
const int map_arrows[]
= { GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_UP, GRUB_TERM_KEY_PPAGE,
'-', GRUB_TERM_KEY_LEFT, GRUB_TERM_KEY_CENTER, GRUB_TERM_KEY_RIGHT, '+',
GRUB_TERM_KEY_END, GRUB_TERM_KEY_DOWN, GRUB_TERM_KEY_NPAGE,
GRUB_TERM_KEY_INSERT, GRUB_TERM_KEY_DC };
const int map_nums[]
= { '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'};
if (((state & GRUB_TERM_STATUS_NUM)
&& !(state & (GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT)))
|| ((state & GRUB_TERM_STATUS_NUM)
&& !(state & (GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT))))
return map_nums [code - 0x47];
else
return map_arrows [code - 0x47];
}
unsigned
grub_term_map_key (int code, int status)
{
int alt_gr_consumed;
int alt_gr_consumed = 0;
int key;
if (code >= 0x47 && code <= 0x53)
key = map_num_key (code, status);
else if (code & 0x80)
key = map_high_key (code, status);
else
key = map_key_core (code, status, &alt_gr_consumed);
if (key == 0 || key == GRUB_TERM_SHIFT)

View file

@ -110,7 +110,6 @@ grub_keyboard_isr (grub_uint8_t key)
at_keyboard_status &= ~GRUB_TERM_STATUS_LALT;
break;
}
extended_pending = (key == 0xe0);
}
/* If there is a raw key pending, return it; otherwise return -1. */
@ -118,13 +117,18 @@ static int
grub_keyboard_getkey (void)
{
grub_uint8_t key;
grub_uint8_t ret;
if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
return -1;
key = grub_inb (KEYBOARD_REG_DATA);
/* FIXME */ grub_keyboard_isr (key);
ret = KEYBOARD_SCANCODE (key);
if (extended_pending)
ret |= 0x80;
extended_pending = (key == 0xe0);
if (! KEYBOARD_ISMAKE (key))
return -1;
return (KEYBOARD_SCANCODE (key));
return ret;
}

View file

@ -69,20 +69,20 @@ static grub_uint8_t usb_to_at_map[128] =
/* 0x42 */ 0x43 /* F9 */, 0x44 /* F10 */,
/* 0x44 */ 0x57 /* F11 */, 0x58 /* F12 */,
/* 0x46 */ 0x00, 0x00,
/* 0x48 */ 0x00, 0x52 /* Insert */,
/* 0x4a */ 0x47 /* HOME */, 0x51 /* PPAGE */,
/* 0x4c */ 0x53 /* DC */, 0x4f /* END */,
/* 0x4e */ 0x49 /* NPAGE */, 0x4d /* RIGHT */,
/* 0x50 */ 0x4b /* LEFT */, 0x50 /* DOWN */,
/* 0x52 */ 0x48 /* UP */, 0x00,
/* 0x54 */ 0x00, 0x00,
/* 0x56 */ 0x00, 0x00,
/* 0x58 */ 0x00, 0x00,
/* 0x5a */ 0x00, 0x00,
/* 0x5c */ 0x00, 0x00,
/* 0x5e */ 0x00, 0x00,
/* 0x60 */ 0x00, 0x00,
/* 0x62 */ 0x00, 0x00,
/* 0x48 */ 0x00, 0xd2 /* Insert */,
/* 0x4a */ 0xc7 /* HOME */, 0xd1 /* PPAGE */,
/* 0x4c */ 0xd3 /* DC */, 0xcf /* END */,
/* 0x4e */ 0xc9 /* NPAGE */, 0xcd /* RIGHT */,
/* 0x50 */ 0xcb /* LEFT */, 0xd0 /* DOWN */,
/* 0x52 */ 0xc8 /* UP */, 0x00,
/* 0x54 */ 0xb5 /* Num / */, 0xb7 /* Num * */,
/* 0x56 */ 0x4a /* Num - */, 0x4e /* Num + */,
/* 0x58 */ 0x9c /* Num \n */, 0x4f /* Num 1 */,
/* 0x5a */ 0x50 /* Num 2 */, 0x51 /* Num 3 */,
/* 0x5c */ 0x4b /* Num 4 */, 0x4c /* Num 5 */,
/* 0x5e */ 0x4d /* Num 6 */, 0x47 /* Num 7 */,
/* 0x60 */ 0x48 /* Num 8 */, 0x49 /* Num 9 */,
/* 0x62 */ 0x52 /* Num 0 */, 0x53 /* Num . */,
/* 0x64 */ 0x56 /* 102nd key. */, 0x00,
/* 0x66 */ 0x00, 0x00,
/* 0x68 */ 0x00, 0x00,
@ -428,7 +428,7 @@ grub_usb_keyboard_checkkey (struct grub_term_input *term)
return -1;
}
if (data[2] > ARRAY_SIZE (usb_to_at_map) || usb_to_at_map[data[2]] == 0)
if (data[2] >= ARRAY_SIZE (usb_to_at_map) || usb_to_at_map[data[2]] == 0)
grub_printf ("Unknown key 0x%02x detected\n", data[2]);
else
{