keyboard.h 9.3 KB

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