Keyboard.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /**
  2. * Copyright (c) 2006-2014 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #ifndef LOVE_KEYBOARD_KEYBOARD_H
  21. #define LOVE_KEYBOARD_KEYBOARD_H
  22. // LOVE
  23. #include "common/Module.h"
  24. #include "common/StringMap.h"
  25. namespace love
  26. {
  27. namespace keyboard
  28. {
  29. class Keyboard : public Module
  30. {
  31. public:
  32. enum Key
  33. {
  34. KEY_UNKNOWN,
  35. KEY_RETURN,
  36. KEY_ESCAPE,
  37. KEY_BACKSPACE,
  38. KEY_TAB,
  39. KEY_SPACE,
  40. KEY_EXCLAIM,
  41. KEY_QUOTEDBL,
  42. KEY_HASH,
  43. KEY_PERCENT,
  44. KEY_DOLLAR,
  45. KEY_AMPERSAND,
  46. KEY_QUOTE,
  47. KEY_LEFTPAREN,
  48. KEY_RIGHTPAREN,
  49. KEY_ASTERISK,
  50. KEY_PLUS,
  51. KEY_COMMA,
  52. KEY_MINUS,
  53. KEY_PERIOD,
  54. KEY_SLASH,
  55. KEY_0,
  56. KEY_1,
  57. KEY_2,
  58. KEY_3,
  59. KEY_4,
  60. KEY_5,
  61. KEY_6,
  62. KEY_7,
  63. KEY_8,
  64. KEY_9,
  65. KEY_COLON,
  66. KEY_SEMICOLON,
  67. KEY_LESS,
  68. KEY_EQUALS,
  69. KEY_GREATER,
  70. KEY_QUESTION,
  71. KEY_AT,
  72. KEY_LEFTBRACKET,
  73. KEY_BACKSLASH,
  74. KEY_RIGHTBRACKET,
  75. KEY_CARET,
  76. KEY_UNDERSCORE,
  77. KEY_BACKQUOTE,
  78. KEY_A,
  79. KEY_B,
  80. KEY_C,
  81. KEY_D,
  82. KEY_E,
  83. KEY_F,
  84. KEY_G,
  85. KEY_H,
  86. KEY_I,
  87. KEY_J,
  88. KEY_K,
  89. KEY_L,
  90. KEY_M,
  91. KEY_N,
  92. KEY_O,
  93. KEY_P,
  94. KEY_Q,
  95. KEY_R,
  96. KEY_S,
  97. KEY_T,
  98. KEY_U,
  99. KEY_V,
  100. KEY_W,
  101. KEY_X,
  102. KEY_Y,
  103. KEY_Z,
  104. KEY_CAPSLOCK,
  105. KEY_F1,
  106. KEY_F2,
  107. KEY_F3,
  108. KEY_F4,
  109. KEY_F5,
  110. KEY_F6,
  111. KEY_F7,
  112. KEY_F8,
  113. KEY_F9,
  114. KEY_F10,
  115. KEY_F11,
  116. KEY_F12,
  117. KEY_PRINTSCREEN,
  118. KEY_SCROLLLOCK,
  119. KEY_PAUSE,
  120. KEY_INSERT,
  121. KEY_HOME,
  122. KEY_PAGEUP,
  123. KEY_DELETE,
  124. KEY_END,
  125. KEY_PAGEDOWN,
  126. KEY_RIGHT,
  127. KEY_LEFT,
  128. KEY_DOWN,
  129. KEY_UP,
  130. KEY_NUMLOCKCLEAR,
  131. KEY_KP_DIVIDE,
  132. KEY_KP_MULTIPLY,
  133. KEY_KP_MINUS,
  134. KEY_KP_PLUS,
  135. KEY_KP_ENTER,
  136. KEY_KP_1,
  137. KEY_KP_2,
  138. KEY_KP_3,
  139. KEY_KP_4,
  140. KEY_KP_5,
  141. KEY_KP_6,
  142. KEY_KP_7,
  143. KEY_KP_8,
  144. KEY_KP_9,
  145. KEY_KP_0,
  146. KEY_KP_PERIOD,
  147. KEY_KP_COMMA,
  148. KEY_KP_EQUALS,
  149. KEY_APPLICATION,
  150. KEY_POWER,
  151. KEY_F13,
  152. KEY_F14,
  153. KEY_F15,
  154. KEY_F16,
  155. KEY_F17,
  156. KEY_F18,
  157. KEY_F19,
  158. KEY_F20,
  159. KEY_F21,
  160. KEY_F22,
  161. KEY_F23,
  162. KEY_F24,
  163. KEY_EXECUTE,
  164. KEY_HELP,
  165. KEY_MENU,
  166. KEY_SELECT,
  167. KEY_STOP,
  168. KEY_AGAIN,
  169. KEY_UNDO,
  170. KEY_CUT,
  171. KEY_COPY,
  172. KEY_PASTE,
  173. KEY_FIND,
  174. KEY_MUTE,
  175. KEY_VOLUMEUP,
  176. KEY_VOLUMEDOWN,
  177. KEY_ALTERASE,
  178. KEY_SYSREQ,
  179. KEY_CANCEL,
  180. KEY_CLEAR,
  181. KEY_PRIOR,
  182. KEY_RETURN2,
  183. KEY_SEPARATOR,
  184. KEY_OUT,
  185. KEY_OPER,
  186. KEY_CLEARAGAIN,
  187. KEY_THOUSANDSSEPARATOR,
  188. KEY_DECIMALSEPARATOR,
  189. KEY_CURRENCYUNIT,
  190. KEY_CURRENCYSUBUNIT,
  191. KEY_LCTRL,
  192. KEY_LSHIFT,
  193. KEY_LALT,
  194. KEY_LGUI,
  195. KEY_RCTRL,
  196. KEY_RSHIFT,
  197. KEY_RALT,
  198. KEY_RGUI,
  199. KEY_MODE,
  200. KEY_AUDIONEXT,
  201. KEY_AUDIOPREV,
  202. KEY_AUDIOSTOP,
  203. KEY_AUDIOPLAY,
  204. KEY_AUDIOMUTE,
  205. KEY_MEDIASELECT,
  206. KEY_WWW,
  207. KEY_MAIL,
  208. KEY_CALCULATOR,
  209. KEY_COMPUTER,
  210. KEY_APP_SEARCH,
  211. KEY_APP_HOME,
  212. KEY_APP_BACK,
  213. KEY_APP_FORWARD,
  214. KEY_APP_STOP,
  215. KEY_APP_REFRESH,
  216. KEY_APP_BOOKMARKS,
  217. KEY_BRIGHTNESSDOWN,
  218. KEY_BRIGHTNESSUP,
  219. KEY_DISPLAYSWITCH,
  220. KEY_KBDILLUMTOGGLE,
  221. KEY_KBDILLUMDOWN,
  222. KEY_KBDILLUMUP,
  223. KEY_EJECT,
  224. KEY_SLEEP,
  225. KEY_MAX_ENUM
  226. };
  227. virtual ~Keyboard() {}
  228. // Implements Module.
  229. virtual ModuleType getModuleType() const { return M_KEYBOARD; }
  230. /**
  231. * Sets whether repeat keypress events should be sent if a key is held down.
  232. * Does not affect text input events.
  233. * @param enable Whether to send repeat key press events.
  234. **/
  235. virtual void setKeyRepeat(bool enable) = 0;
  236. /**
  237. * Gets whether repeat keypress events will be sent if a key is held down.
  238. **/
  239. virtual bool hasKeyRepeat() const = 0;
  240. /**
  241. * Checks whether certain keys are down or not.
  242. * @param keylist An array of key identifiers, terminated by KEY_MAX_ENUM.
  243. * @return boolean
  244. **/
  245. virtual bool isDown(Key *keylist) const = 0;
  246. /**
  247. * Sets whether text input events should be sent
  248. * @param enable Whether to send text input events.
  249. **/
  250. virtual void setTextInput(bool enable) = 0;
  251. /**
  252. * Gets whether text input events are enabled.
  253. **/
  254. virtual bool hasTextInput() const = 0;
  255. static bool getConstant(const char *in, Key &out);
  256. static bool getConstant(Key in, const char *&out);
  257. private:
  258. static StringMap<Key, KEY_MAX_ENUM>::Entry keyEntries[];
  259. static StringMap<Key, KEY_MAX_ENUM> keys;
  260. }; // Keyboard
  261. } // keyboard
  262. } // love
  263. #endif // LOVE_KEYBOARD_KEYBOARD_H