/* * p1_keyboard.c — печать сырых событий getkey()/kbd_mod_state(). */ #include #include #include #include "p1_platform.h" static uint8_t compact_modifiers(uint16_t state) { uint8_t result = 0; if (state & (KBD_MOD_LSHIFT | KBD_MOD_RSHIFT)) result |= 0x01; if (state & (KBD_MOD_CTRL | KBD_MOD_LCTRL | KBD_MOD_RCTRL)) result |= 0x02; if (state & (KBD_MOD_ALT | KBD_MOD_LALT | KBD_MOD_RALT)) result |= 0x04; return result; } int p1_test_keyboard(void) { uint8_t n = 0; p1_heading("Keyboard: raw event capture"); cputs("Press navigation keys, F1..F10 and Ctrl combinations.\r\n"); cputs("Esc finishes after its event is printed. Maximum: 24 events.\r\n\r\n"); cputs(" n key ascii scan live_mod compact\r\n"); while (n < 24) { uint16_t key = getkey(); uint16_t live = kbd_mod_state(); uint8_t ascii = (uint8_t)key; uint8_t scan = (uint8_t)(key >> 8); uint8_t compact = compact_modifiers(live); char printable = (ascii >= 0x20 && ascii < 0x7F) ? (char)ascii : '.'; printf("%2u %c %02X %02X %04X %02X\n", (unsigned)n, printable, (unsigned)ascii, (unsigned)scan, (unsigned)live, (unsigned)compact); n++; if (ascii == 0x1B) break; } cputs("\r\nCompare the captured values with commander-keymap.md.\r\n"); return 0; }