InputEvents.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "Object.h"
  24. #include <SDL_joystick.h>
  25. #include <SDL_gamecontroller.h>
  26. #include <SDL_keycode.h>
  27. namespace Urho3D
  28. {
  29. /// Mouse button pressed.
  30. EVENT(E_MOUSEBUTTONDOWN, MouseButtonDown)
  31. {
  32. PARAM(P_BUTTON, Button); // int
  33. PARAM(P_BUTTONS, Buttons); // int
  34. PARAM(P_QUALIFIERS, Qualifiers); // int
  35. }
  36. /// Mouse button released.
  37. EVENT(E_MOUSEBUTTONUP, MouseButtonUp)
  38. {
  39. PARAM(P_BUTTON, Button); // int
  40. PARAM(P_BUTTONS, Buttons); // int
  41. PARAM(P_QUALIFIERS, Qualifiers); // int
  42. }
  43. /// Mouse moved.
  44. EVENT(E_MOUSEMOVE, MouseMove)
  45. {
  46. PARAM(P_X, X); // int (only when mouse visible)
  47. PARAM(P_Y, Y); // int (only when mouse visible)
  48. PARAM(P_DX, DX); // int
  49. PARAM(P_DY, DY); // int
  50. PARAM(P_BUTTONS, Buttons); // int
  51. PARAM(P_QUALIFIERS, Qualifiers); // int
  52. }
  53. /// Mouse wheel moved.
  54. EVENT(E_MOUSEWHEEL, MouseWheel)
  55. {
  56. PARAM(P_WHEEL, Wheel); // int
  57. PARAM(P_BUTTONS, Buttons); // int
  58. PARAM(P_QUALIFIERS, Qualifiers); // int
  59. }
  60. /// Key pressed.
  61. EVENT(E_KEYDOWN, KeyDown)
  62. {
  63. PARAM(P_KEY, Key); // int
  64. PARAM(P_BUTTONS, Buttons); // int
  65. PARAM(P_QUALIFIERS, Qualifiers); // int
  66. PARAM(P_REPEAT, Repeat); // bool
  67. PARAM(P_RAW, Raw); // uint
  68. }
  69. /// Key released.
  70. EVENT(E_KEYUP, KeyUp)
  71. {
  72. PARAM(P_KEY, Key); // int
  73. PARAM(P_BUTTONS, Buttons); // int
  74. PARAM(P_QUALIFIERS, Qualifiers); // int
  75. PARAM(P_RAW, Raw); // uint
  76. }
  77. /// Character typed on the keyboard.
  78. EVENT(E_CHAR, Char)
  79. {
  80. PARAM(P_CHAR, Char); // int
  81. PARAM(P_BUTTONS, Buttons); // int
  82. PARAM(P_QUALIFIERS, Qualifiers); // int
  83. }
  84. /// Finger pressed on the screen.
  85. EVENT(E_TOUCHBEGIN, TouchBegin)
  86. {
  87. PARAM(P_TOUCHID, TouchID); // int
  88. PARAM(P_X, X); // int
  89. PARAM(P_Y, Y); // int
  90. PARAM(P_PRESSURE, Pressure); // float
  91. }
  92. /// Finger released from the screen.
  93. EVENT(E_TOUCHEND, TouchEnd)
  94. {
  95. PARAM(P_TOUCHID, TouchID); // int
  96. PARAM(P_X, X); // int
  97. PARAM(P_Y, Y); // int
  98. }
  99. /// Finger moved on the screen.
  100. EVENT(E_TOUCHMOVE, TouchMove)
  101. {
  102. PARAM(P_TOUCHID, TouchID); // int
  103. PARAM(P_X, X); // int
  104. PARAM(P_Y, Y); // int
  105. PARAM(P_DX, DX); // int
  106. PARAM(P_DY, DY); // int
  107. PARAM(P_PRESSURE, Pressure); // float
  108. }
  109. /// Joystick button pressed.
  110. EVENT(E_JOYSTICKBUTTONDOWN, JoystickButtonDown)
  111. {
  112. PARAM(P_JOYSTICK, Joystick); // int
  113. PARAM(P_BUTTON, Button); // int
  114. }
  115. /// Joystick button released.
  116. EVENT(E_JOYSTICKBUTTONUP, JoystickButtonUp)
  117. {
  118. PARAM(P_JOYSTICK, Joystick); // int
  119. PARAM(P_BUTTON, Button); // int
  120. }
  121. /// Joystick axis moved.
  122. EVENT(E_JOYSTICKAXISMOVE, JoystickAxisMove)
  123. {
  124. PARAM(P_JOYSTICK, Joystick); // int
  125. PARAM(P_AXIS, Button); // int
  126. PARAM(P_POSITION, Position); // float
  127. }
  128. /// Joystick POV hat moved.
  129. EVENT(E_JOYSTICKHATMOVE, JoystickHatMove)
  130. {
  131. PARAM(P_JOYSTICK, Joystick); // int
  132. PARAM(P_HAT, Button); // int
  133. PARAM(P_POSITION, Position); // int
  134. }
  135. /// Controller button pressed.
  136. EVENT(E_CONTROLLERBUTTONDOWN, ControllerButtonDown)
  137. {
  138. PARAM(P_JOYSTICK, Joystick); // int
  139. PARAM(P_BUTTON, Button); // int
  140. }
  141. /// Controller button released.
  142. EVENT(E_CONTROLLERBUTTONUP, ControllerButtonUp)
  143. {
  144. PARAM(P_JOYSTICK, Joystick); // int
  145. PARAM(P_BUTTON, Button); // int
  146. }
  147. /// Controller axis moved.
  148. EVENT(E_CONTROLLERAXISMOVE, ControllerAxisMove)
  149. {
  150. PARAM(P_JOYSTICK, Joystick); // int
  151. PARAM(P_AXIS, Button); // int
  152. PARAM(P_POSITION, Position); // float
  153. }
  154. /// A file was drag-dropped into the application window.
  155. EVENT(E_DROPFILE, DropFile)
  156. {
  157. PARAM(P_FILENAME, FileName); // String
  158. }
  159. /// Application input focus or minimization changed.
  160. EVENT(E_INPUTFOCUS, InputFocus)
  161. {
  162. PARAM(P_FOCUS, Focus); // bool
  163. PARAM(P_MINIMIZED, Minimized); // bool
  164. }
  165. /// OS mouse cursor visibility changed.
  166. EVENT(E_MOUSEVISIBLECHANGED, MouseVisibleChanged)
  167. {
  168. PARAM(P_VISIBLE, Visible); // bool
  169. }
  170. /// Application exit requested.
  171. EVENT(E_EXITREQUESTED, ExitRequested)
  172. {
  173. }
  174. static const int MOUSEB_LEFT = 1;
  175. static const int MOUSEB_MIDDLE = 2;
  176. static const int MOUSEB_RIGHT = 4;
  177. static const int QUAL_SHIFT = 1;
  178. static const int QUAL_CTRL = 2;
  179. static const int QUAL_ALT = 4;
  180. static const int QUAL_ANY = 8;
  181. static const int KEY_BACKSPACE = SDLK_BACKSPACE;
  182. static const int KEY_TAB = SDLK_TAB;
  183. static const int KEY_RETURN = SDLK_RETURN;
  184. static const int KEY_RETURN2 = SDLK_RETURN2;
  185. static const int KEY_KP_ENTER = SDLK_KP_ENTER;
  186. static const int KEY_SHIFT = SDLK_LSHIFT;
  187. static const int KEY_CTRL = SDLK_LCTRL;
  188. static const int KEY_ALT = SDLK_LALT;
  189. static const int KEY_PAUSE = SDLK_PAUSE;
  190. static const int KEY_CAPSLOCK = SDLK_CAPSLOCK;
  191. static const int KEY_ESC = SDLK_ESCAPE;
  192. static const int KEY_SPACE = SDLK_SPACE;
  193. static const int KEY_PAGEUP = SDLK_PAGEUP;
  194. static const int KEY_PAGEDOWN = SDLK_PAGEDOWN;
  195. static const int KEY_END = SDLK_END;
  196. static const int KEY_HOME = SDLK_HOME;
  197. static const int KEY_LEFT = SDLK_LEFT;
  198. static const int KEY_UP = SDLK_UP;
  199. static const int KEY_RIGHT = SDLK_RIGHT;
  200. static const int KEY_DOWN = SDLK_DOWN;
  201. static const int KEY_SELECT = SDLK_SELECT;
  202. static const int KEY_PRINTSCREEN = SDLK_PRINTSCREEN;
  203. static const int KEY_INSERT = SDLK_INSERT;
  204. static const int KEY_DELETE = SDLK_DELETE;
  205. static const int KEY_LWIN = SDLK_LGUI;
  206. static const int KEY_RWIN = SDLK_RGUI;
  207. static const int KEY_APPS = SDLK_APPLICATION;
  208. static const int KEY_NUMPAD0 = SDLK_KP_0;
  209. static const int KEY_NUMPAD1 = SDLK_KP_1;
  210. static const int KEY_NUMPAD2 = SDLK_KP_2;
  211. static const int KEY_NUMPAD3 = SDLK_KP_3;
  212. static const int KEY_NUMPAD4 = SDLK_KP_4;
  213. static const int KEY_NUMPAD5 = SDLK_KP_5;
  214. static const int KEY_NUMPAD6 = SDLK_KP_6;
  215. static const int KEY_NUMPAD7 = SDLK_KP_7;
  216. static const int KEY_NUMPAD8 = SDLK_KP_8;
  217. static const int KEY_NUMPAD9 = SDLK_KP_9;
  218. static const int KEY_MULTIPLY = SDLK_KP_MULTIPLY;
  219. static const int KEY_ADD = SDLK_KP_PLUS;
  220. static const int KEY_SUBTRACT = SDLK_KP_MINUS;
  221. static const int KEY_DECIMAL = SDLK_KP_PERIOD;
  222. static const int KEY_DIVIDE = SDLK_KP_DIVIDE;
  223. static const int KEY_F1 = SDLK_F1;
  224. static const int KEY_F2 = SDLK_F2;
  225. static const int KEY_F3 = SDLK_F3;
  226. static const int KEY_F4 = SDLK_F4;
  227. static const int KEY_F5 = SDLK_F5;
  228. static const int KEY_F6 = SDLK_F6;
  229. static const int KEY_F7 = SDLK_F7;
  230. static const int KEY_F8 = SDLK_F8;
  231. static const int KEY_F9 = SDLK_F9;
  232. static const int KEY_F10 = SDLK_F10;
  233. static const int KEY_F11 = SDLK_F11;
  234. static const int KEY_F12 = SDLK_F12;
  235. static const int KEY_F13 = SDLK_F13;
  236. static const int KEY_F14 = SDLK_F14;
  237. static const int KEY_F15 = SDLK_F15;
  238. static const int KEY_F16 = SDLK_F16;
  239. static const int KEY_F17 = SDLK_F17;
  240. static const int KEY_F18 = SDLK_F18;
  241. static const int KEY_F19 = SDLK_F19;
  242. static const int KEY_F20 = SDLK_F20;
  243. static const int KEY_F21 = SDLK_F21;
  244. static const int KEY_F22 = SDLK_F22;
  245. static const int KEY_F23 = SDLK_F23;
  246. static const int KEY_F24 = SDLK_F24;
  247. static const int KEY_NUMLOCK = SDLK_NUMLOCKCLEAR;
  248. static const int KEY_SCROLLLOCK = SDLK_SCROLLLOCK;
  249. static const int KEY_LSHIFT = SDLK_LSHIFT;
  250. static const int KEY_RSHIFT = SDLK_RSHIFT;
  251. static const int KEY_LCTRL = SDLK_LCTRL;
  252. static const int KEY_RCTRL = SDLK_RCTRL;
  253. static const int KEY_LALT = SDLK_LALT;
  254. static const int KEY_RALT = SDLK_RALT;
  255. static const int HAT_CENTER = SDL_HAT_CENTERED;
  256. static const int HAT_UP = SDL_HAT_UP;
  257. static const int HAT_RIGHT = SDL_HAT_RIGHT;
  258. static const int HAT_DOWN = SDL_HAT_DOWN;
  259. static const int HAT_LEFT = SDL_HAT_LEFT;
  260. static const int CONTROLLER_BUTTON_A = SDL_CONTROLLER_BUTTON_A;
  261. static const int CONTROLLER_BUTTON_B = SDL_CONTROLLER_BUTTON_B;
  262. static const int CONTROLLER_BUTTON_X = SDL_CONTROLLER_BUTTON_X;
  263. static const int CONTROLLER_BUTTON_Y = SDL_CONTROLLER_BUTTON_Y;
  264. static const int CONTROLLER_BUTTON_BACK = SDL_CONTROLLER_BUTTON_BACK;
  265. static const int CONTROLLER_BUTTON_GUIDE = SDL_CONTROLLER_BUTTON_GUIDE;
  266. static const int CONTROLLER_BUTTON_START = SDL_CONTROLLER_BUTTON_START;
  267. static const int CONTROLLER_BUTTON_LEFTSTICK = SDL_CONTROLLER_BUTTON_LEFTSTICK;
  268. static const int CONTROLLER_BUTTON_RIGHTSTICK = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
  269. static const int CONTROLLER_BUTTON_LEFTSHOULDER = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
  270. static const int CONTROLLER_BUTTON_RIGHTSHOULDER = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
  271. static const int CONTROLLER_BUTTON_DPAD_UP = SDL_CONTROLLER_BUTTON_DPAD_UP;
  272. static const int CONTROLLER_BUTTON_DPAD_DOWN = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
  273. static const int CONTROLLER_BUTTON_DPAD_LEFT = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
  274. static const int CONTROLLER_BUTTON_DPAD_RIGHT = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
  275. static const int CONTROLLER_AXIS_LEFTX = SDL_CONTROLLER_AXIS_LEFTX;
  276. static const int CONTROLLER_AXIS_LEFTY = SDL_CONTROLLER_AXIS_LEFTY;
  277. static const int CONTROLLER_AXIS_RIGHTX = SDL_CONTROLLER_AXIS_RIGHTX;
  278. static const int CONTROLLER_AXIS_RIGHTY = SDL_CONTROLLER_AXIS_RIGHTY;
  279. static const int CONTROLLER_AXIS_TRIGGERLEFT = SDL_CONTROLLER_AXIS_TRIGGERLEFT;
  280. static const int CONTROLLER_AXIS_TRIGGERRIGHT = SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
  281. }