keyboard.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*************************************************************************/
  2. /* keyboard.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef KEYBOARD_H
  31. #define KEYBOARD_H
  32. #include "core/ustring.h"
  33. /**
  34. @author Juan Linietsky <reduzio@gmail.com>
  35. */
  36. /*
  37. Special Key:
  38. The strategy here is similar to the one used by toolkits,
  39. which consists in leaving the 24 bits unicode range for printable
  40. characters, and use the upper 8 bits for special keys and
  41. modifiers. This way everything (char/keycode) can fit nicely in one 32 bits unsigned integer.
  42. */
  43. enum {
  44. SPKEY = (1 << 24)
  45. };
  46. enum KeyList {
  47. /* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */
  48. KEY_ESCAPE = SPKEY | 0x01,
  49. KEY_TAB = SPKEY | 0x02,
  50. KEY_BACKTAB = SPKEY | 0x03,
  51. KEY_BACKSPACE = SPKEY | 0x04,
  52. KEY_ENTER = SPKEY | 0x05,
  53. KEY_KP_ENTER = SPKEY | 0x06,
  54. KEY_INSERT = SPKEY | 0x07,
  55. KEY_DELETE = SPKEY | 0x08,
  56. KEY_PAUSE = SPKEY | 0x09,
  57. KEY_PRINT = SPKEY | 0x0A,
  58. KEY_SYSREQ = SPKEY | 0x0B,
  59. KEY_CLEAR = SPKEY | 0x0C,
  60. KEY_HOME = SPKEY | 0x0D,
  61. KEY_END = SPKEY | 0x0E,
  62. KEY_LEFT = SPKEY | 0x0F,
  63. KEY_UP = SPKEY | 0x10,
  64. KEY_RIGHT = SPKEY | 0x11,
  65. KEY_DOWN = SPKEY | 0x12,
  66. KEY_PAGEUP = SPKEY | 0x13,
  67. KEY_PAGEDOWN = SPKEY | 0x14,
  68. KEY_SHIFT = SPKEY | 0x15,
  69. KEY_CONTROL = SPKEY | 0x16,
  70. KEY_META = SPKEY | 0x17,
  71. KEY_ALT = SPKEY | 0x18,
  72. KEY_CAPSLOCK = SPKEY | 0x19,
  73. KEY_NUMLOCK = SPKEY | 0x1A,
  74. KEY_SCROLLLOCK = SPKEY | 0x1B,
  75. KEY_F1 = SPKEY | 0x1C,
  76. KEY_F2 = SPKEY | 0x1D,
  77. KEY_F3 = SPKEY | 0x1E,
  78. KEY_F4 = SPKEY | 0x1F,
  79. KEY_F5 = SPKEY | 0x20,
  80. KEY_F6 = SPKEY | 0x21,
  81. KEY_F7 = SPKEY | 0x22,
  82. KEY_F8 = SPKEY | 0x23,
  83. KEY_F9 = SPKEY | 0x24,
  84. KEY_F10 = SPKEY | 0x25,
  85. KEY_F11 = SPKEY | 0x26,
  86. KEY_F12 = SPKEY | 0x27,
  87. KEY_F13 = SPKEY | 0x28,
  88. KEY_F14 = SPKEY | 0x29,
  89. KEY_F15 = SPKEY | 0x2A,
  90. KEY_F16 = SPKEY | 0x2B,
  91. KEY_KP_MULTIPLY = SPKEY | 0x81,
  92. KEY_KP_DIVIDE = SPKEY | 0x82,
  93. KEY_KP_SUBTRACT = SPKEY | 0x83,
  94. KEY_KP_PERIOD = SPKEY | 0x84,
  95. KEY_KP_ADD = SPKEY | 0x85,
  96. KEY_KP_0 = SPKEY | 0x86,
  97. KEY_KP_1 = SPKEY | 0x87,
  98. KEY_KP_2 = SPKEY | 0x88,
  99. KEY_KP_3 = SPKEY | 0x89,
  100. KEY_KP_4 = SPKEY | 0x8A,
  101. KEY_KP_5 = SPKEY | 0x8B,
  102. KEY_KP_6 = SPKEY | 0x8C,
  103. KEY_KP_7 = SPKEY | 0x8D,
  104. KEY_KP_8 = SPKEY | 0x8E,
  105. KEY_KP_9 = SPKEY | 0x8F,
  106. KEY_SUPER_L = SPKEY | 0x2C,
  107. KEY_SUPER_R = SPKEY | 0x2D,
  108. KEY_MENU = SPKEY | 0x2E,
  109. KEY_HYPER_L = SPKEY | 0x2F,
  110. KEY_HYPER_R = SPKEY | 0x30,
  111. KEY_HELP = SPKEY | 0x31,
  112. KEY_DIRECTION_L = SPKEY | 0x32,
  113. KEY_DIRECTION_R = SPKEY | 0x33,
  114. KEY_BACK = SPKEY | 0x40,
  115. KEY_FORWARD = SPKEY | 0x41,
  116. KEY_STOP = SPKEY | 0x42,
  117. KEY_REFRESH = SPKEY | 0x43,
  118. KEY_VOLUMEDOWN = SPKEY | 0x44,
  119. KEY_VOLUMEMUTE = SPKEY | 0x45,
  120. KEY_VOLUMEUP = SPKEY | 0x46,
  121. KEY_BASSBOOST = SPKEY | 0x47,
  122. KEY_BASSUP = SPKEY | 0x48,
  123. KEY_BASSDOWN = SPKEY | 0x49,
  124. KEY_TREBLEUP = SPKEY | 0x4A,
  125. KEY_TREBLEDOWN = SPKEY | 0x4B,
  126. KEY_MEDIAPLAY = SPKEY | 0x4C,
  127. KEY_MEDIASTOP = SPKEY | 0x4D,
  128. KEY_MEDIAPREVIOUS = SPKEY | 0x4E,
  129. KEY_MEDIANEXT = SPKEY | 0x4F,
  130. KEY_MEDIARECORD = SPKEY | 0x50,
  131. KEY_HOMEPAGE = SPKEY | 0x51,
  132. KEY_FAVORITES = SPKEY | 0x52,
  133. KEY_SEARCH = SPKEY | 0x53,
  134. KEY_STANDBY = SPKEY | 0x54,
  135. KEY_OPENURL = SPKEY | 0x55,
  136. KEY_LAUNCHMAIL = SPKEY | 0x56,
  137. KEY_LAUNCHMEDIA = SPKEY | 0x57,
  138. KEY_LAUNCH0 = SPKEY | 0x58,
  139. KEY_LAUNCH1 = SPKEY | 0x59,
  140. KEY_LAUNCH2 = SPKEY | 0x5A,
  141. KEY_LAUNCH3 = SPKEY | 0x5B,
  142. KEY_LAUNCH4 = SPKEY | 0x5C,
  143. KEY_LAUNCH5 = SPKEY | 0x5D,
  144. KEY_LAUNCH6 = SPKEY | 0x5E,
  145. KEY_LAUNCH7 = SPKEY | 0x5F,
  146. KEY_LAUNCH8 = SPKEY | 0x60,
  147. KEY_LAUNCH9 = SPKEY | 0x61,
  148. KEY_LAUNCHA = SPKEY | 0x62,
  149. KEY_LAUNCHB = SPKEY | 0x63,
  150. KEY_LAUNCHC = SPKEY | 0x64,
  151. KEY_LAUNCHD = SPKEY | 0x65,
  152. KEY_LAUNCHE = SPKEY | 0x66,
  153. KEY_LAUNCHF = SPKEY | 0x67,
  154. KEY_UNKNOWN = SPKEY | 0xFFFFFF,
  155. /* PRINTABLE LATIN 1 CODES */
  156. KEY_SPACE = 0x0020,
  157. KEY_EXCLAM = 0x0021,
  158. KEY_QUOTEDBL = 0x0022,
  159. KEY_NUMBERSIGN = 0x0023,
  160. KEY_DOLLAR = 0x0024,
  161. KEY_PERCENT = 0x0025,
  162. KEY_AMPERSAND = 0x0026,
  163. KEY_APOSTROPHE = 0x0027,
  164. KEY_PARENLEFT = 0x0028,
  165. KEY_PARENRIGHT = 0x0029,
  166. KEY_ASTERISK = 0x002A,
  167. KEY_PLUS = 0x002B,
  168. KEY_COMMA = 0x002C,
  169. KEY_MINUS = 0x002D,
  170. KEY_PERIOD = 0x002E,
  171. KEY_SLASH = 0x002F,
  172. KEY_0 = 0x0030,
  173. KEY_1 = 0x0031,
  174. KEY_2 = 0x0032,
  175. KEY_3 = 0x0033,
  176. KEY_4 = 0x0034,
  177. KEY_5 = 0x0035,
  178. KEY_6 = 0x0036,
  179. KEY_7 = 0x0037,
  180. KEY_8 = 0x0038,
  181. KEY_9 = 0x0039,
  182. KEY_COLON = 0x003A,
  183. KEY_SEMICOLON = 0x003B,
  184. KEY_LESS = 0x003C,
  185. KEY_EQUAL = 0x003D,
  186. KEY_GREATER = 0x003E,
  187. KEY_QUESTION = 0x003F,
  188. KEY_AT = 0x0040,
  189. KEY_A = 0x0041,
  190. KEY_B = 0x0042,
  191. KEY_C = 0x0043,
  192. KEY_D = 0x0044,
  193. KEY_E = 0x0045,
  194. KEY_F = 0x0046,
  195. KEY_G = 0x0047,
  196. KEY_H = 0x0048,
  197. KEY_I = 0x0049,
  198. KEY_J = 0x004A,
  199. KEY_K = 0x004B,
  200. KEY_L = 0x004C,
  201. KEY_M = 0x004D,
  202. KEY_N = 0x004E,
  203. KEY_O = 0x004F,
  204. KEY_P = 0x0050,
  205. KEY_Q = 0x0051,
  206. KEY_R = 0x0052,
  207. KEY_S = 0x0053,
  208. KEY_T = 0x0054,
  209. KEY_U = 0x0055,
  210. KEY_V = 0x0056,
  211. KEY_W = 0x0057,
  212. KEY_X = 0x0058,
  213. KEY_Y = 0x0059,
  214. KEY_Z = 0x005A,
  215. KEY_BRACKETLEFT = 0x005B,
  216. KEY_BACKSLASH = 0x005C,
  217. KEY_BRACKETRIGHT = 0x005D,
  218. KEY_ASCIICIRCUM = 0x005E,
  219. KEY_UNDERSCORE = 0x005F,
  220. KEY_QUOTELEFT = 0x0060,
  221. KEY_BRACELEFT = 0x007B,
  222. KEY_BAR = 0x007C,
  223. KEY_BRACERIGHT = 0x007D,
  224. KEY_ASCIITILDE = 0x007E,
  225. KEY_NOBREAKSPACE = 0x00A0,
  226. KEY_EXCLAMDOWN = 0x00A1,
  227. KEY_CENT = 0x00A2,
  228. KEY_STERLING = 0x00A3,
  229. KEY_CURRENCY = 0x00A4,
  230. KEY_YEN = 0x00A5,
  231. KEY_BROKENBAR = 0x00A6,
  232. KEY_SECTION = 0x00A7,
  233. KEY_DIAERESIS = 0x00A8,
  234. KEY_COPYRIGHT = 0x00A9,
  235. KEY_ORDFEMININE = 0x00AA,
  236. KEY_GUILLEMOTLEFT = 0x00AB,
  237. KEY_NOTSIGN = 0x00AC,
  238. KEY_HYPHEN = 0x00AD,
  239. KEY_REGISTERED = 0x00AE,
  240. KEY_MACRON = 0x00AF,
  241. KEY_DEGREE = 0x00B0,
  242. KEY_PLUSMINUS = 0x00B1,
  243. KEY_TWOSUPERIOR = 0x00B2,
  244. KEY_THREESUPERIOR = 0x00B3,
  245. KEY_ACUTE = 0x00B4,
  246. KEY_MU = 0x00B5,
  247. KEY_PARAGRAPH = 0x00B6,
  248. KEY_PERIODCENTERED = 0x00B7,
  249. KEY_CEDILLA = 0x00B8,
  250. KEY_ONESUPERIOR = 0x00B9,
  251. KEY_MASCULINE = 0x00BA,
  252. KEY_GUILLEMOTRIGHT = 0x00BB,
  253. KEY_ONEQUARTER = 0x00BC,
  254. KEY_ONEHALF = 0x00BD,
  255. KEY_THREEQUARTERS = 0x00BE,
  256. KEY_QUESTIONDOWN = 0x00BF,
  257. KEY_AGRAVE = 0x00C0,
  258. KEY_AACUTE = 0x00C1,
  259. KEY_ACIRCUMFLEX = 0x00C2,
  260. KEY_ATILDE = 0x00C3,
  261. KEY_ADIAERESIS = 0x00C4,
  262. KEY_ARING = 0x00C5,
  263. KEY_AE = 0x00C6,
  264. KEY_CCEDILLA = 0x00C7,
  265. KEY_EGRAVE = 0x00C8,
  266. KEY_EACUTE = 0x00C9,
  267. KEY_ECIRCUMFLEX = 0x00CA,
  268. KEY_EDIAERESIS = 0x00CB,
  269. KEY_IGRAVE = 0x00CC,
  270. KEY_IACUTE = 0x00CD,
  271. KEY_ICIRCUMFLEX = 0x00CE,
  272. KEY_IDIAERESIS = 0x00CF,
  273. KEY_ETH = 0x00D0,
  274. KEY_NTILDE = 0x00D1,
  275. KEY_OGRAVE = 0x00D2,
  276. KEY_OACUTE = 0x00D3,
  277. KEY_OCIRCUMFLEX = 0x00D4,
  278. KEY_OTILDE = 0x00D5,
  279. KEY_ODIAERESIS = 0x00D6,
  280. KEY_MULTIPLY = 0x00D7,
  281. KEY_OOBLIQUE = 0x00D8,
  282. KEY_UGRAVE = 0x00D9,
  283. KEY_UACUTE = 0x00DA,
  284. KEY_UCIRCUMFLEX = 0x00DB,
  285. KEY_UDIAERESIS = 0x00DC,
  286. KEY_YACUTE = 0x00DD,
  287. KEY_THORN = 0x00DE,
  288. KEY_SSHARP = 0x00DF,
  289. KEY_DIVISION = 0x00F7,
  290. KEY_YDIAERESIS = 0x00FF,
  291. };
  292. enum KeyModifierMask {
  293. KEY_CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers.
  294. KEY_MODIFIER_MASK = (0xFF << 24), ///< Apply this mask to isolate modifiers.
  295. KEY_MASK_SHIFT = (1 << 25),
  296. KEY_MASK_ALT = (1 << 26),
  297. KEY_MASK_META = (1 << 27),
  298. KEY_MASK_CTRL = (1 << 28),
  299. #ifdef APPLE_STYLE_KEYS
  300. KEY_MASK_CMD = KEY_MASK_META,
  301. #else
  302. KEY_MASK_CMD = KEY_MASK_CTRL,
  303. #endif
  304. KEY_MASK_KPAD = (1 << 29),
  305. KEY_MASK_GROUP_SWITCH = (1 << 30)
  306. // bit 31 can't be used because variant uses regular 32 bits int as datatype
  307. };
  308. String keycode_get_string(uint32_t p_code);
  309. bool keycode_has_unicode(uint32_t p_keycode);
  310. int find_keycode(const String &p_code);
  311. const char *find_keycode_name(int p_keycode);
  312. int keycode_get_count();
  313. int keycode_get_value_by_index(int p_index);
  314. const char *keycode_get_name_by_index(int p_index);
  315. #endif