kbd.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #pragma once
  2. #define KBD_NORMAL 0
  3. #define KBD_ESC_A 1
  4. #define KBD_ESC_B 2
  5. #define KBD_FUNC 3
  6. #define KBD_ESC_O 4
  7. #define KBD_ESC_EXT 5
  8. #define KEY_NONE 0
  9. #define KEY_BACKSPACE 8
  10. #define KEY_CTRL_A 1
  11. #define KEY_CTRL_B 2
  12. #define KEY_CTRL_C 3
  13. #define KEY_CTRL_D 4
  14. #define KEY_CTRL_E 5
  15. #define KEY_CTRL_F 6
  16. #define KEY_CTRL_G 7
  17. #define KEY_CTRL_H 8
  18. #define KEY_CTRL_I 9
  19. #define KEY_CTRL_J 10
  20. #define KEY_CTRL_K 11
  21. #define KEY_CTRL_L 12
  22. #define KEY_CTRL_M 13
  23. #define KEY_CTRL_N 14
  24. #define KEY_CTRL_O 15
  25. #define KEY_CTRL_P 16
  26. #define KEY_CTRL_Q 17
  27. #define KEY_CTRL_R 18
  28. #define KEY_CTRL_S 19
  29. #define KEY_CTRL_T 20
  30. #define KEY_CTRL_U 21
  31. #define KEY_CTRL_V 22
  32. #define KEY_CTRL_W 23
  33. #define KEY_CTRL_X 24
  34. #define KEY_CTRL_Y 25
  35. #define KEY_CTRL_Z 26
  36. #define KEY_ESCAPE 27
  37. #define KEY_NORMAL_MAX 256
  38. #define KEY_ARROW_UP 257
  39. #define KEY_ARROW_DOWN 258
  40. #define KEY_ARROW_RIGHT 259
  41. #define KEY_ARROW_LEFT 260
  42. #define KEY_BAD_STATE -1
  43. #define KEY_CTRL_ARROW_UP 261
  44. #define KEY_CTRL_ARROW_DOWN 262
  45. #define KEY_CTRL_ARROW_RIGHT 263
  46. #define KEY_CTRL_ARROW_LEFT 264
  47. #define KEY_SHIFT_ARROW_UP 265
  48. #define KEY_SHIFT_ARROW_DOWN 266
  49. #define KEY_SHIFT_ARROW_RIGHT 267
  50. #define KEY_SHIFT_ARROW_LEFT 268
  51. #define KEY_LEFT_CTRL 1001
  52. #define KEY_LEFT_SHIFT 1002
  53. #define KEY_LEFT_ALT 1003
  54. #define KEY_LEFT_SUPER 1004
  55. #define KEY_RIGHT_CTRL 1011
  56. #define KEY_RIGHT_SHIFT 1012
  57. #define KEY_RIGHT_ALT 1013
  58. #define KEY_RIGHT_SUPER 1014
  59. #define KEY_F1 2001
  60. #define KEY_F2 2002
  61. #define KEY_F3 2003
  62. #define KEY_F4 2004
  63. #define KEY_F5 2005
  64. #define KEY_F6 2006
  65. #define KEY_F7 2007
  66. #define KEY_F8 2008
  67. #define KEY_F9 2009
  68. #define KEY_F10 2010
  69. #define KEY_F11 2011
  70. #define KEY_F12 2012
  71. #define KEY_PAGE_DOWN 2013
  72. #define KEY_PAGE_UP 2014
  73. #define KEY_HOME 2015
  74. #define KEY_END 2016
  75. #define KEY_DEL 2017
  76. #define KEY_INSERT 2018
  77. #define KEY_SCANCODE_F1 0x3b
  78. #define KEY_SCANCODE_F2 0x3c
  79. #define KEY_SCANCODE_F3 0x3d
  80. #define KEY_SCANCODE_F4 0x3e
  81. #define KEY_SCANCODE_F5 0x3f
  82. #define KEY_SCANCODE_F6 0x40
  83. #define KEY_SCANCODE_F7 0x41
  84. #define KEY_SCANCODE_F8 0x42
  85. #define KEY_SCANCODE_F9 0x43
  86. #define KEY_SCANCODE_F10 0x44
  87. #define KEY_SCANCODE_F11 0x57
  88. #define KEY_SCANCODE_F12 0x58
  89. #define KEY_MOD_LEFT_CTRL 0x01
  90. #define KEY_MOD_LEFT_SHIFT 0x02
  91. #define KEY_MOD_LEFT_ALT 0x04
  92. #define KEY_MOD_LEFT_SUPER 0x08
  93. #define KEY_MOD_RIGHT_CTRL 0x10
  94. #define KEY_MOD_RIGHT_SHIFT 0x20
  95. #define KEY_MOD_RIGHT_ALT 0x40
  96. #define KEY_MOD_RIGHT_SUPER 0x80
  97. #define KEY_ACTION_DOWN 0x01
  98. #define KEY_ACTION_UP 0x02
  99. typedef unsigned int kbd_key_t;
  100. typedef unsigned int kbd_mod_t;
  101. typedef unsigned char kbd_act_t;
  102. typedef struct {
  103. kbd_key_t keycode;
  104. kbd_mod_t modifiers;
  105. kbd_act_t action;
  106. unsigned char key; /* Key as a raw code, ready for reading, or \0 if it's not a good down strike / was a modifier change / etc/. */
  107. } key_event_t;
  108. typedef struct {
  109. int kbd_state;
  110. int kbd_s_state;
  111. int k_ctrl;
  112. int k_shift;
  113. int k_alt;
  114. int k_super;
  115. int kl_ctrl;
  116. int kl_shift;
  117. int kl_alt;
  118. int kl_super;
  119. int kr_ctrl;
  120. int kr_shift;
  121. int kr_alt;
  122. int kr_super;
  123. int kbd_esc_buf;
  124. } key_event_state_t;
  125. extern kbd_key_t kbd_key(key_event_state_t * state, unsigned char c);
  126. extern int kbd_scancode(key_event_state_t * state, unsigned char c, key_event_t * event);