void keyboard_state_machine(unsigned char scancode) { /* this will process the incoming scancodes, translate them to * a character stream, and write them to the masterfd of the * current pty. */ bool release = false; if(!scancode) return; /* first, take care of protocol codes */ switch(scancode) { case 0xee: case 0xf1: case 0xfa: return; case 0xfc: case 0xfd: case 0xfe: case 0xff: syslog(LOG_ERR, "internal keyboard error: %x\n", scancode); return; } /* TODO: actually handle escaped codes */ if(scancode == 0xe0) return; if(scancode & 0x80) { release = true; scancode -= 0x80; } unsigned int key = 0; switch(scancode) { case 0x1d: ctrl = !release; break; case 0x2a: shift = !release; break; case 0x38: alt = !release; break; case 0x3a: capslock = !capslock; break; default: if(shift) key = us_map_shift[scancode]; else if(ctrl) key = us_map_ctrl[scancode]; else key = us_map[scancode]; if(shift ^ capslock) key = toupper(key); if(key == 0) syslog(LOG_ERR, "unknown scancode: %x (%d %d %d)\n", scancode, shift, ctrl, alt); else if(!release && key < 256) { sendkey((unsigned char)key); } else if(!release) { special_key(key); } } }
static LRESULT CALLBACK window_cb(HWND window, UINT message, WPARAM wparam, LPARAM lparam) { dpy_flushkeys(); switch (message) { case WM_CLOSE: return 0; case WM_EXITSIZEMOVE: if (!isfullscreen) { window_geometry_valid = true; GetWindowRect(window, &window_geometry); write_window_geometry(); } break; case WM_SIZE: if (!window_created) { create_cb(); window_created = true; } resize_buffer(); break; case WM_SIZING: sizing_cb(wparam, (RECT*) lparam); goto delegate; case WM_ERASEBKGND: return 1; case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(window, &ps); paint_cb(window, &ps, ps.hdc); EndPaint(window, &ps); break; } case WM_PRINTCLIENT: { PAINTSTRUCT ps; ps.hdc = (HDC) wparam; GetClientRect(window, &ps.rcPaint); paint_cb(window, &ps, ps.hdc); break; } case WM_CHAR: { unicode_key(wparam, lparam); break; } case WM_KEYDOWN: case WM_SYSKEYDOWN: { if (special_key(wparam, lparam)) return 1; break; } case WM_SYSCOMMAND: { switch (wparam) { case MENUITEM_SETFONT: setfont_cb(); break; case MENUITEM_FULLSCREEN: fullscreen_cb(); break; } goto delegate; } case WM_TIMER: { if (wparam == TIMEOUT_TIMER_ID) { dpy_queuekey(-VK_TIMEOUT); break; } goto delegate; } delegate: default: return DefWindowProcW(window, message, wparam, lparam); } return 0; }