sdl2-input.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * QEMU SDL display driver
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
  25. #include "qemu/osdep.h"
  26. #include "qemu-common.h"
  27. #include "ui/console.h"
  28. #include "ui/input.h"
  29. #include "ui/sdl2.h"
  30. #include "sysemu/sysemu.h"
  31. #include "sdl2-keymap.h"
  32. static uint8_t modifiers_state[SDL_NUM_SCANCODES];
  33. void sdl2_reset_keys(struct sdl2_console *scon)
  34. {
  35. QemuConsole *con = scon ? scon->dcl.con : NULL;
  36. int i;
  37. for (i = 0; i < SDL_NUM_SCANCODES; i++) {
  38. if (modifiers_state[i]) {
  39. int qcode = sdl2_scancode_to_qcode[i];
  40. qemu_input_event_send_key_qcode(con, qcode, false);
  41. modifiers_state[i] = 0;
  42. }
  43. }
  44. }
  45. void sdl2_process_key(struct sdl2_console *scon,
  46. SDL_KeyboardEvent *ev)
  47. {
  48. int qcode = sdl2_scancode_to_qcode[ev->keysym.scancode];
  49. QemuConsole *con = scon ? scon->dcl.con : NULL;
  50. if (!qemu_console_is_graphic(con)) {
  51. if (ev->type == SDL_KEYDOWN) {
  52. switch (ev->keysym.scancode) {
  53. case SDL_SCANCODE_RETURN:
  54. kbd_put_keysym_console(con, '\n');
  55. break;
  56. case SDL_SCANCODE_BACKSPACE:
  57. kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
  58. break;
  59. default:
  60. kbd_put_qcode_console(con, qcode);
  61. break;
  62. }
  63. }
  64. return;
  65. }
  66. switch (ev->keysym.scancode) {
  67. #if 0
  68. case SDL_SCANCODE_NUMLOCKCLEAR:
  69. case SDL_SCANCODE_CAPSLOCK:
  70. /* SDL does not send the key up event, so we generate it */
  71. qemu_input_event_send_key_qcode(con, qcode, true);
  72. qemu_input_event_send_key_qcode(con, qcode, false);
  73. return;
  74. #endif
  75. case SDL_SCANCODE_LCTRL:
  76. case SDL_SCANCODE_LSHIFT:
  77. case SDL_SCANCODE_LALT:
  78. case SDL_SCANCODE_LGUI:
  79. case SDL_SCANCODE_RCTRL:
  80. case SDL_SCANCODE_RSHIFT:
  81. case SDL_SCANCODE_RALT:
  82. case SDL_SCANCODE_RGUI:
  83. if (ev->type == SDL_KEYUP) {
  84. modifiers_state[ev->keysym.scancode] = 0;
  85. } else {
  86. modifiers_state[ev->keysym.scancode] = 1;
  87. }
  88. /* fall though */
  89. default:
  90. qemu_input_event_send_key_qcode(con, qcode,
  91. ev->type == SDL_KEYDOWN);
  92. }
  93. }