1e16f4c87SPeter Maydell #include "qemu/osdep.h" 20041e9a0SMichael S. Tsirkin #include "keymaps.h" 302aa76c2SGerd Hoffmann #include "ui/input.h" 402aa76c2SGerd Hoffmann 5606eb0c6SGerd Hoffmann #include "standard-headers/linux/input.h" 6606eb0c6SGerd Hoffmann 7*139c1837SPaolo Bonzini #include "ui/input-keymap-atset1-to-qcode.c.inc" 8*139c1837SPaolo Bonzini #include "ui/input-keymap-linux-to-qcode.c.inc" 9*139c1837SPaolo Bonzini #include "ui/input-keymap-qcode-to-atset1.c.inc" 10*139c1837SPaolo Bonzini #include "ui/input-keymap-qcode-to-atset2.c.inc" 11*139c1837SPaolo Bonzini #include "ui/input-keymap-qcode-to-atset3.c.inc" 12*139c1837SPaolo Bonzini #include "ui/input-keymap-qcode-to-linux.c.inc" 13*139c1837SPaolo Bonzini #include "ui/input-keymap-qcode-to-qnum.c.inc" 14*139c1837SPaolo Bonzini #include "ui/input-keymap-qcode-to-sun.c.inc" 15*139c1837SPaolo Bonzini #include "ui/input-keymap-qnum-to-qcode.c.inc" 16*139c1837SPaolo Bonzini #include "ui/input-keymap-usb-to-qcode.c.inc" 17*139c1837SPaolo Bonzini #include "ui/input-keymap-win32-to-qcode.c.inc" 18*139c1837SPaolo Bonzini #include "ui/input-keymap-x11-to-qcode.c.inc" 19*139c1837SPaolo Bonzini #include "ui/input-keymap-xorgevdev-to-qcode.c.inc" 20*139c1837SPaolo Bonzini #include "ui/input-keymap-xorgkbd-to-qcode.c.inc" 21*139c1837SPaolo Bonzini #include "ui/input-keymap-xorgxquartz-to-qcode.c.inc" 22*139c1837SPaolo Bonzini #include "ui/input-keymap-xorgxwin-to-qcode.c.inc" 23*139c1837SPaolo Bonzini #include "ui/input-keymap-osx-to-qcode.c.inc" 2402aa76c2SGerd Hoffmann qemu_input_linux_to_qcode(unsigned int lnx)25606eb0c6SGerd Hoffmannint qemu_input_linux_to_qcode(unsigned int lnx) 26606eb0c6SGerd Hoffmann { 27bcd5ac9bSDaniel P. Berrange if (lnx >= qemu_input_map_linux_to_qcode_len) { 28bcd5ac9bSDaniel P. Berrange return 0; 29bcd5ac9bSDaniel P. Berrange } 30bcd5ac9bSDaniel P. Berrange return qemu_input_map_linux_to_qcode[lnx]; 31606eb0c6SGerd Hoffmann } 32606eb0c6SGerd Hoffmann qemu_input_key_value_to_number(const KeyValue * value)3302aa76c2SGerd Hoffmannint qemu_input_key_value_to_number(const KeyValue *value) 3402aa76c2SGerd Hoffmann { 35568c73a4SEric Blake if (value->type == KEY_VALUE_KIND_QCODE) { 36bcd5ac9bSDaniel P. Berrange if (value->u.qcode.data >= qemu_input_map_qcode_to_qnum_len) { 37bcd5ac9bSDaniel P. Berrange return 0; 38bcd5ac9bSDaniel P. Berrange } 39bcd5ac9bSDaniel P. Berrange return qemu_input_map_qcode_to_qnum[value->u.qcode.data]; 4002aa76c2SGerd Hoffmann } else { 41568c73a4SEric Blake assert(value->type == KEY_VALUE_KIND_NUMBER); 4232bafa8fSEric Blake return value->u.number.data; 4302aa76c2SGerd Hoffmann } 4402aa76c2SGerd Hoffmann } 4502aa76c2SGerd Hoffmann qemu_input_key_number_to_qcode(unsigned int nr)46bcd5ac9bSDaniel P. Berrangeint qemu_input_key_number_to_qcode(unsigned int nr) 4702aa76c2SGerd Hoffmann { 48bcd5ac9bSDaniel P. Berrange if (nr >= qemu_input_map_qnum_to_qcode_len) { 49bcd5ac9bSDaniel P. Berrange return 0; 5002aa76c2SGerd Hoffmann } 51bcd5ac9bSDaniel P. Berrange return qemu_input_map_qnum_to_qcode[nr]; 5211c7fa7fSGerd Hoffmann } 5311c7fa7fSGerd Hoffmann qemu_input_key_value_to_qcode(const KeyValue * value)5411c7fa7fSGerd Hoffmannint qemu_input_key_value_to_qcode(const KeyValue *value) 5511c7fa7fSGerd Hoffmann { 56568c73a4SEric Blake if (value->type == KEY_VALUE_KIND_QCODE) { 5732bafa8fSEric Blake return value->u.qcode.data; 5802aa76c2SGerd Hoffmann } else { 59568c73a4SEric Blake assert(value->type == KEY_VALUE_KIND_NUMBER); 6032bafa8fSEric Blake return qemu_input_key_number_to_qcode(value->u.number.data); 6102aa76c2SGerd Hoffmann } 6202aa76c2SGerd Hoffmann } 6302aa76c2SGerd Hoffmann qemu_input_key_value_to_scancode(const KeyValue * value,bool down,int * codes)6402aa76c2SGerd Hoffmannint qemu_input_key_value_to_scancode(const KeyValue *value, bool down, 6502aa76c2SGerd Hoffmann int *codes) 6602aa76c2SGerd Hoffmann { 6702aa76c2SGerd Hoffmann int keycode = qemu_input_key_value_to_number(value); 6802aa76c2SGerd Hoffmann int count = 0; 6902aa76c2SGerd Hoffmann 70568c73a4SEric Blake if (value->type == KEY_VALUE_KIND_QCODE && 7132bafa8fSEric Blake value->u.qcode.data == Q_KEY_CODE_PAUSE) { 7202aa76c2SGerd Hoffmann /* specific case */ 7302aa76c2SGerd Hoffmann int v = down ? 0 : 0x80; 7402aa76c2SGerd Hoffmann codes[count++] = 0xe1; 7502aa76c2SGerd Hoffmann codes[count++] = 0x1d | v; 7602aa76c2SGerd Hoffmann codes[count++] = 0x45 | v; 7702aa76c2SGerd Hoffmann return count; 7802aa76c2SGerd Hoffmann } 7902aa76c2SGerd Hoffmann if (keycode & SCANCODE_GREY) { 8002aa76c2SGerd Hoffmann codes[count++] = SCANCODE_EMUL0; 8102aa76c2SGerd Hoffmann keycode &= ~SCANCODE_GREY; 8202aa76c2SGerd Hoffmann } 8302aa76c2SGerd Hoffmann if (!down) { 8402aa76c2SGerd Hoffmann keycode |= SCANCODE_UP; 8502aa76c2SGerd Hoffmann } 8602aa76c2SGerd Hoffmann codes[count++] = keycode; 8702aa76c2SGerd Hoffmann 8802aa76c2SGerd Hoffmann return count; 8902aa76c2SGerd Hoffmann } 90