InputEvents.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. }
  68. /// Key released.
  69. EVENT(E_KEYUP, KeyUp)
  70. {
  71. PARAM(P_KEY, Key); // int
  72. PARAM(P_BUTTONS, Buttons); // int
  73. PARAM(P_QUALIFIERS, Qualifiers); // int
  74. }
  75. /// Character typed on the keyboard.
  76. EVENT(E_CHAR, Char)
  77. {
  78. PARAM(P_CHAR, Char); // int
  79. PARAM(P_BUTTONS, Buttons); // int
  80. PARAM(P_QUALIFIERS, Qualifiers); // int
  81. }
  82. /// Finger pressed on the screen.
  83. EVENT(E_TOUCHBEGIN, TouchBegin)
  84. {
  85. PARAM(P_TOUCHID, TouchID); // int
  86. PARAM(P_X, X); // int
  87. PARAM(P_Y, Y); // int
  88. PARAM(P_PRESSURE, Pressure); // float
  89. }
  90. /// Finger released from the screen.
  91. EVENT(E_TOUCHEND, TouchEnd)
  92. {
  93. PARAM(P_TOUCHID, TouchID); // int
  94. PARAM(P_X, X); // int
  95. PARAM(P_Y, Y); // int
  96. }
  97. /// Finger moved on the screen.
  98. EVENT(E_TOUCHMOVE, TouchMove)
  99. {
  100. PARAM(P_TOUCHID, TouchID); // int
  101. PARAM(P_X, X); // int
  102. PARAM(P_Y, Y); // int
  103. PARAM(P_DX, DX); // int
  104. PARAM(P_DY, DY); // int
  105. PARAM(P_PRESSURE, Pressure); // float
  106. }
  107. /// Joystick button pressed.
  108. EVENT(E_JOYSTICKBUTTONDOWN, JoystickButtonDown)
  109. {
  110. PARAM(P_JOYSTICK, Joystick); // int
  111. PARAM(P_BUTTON, Button); // int
  112. }
  113. /// Joystick button released.
  114. EVENT(E_JOYSTICKBUTTONUP, JoystickButtonUp)
  115. {
  116. PARAM(P_JOYSTICK, Joystick); // int
  117. PARAM(P_BUTTON, Button); // int
  118. }
  119. /// Joystick axis moved.
  120. EVENT(E_JOYSTICKAXISMOVE, JoystickAxisMove)
  121. {
  122. PARAM(P_JOYSTICK, Joystick); // int
  123. PARAM(P_AXIS, Button); // int
  124. PARAM(P_POSITION, Position); // float
  125. }
  126. /// Joystick POV hat moved.
  127. EVENT(E_JOYSTICKHATMOVE, JoystickHatMove)
  128. {
  129. PARAM(P_JOYSTICK, Joystick); // int
  130. PARAM(P_HAT, Button); // int
  131. PARAM(P_POSITION, Position); // int
  132. }
  133. /// Controller button pressed.
  134. EVENT(E_CONTROLLERBUTTONDOWN, ControllerButtonDown)
  135. {
  136. PARAM(P_JOYSTICK, Joystick); // int
  137. PARAM(P_BUTTON, Button); // int
  138. }
  139. /// Controller button released.
  140. EVENT(E_CONTROLLERBUTTONUP, ControllerButtonUp)
  141. {
  142. PARAM(P_JOYSTICK, Joystick); // int
  143. PARAM(P_BUTTON, Button); // int
  144. }
  145. /// Controller axis moved.
  146. EVENT(E_CONTROLLERAXISMOVE, ControllerAxisMove)
  147. {
  148. PARAM(P_JOYSTICK, Joystick); // int
  149. PARAM(P_AXIS, Button); // int
  150. PARAM(P_POSITION, Position); // float
  151. }
  152. /// A file was drag-dropped into the application window.
  153. EVENT(E_DROPFILE, DropFile)
  154. {
  155. PARAM(P_FILENAME, FileName); // String
  156. }
  157. /// Application input focus or minimization changed.
  158. EVENT(E_INPUTFOCUS, InputFocus)
  159. {
  160. PARAM(P_FOCUS, Focus); // bool
  161. PARAM(P_MINIMIZED, Minimized); // bool
  162. }
  163. /// OS mouse cursor visibility changed.
  164. EVENT(E_MOUSEVISIBLECHANGED, MouseVisibleChanged)
  165. {
  166. PARAM(P_VISIBLE, Visible); // bool
  167. }
  168. /// Application exit requested.
  169. EVENT(E_EXITREQUESTED, ExitRequested)
  170. {
  171. }
  172. static const int MOUSEB_LEFT = 1;
  173. static const int MOUSEB_MIDDLE = 2;
  174. static const int MOUSEB_RIGHT = 4;
  175. static const int QUAL_SHIFT = 1;
  176. static const int QUAL_CTRL = 2;
  177. static const int QUAL_ALT = 4;
  178. static const int QUAL_ANY = 8;
  179. static const int KEY_BACKSPACE = SDLK_BACKSPACE;
  180. static const int KEY_TAB = SDLK_TAB;
  181. static const int KEY_RETURN = SDLK_RETURN;
  182. static const int KEY_RETURN2 = SDLK_RETURN2;
  183. static const int KEY_KP_ENTER = SDLK_KP_ENTER;
  184. static const int KEY_SHIFT = SDLK_LSHIFT;
  185. static const int KEY_CTRL = SDLK_LCTRL;
  186. static const int KEY_ALT = SDLK_LALT;
  187. static const int KEY_PAUSE = SDLK_PAUSE;
  188. static const int KEY_CAPSLOCK = SDLK_CAPSLOCK;
  189. static const int KEY_ESC = SDLK_ESCAPE;
  190. static const int KEY_SPACE = SDLK_SPACE;
  191. static const int KEY_PAGEUP = SDLK_PAGEUP;
  192. static const int KEY_PAGEDOWN = SDLK_PAGEDOWN;
  193. static const int KEY_END = SDLK_END;
  194. static const int KEY_HOME = SDLK_HOME;
  195. static const int KEY_LEFT = SDLK_LEFT;
  196. static const int KEY_UP = SDLK_UP;
  197. static const int KEY_RIGHT = SDLK_RIGHT;
  198. static const int KEY_DOWN = SDLK_DOWN;
  199. static const int KEY_SELECT = SDLK_SELECT;
  200. static const int KEY_PRINTSCREEN = SDLK_PRINTSCREEN;
  201. static const int KEY_INSERT = SDLK_INSERT;
  202. static const int KEY_DELETE = SDLK_DELETE;
  203. static const int KEY_LWIN = SDLK_LGUI;
  204. static const int KEY_RWIN = SDLK_RGUI;
  205. static const int KEY_APPS = SDLK_APPLICATION;
  206. static const int KEY_NUMPAD0 = SDLK_KP_0;
  207. static const int KEY_NUMPAD1 = SDLK_KP_1;
  208. static const int KEY_NUMPAD2 = SDLK_KP_2;
  209. static const int KEY_NUMPAD3 = SDLK_KP_3;
  210. static const int KEY_NUMPAD4 = SDLK_KP_4;
  211. static const int KEY_NUMPAD5 = SDLK_KP_5;
  212. static const int KEY_NUMPAD6 = SDLK_KP_6;
  213. static const int KEY_NUMPAD7 = SDLK_KP_7;
  214. static const int KEY_NUMPAD8 = SDLK_KP_8;
  215. static const int KEY_NUMPAD9 = SDLK_KP_9;
  216. static const int KEY_MULTIPLY = SDLK_KP_MULTIPLY;
  217. static const int KEY_ADD = SDLK_KP_PLUS;
  218. static const int KEY_SUBTRACT = SDLK_KP_MINUS;
  219. static const int KEY_DECIMAL = SDLK_KP_PERIOD;
  220. static const int KEY_DIVIDE = SDLK_KP_DIVIDE;
  221. static const int KEY_F1 = SDLK_F1;
  222. static const int KEY_F2 = SDLK_F2;
  223. static const int KEY_F3 = SDLK_F3;
  224. static const int KEY_F4 = SDLK_F4;
  225. static const int KEY_F5 = SDLK_F5;
  226. static const int KEY_F6 = SDLK_F6;
  227. static const int KEY_F7 = SDLK_F7;
  228. static const int KEY_F8 = SDLK_F8;
  229. static const int KEY_F9 = SDLK_F9;
  230. static const int KEY_F10 = SDLK_F10;
  231. static const int KEY_F11 = SDLK_F11;
  232. static const int KEY_F12 = SDLK_F12;
  233. static const int KEY_F13 = SDLK_F13;
  234. static const int KEY_F14 = SDLK_F14;
  235. static const int KEY_F15 = SDLK_F15;
  236. static const int KEY_F16 = SDLK_F16;
  237. static const int KEY_F17 = SDLK_F17;
  238. static const int KEY_F18 = SDLK_F18;
  239. static const int KEY_F19 = SDLK_F19;
  240. static const int KEY_F20 = SDLK_F20;
  241. static const int KEY_F21 = SDLK_F21;
  242. static const int KEY_F22 = SDLK_F22;
  243. static const int KEY_F23 = SDLK_F23;
  244. static const int KEY_F24 = SDLK_F24;
  245. static const int KEY_NUMLOCK = SDLK_NUMLOCKCLEAR;
  246. static const int KEY_SCROLLLOCK = SDLK_SCROLLLOCK;
  247. static const int KEY_LSHIFT = SDLK_LSHIFT;
  248. static const int KEY_RSHIFT = SDLK_RSHIFT;
  249. static const int KEY_LCTRL = SDLK_LCTRL;
  250. static const int KEY_RCTRL = SDLK_RCTRL;
  251. static const int KEY_LALT = SDLK_LALT;
  252. static const int KEY_RALT = SDLK_RALT;
  253. static const int HAT_CENTER = SDL_HAT_CENTERED;
  254. static const int HAT_UP = SDL_HAT_UP;
  255. static const int HAT_RIGHT = SDL_HAT_RIGHT;
  256. static const int HAT_DOWN = SDL_HAT_DOWN;
  257. static const int HAT_LEFT = SDL_HAT_LEFT;
  258. static const int CONTROLLER_BUTTON_A = SDL_CONTROLLER_BUTTON_A;
  259. static const int CONTROLLER_BUTTON_B = SDL_CONTROLLER_BUTTON_B;
  260. static const int CONTROLLER_BUTTON_X = SDL_CONTROLLER_BUTTON_X;
  261. static const int CONTROLLER_BUTTON_Y = SDL_CONTROLLER_BUTTON_Y;
  262. static const int CONTROLLER_BUTTON_BACK = SDL_CONTROLLER_BUTTON_BACK;
  263. static const int CONTROLLER_BUTTON_GUIDE = SDL_CONTROLLER_BUTTON_GUIDE;
  264. static const int CONTROLLER_BUTTON_START = SDL_CONTROLLER_BUTTON_START;
  265. static const int CONTROLLER_BUTTON_LEFTSTICK = SDL_CONTROLLER_BUTTON_LEFTSTICK;
  266. static const int CONTROLLER_BUTTON_RIGHTSTICK = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
  267. static const int CONTROLLER_BUTTON_LEFTSHOULDER = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
  268. static const int CONTROLLER_BUTTON_RIGHTSHOULDER = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
  269. static const int CONTROLLER_BUTTON_DPAD_UP = SDL_CONTROLLER_BUTTON_DPAD_UP;
  270. static const int CONTROLLER_BUTTON_DPAD_DOWN = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
  271. static const int CONTROLLER_BUTTON_DPAD_LEFT = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
  272. static const int CONTROLLER_BUTTON_DPAD_RIGHT = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
  273. static const int CONTROLLER_AXIS_LEFTX = SDL_CONTROLLER_AXIS_LEFTX;
  274. static const int CONTROLLER_AXIS_LEFTY = SDL_CONTROLLER_AXIS_LEFTY;
  275. static const int CONTROLLER_AXIS_RIGHTX = SDL_CONTROLLER_AXIS_RIGHTX;
  276. static const int CONTROLLER_AXIS_RIGHTY = SDL_CONTROLLER_AXIS_RIGHTY;
  277. static const int CONTROLLER_AXIS_TRIGGERLEFT = SDL_CONTROLLER_AXIS_TRIGGERLEFT;
  278. static const int CONTROLLER_AXIS_TRIGGERRIGHT = SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
  279. }