BsInputFwd.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Math/BsVector2I.h"
  6. namespace bs
  7. {
  8. // Undefine conflicting defines from other libs
  9. #undef None
  10. /** @addtogroup Input
  11. * @{
  12. */
  13. /**
  14. * Contains all possible input buttons, including keyboard scan codes, mouse buttons and gamepad buttons.
  15. *
  16. * @note
  17. * These codes are only keyboard scan codes. This means that exact scan code identifier might not correspond to that
  18. * exact character on user's keyboard, depending on user's input locale. Only for US locale will these scan code names
  19. * match the actual keyboard input. Think of the US key code names as only a convenience for more easily identifying
  20. * which location on the keyboard a scan code represents.
  21. * @note
  22. * When storing these sequentially make sure to only reference the low order 2 bytes. Two high order bytes are used for
  23. * various flags.
  24. */
  25. enum ButtonCode : UINT32
  26. {
  27. BC_UNASSIGNED = 0x00,
  28. BC_ESCAPE = 0x01,
  29. BC_1 = 0x02,
  30. BC_2 = 0x03,
  31. BC_3 = 0x04,
  32. BC_4 = 0x05,
  33. BC_5 = 0x06,
  34. BC_6 = 0x07,
  35. BC_7 = 0x08,
  36. BC_8 = 0x09,
  37. BC_9 = 0x0A,
  38. BC_0 = 0x0B,
  39. BC_MINUS = 0x0C, // - on main keyboard
  40. BC_EQUALS = 0x0D,
  41. BC_BACK = 0x0E, // backspace
  42. BC_TAB = 0x0F,
  43. BC_Q = 0x10,
  44. BC_W = 0x11,
  45. BC_E = 0x12,
  46. BC_R = 0x13,
  47. BC_T = 0x14,
  48. BC_Y = 0x15,
  49. BC_U = 0x16,
  50. BC_I = 0x17,
  51. BC_O = 0x18,
  52. BC_P = 0x19,
  53. BC_LBRACKET = 0x1A,
  54. BC_RBRACKET = 0x1B,
  55. BC_RETURN = 0x1C, // Enter on main keyboard
  56. BC_LCONTROL = 0x1D,
  57. BC_A = 0x1E,
  58. BC_S = 0x1F,
  59. BC_D = 0x20,
  60. BC_F = 0x21,
  61. BC_G = 0x22,
  62. BC_H = 0x23,
  63. BC_J = 0x24,
  64. BC_K = 0x25,
  65. BC_L = 0x26,
  66. BC_SEMICOLON = 0x27,
  67. BC_APOSTROPHE = 0x28,
  68. BC_GRAVE = 0x29, // accent
  69. BC_LSHIFT = 0x2A,
  70. BC_BACKSLASH = 0x2B,
  71. BC_Z = 0x2C,
  72. BC_X = 0x2D,
  73. BC_C = 0x2E,
  74. BC_V = 0x2F,
  75. BC_B = 0x30,
  76. BC_N = 0x31,
  77. BC_M = 0x32,
  78. BC_COMMA = 0x33,
  79. BC_PERIOD = 0x34, // . on main keyboard
  80. BC_SLASH = 0x35, // / on main keyboard
  81. BC_RSHIFT = 0x36,
  82. BC_MULTIPLY = 0x37, // * on numeric keypad
  83. BC_LMENU = 0x38, // left Alt
  84. BC_SPACE = 0x39,
  85. BC_CAPITAL = 0x3A,
  86. BC_F1 = 0x3B,
  87. BC_F2 = 0x3C,
  88. BC_F3 = 0x3D,
  89. BC_F4 = 0x3E,
  90. BC_F5 = 0x3F,
  91. BC_F6 = 0x40,
  92. BC_F7 = 0x41,
  93. BC_F8 = 0x42,
  94. BC_F9 = 0x43,
  95. BC_F10 = 0x44,
  96. BC_NUMLOCK = 0x45,
  97. BC_SCROLL = 0x46, // Scroll Lock
  98. BC_NUMPAD7 = 0x47,
  99. BC_NUMPAD8 = 0x48,
  100. BC_NUMPAD9 = 0x49,
  101. BC_SUBTRACT = 0x4A, // - on numeric keypad
  102. BC_NUMPAD4 = 0x4B,
  103. BC_NUMPAD5 = 0x4C,
  104. BC_NUMPAD6 = 0x4D,
  105. BC_ADD = 0x4E, // + on numeric keypad
  106. BC_NUMPAD1 = 0x4F,
  107. BC_NUMPAD2 = 0x50,
  108. BC_NUMPAD3 = 0x51,
  109. BC_NUMPAD0 = 0x52,
  110. BC_DECIMAL = 0x53, // . on numeric keypad
  111. BC_OEM_102 = 0x56, // < > | on UK/Germany keyboards
  112. BC_F11 = 0x57,
  113. BC_F12 = 0x58,
  114. BC_F13 = 0x64, // (NEC PC98)
  115. BC_F14 = 0x65, // (NEC PC98)
  116. BC_F15 = 0x66, // (NEC PC98)
  117. BC_KANA = 0x70, // (Japanese keyboard)
  118. BC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards
  119. BC_CONVERT = 0x79, // (Japanese keyboard)
  120. BC_NOCONVERT = 0x7B, // (Japanese keyboard)
  121. BC_YEN = 0x7D, // (Japanese keyboard)
  122. BC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards
  123. BC_NUMPADEQUALS= 0x8D, // = on numeric keypad (NEC PC98)
  124. BC_PREVTRACK = 0x90, // Previous Track (BC_CIRCUMFLEX on Japanese keyboard)
  125. BC_AT = 0x91, // (NEC PC98)
  126. BC_COLON = 0x92, // (NEC PC98)
  127. BC_UNDERLINE = 0x93, // (NEC PC98)
  128. BC_KANJI = 0x94, // (Japanese keyboard)
  129. BC_STOP = 0x95, // (NEC PC98)
  130. BC_AX = 0x96, // (Japan AX)
  131. BC_UNLABELED = 0x97, // (J3100)
  132. BC_NEXTTRACK = 0x99, // Next Track
  133. BC_NUMPADENTER = 0x9C, // Enter on numeric keypad
  134. BC_RCONTROL = 0x9D,
  135. BC_MUTE = 0xA0, // Mute
  136. BC_CALCULATOR = 0xA1, // Calculator
  137. BC_PLAYPAUSE = 0xA2, // Play / Pause
  138. BC_MEDIASTOP = 0xA4, // Media Stop
  139. BC_VOLUMEDOWN = 0xAE, // Volume -
  140. BC_VOLUMEUP = 0xB0, // Volume +
  141. BC_WEBHOME = 0xB2, // Web home
  142. BC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98)
  143. BC_DIVIDE = 0xB5, // / on numeric keypad
  144. BC_SYSRQ = 0xB7,
  145. BC_RMENU = 0xB8, // right Alt
  146. BC_PAUSE = 0xC5, // Pause
  147. BC_HOME = 0xC7, // Home on arrow keypad
  148. BC_UP = 0xC8, // UpArrow on arrow keypad
  149. BC_PGUP = 0xC9, // PgUp on arrow keypad
  150. BC_LEFT = 0xCB, // LeftArrow on arrow keypad
  151. BC_RIGHT = 0xCD, // RightArrow on arrow keypad
  152. BC_END = 0xCF, // End on arrow keypad
  153. BC_DOWN = 0xD0, // DownArrow on arrow keypad
  154. BC_PGDOWN = 0xD1, // PgDn on arrow keypad
  155. BC_INSERT = 0xD2, // Insert on arrow keypad
  156. BC_DELETE = 0xD3, // Delete on arrow keypad
  157. BC_LWIN = 0xDB, // Left Windows key
  158. BC_RWIN = 0xDC, // Right Windows key
  159. BC_APPS = 0xDD, // AppMenu key
  160. BC_POWER = 0xDE, // System Power
  161. BC_SLEEP = 0xDF, // System Sleep
  162. BC_WAKE = 0xE3, // System Wake
  163. BC_WEBSEARCH = 0xE5, // Web Search
  164. BC_WEBFAVORITES= 0xE6, // Web Favorites
  165. BC_WEBREFRESH = 0xE7, // Web Refresh
  166. BC_WEBSTOP = 0xE8, // Web Stop
  167. BC_WEBFORWARD = 0xE9, // Web Forward
  168. BC_WEBBACK = 0xEA, // Web Back
  169. BC_MYCOMPUTER = 0xEB, // My Computer
  170. BC_MAIL = 0xEC, // Mail
  171. BC_MEDIASELECT = 0xED, // Media Select
  172. BC_MOUSE_LEFT = 0x800000EE, // Mouse buttons - Most important bit signifies this key is a mouse button
  173. BC_MOUSE_RIGHT,
  174. BC_MOUSE_MIDDLE,
  175. BC_MOUSE_BTN4,
  176. BC_MOUSE_BTN5,
  177. BC_MOUSE_BTN6,
  178. BC_MOUSE_BTN7,
  179. BC_MOUSE_BTN8,
  180. BC_MOUSE_BTN9,
  181. BC_MOUSE_BTN10,
  182. BC_MOUSE_BTN11,
  183. BC_MOUSE_BTN12,
  184. BC_MOUSE_BTN13,
  185. BC_MOUSE_BTN14,
  186. BC_MOUSE_BTN15,
  187. BC_MOUSE_BTN16,
  188. BC_MOUSE_BTN17,
  189. BC_MOUSE_BTN18,
  190. BC_MOUSE_BTN19,
  191. BC_MOUSE_BTN20,
  192. BC_MOUSE_BTN21,
  193. BC_MOUSE_BTN22,
  194. BC_MOUSE_BTN23,
  195. BC_MOUSE_BTN24,
  196. BC_MOUSE_BTN25,
  197. BC_MOUSE_BTN26,
  198. BC_MOUSE_BTN27,
  199. BC_MOUSE_BTN28,
  200. BC_MOUSE_BTN29,
  201. BC_MOUSE_BTN30,
  202. BC_MOUSE_BTN31,
  203. BC_MOUSE_BTN32,
  204. BC_GAMEPAD_A = 0x4000010F, // Joystick/Gamepad buttons- Second most important bit signifies key is a gamepad button
  205. BC_GAMEPAD_B, // Similar to keyboard names, these are for convenience named after Xbox controller buttons
  206. BC_GAMEPAD_X, // but if some other controller is connected you will need to learn yourself which of these
  207. BC_GAMEPAD_Y, // corresponds to which actual button on the controller.
  208. BC_GAMEPAD_LB,
  209. BC_GAMEPAD_RB,
  210. BC_GAMEPAD_LS,
  211. BC_GAMEPAD_RS,
  212. BC_GAMEPAD_BACK,
  213. BC_GAMEPAD_START,
  214. BC_GAMEPAD_DPAD_LEFT,
  215. BC_GAMEPAD_DPAD_RIGHT,
  216. BC_GAMEPAD_DPAD_UP,
  217. BC_GAMEPAD_DPAD_DOWN,
  218. BC_GAMEPAD_BTN1,
  219. BC_GAMEPAD_BTN2,
  220. BC_GAMEPAD_BTN3,
  221. BC_GAMEPAD_BTN4,
  222. BC_GAMEPAD_BTN5,
  223. BC_GAMEPAD_BTN6,
  224. BC_GAMEPAD_BTN7,
  225. BC_GAMEPAD_BTN8,
  226. BC_GAMEPAD_BTN9,
  227. BC_GAMEPAD_BTN10,
  228. BC_GAMEPAD_BTN11,
  229. BC_GAMEPAD_BTN12,
  230. BC_GAMEPAD_BTN13,
  231. BC_GAMEPAD_BTN14,
  232. BC_GAMEPAD_BTN15,
  233. BC_GAMEPAD_BTN16,
  234. BC_GAMEPAD_BTN17,
  235. BC_GAMEPAD_BTN18,
  236. BC_GAMEPAD_BTN19,
  237. BC_GAMEPAD_BTN20,
  238. BC_GAMEPAD_DPAD_UPLEFT,
  239. BC_GAMEPAD_DPAD_UPRIGHT,
  240. BC_GAMEPAD_DPAD_DOWNLEFT,
  241. BC_GAMEPAD_DPAD_DOWNRIGHT,
  242. BC_NumKeys = BC_MEDIASELECT - BC_UNASSIGNED + 1, // IMPORTANT: Make sure to update these if you modify the values above
  243. BC_NumMouse = BC_MOUSE_BTN32 - BC_MOUSE_LEFT + 1,
  244. BC_NumGamepad = BC_GAMEPAD_DPAD_DOWNRIGHT - BC_GAMEPAD_A + 1,
  245. BC_Count = BC_NumKeys + BC_NumMouse + BC_NumGamepad,
  246. };
  247. /** Contains data about a button input event. */
  248. struct ButtonEvent
  249. {
  250. public:
  251. ButtonEvent()
  252. :mIsUsed(false)
  253. { }
  254. ButtonCode buttonCode; /**< Button code this event is referring to. */
  255. UINT64 timestamp; /**< Timestamp in ticks when the event happened. */
  256. UINT32 deviceIdx; /**< Index of the device that the event originated from. */
  257. /** Query is the pressed button a keyboard button. */
  258. bool isKeyboard() const { return (buttonCode & 0xC0000000) == 0; }
  259. /** Query is the pressed button a mouse button. */
  260. bool isMouse() const { return (buttonCode & 0x80000000) != 0; }
  261. /** Query is the pressed button a gamepad button. */
  262. bool isGamepad() const { return (buttonCode & 0x40000000) != 0; }
  263. /**
  264. * Check if the event has been marked as used. Internally this means nothing but caller might choose to ignore an
  265. * used event.
  266. */
  267. bool isUsed() const { return mIsUsed; }
  268. /** Mark the event as used. Internally this means nothing but caller might choose to ignore an used event. */
  269. void markAsUsed() const { mIsUsed = true; }
  270. private:
  271. mutable bool mIsUsed;
  272. };
  273. /**
  274. * Pointer buttons. Generally these correspond to mouse buttons, but may be used in some form for touch input as well.
  275. */
  276. enum class PointerEventButton
  277. {
  278. Left, Middle, Right, Count
  279. };
  280. /** Type of pointer event.*/
  281. enum class PointerEventType
  282. {
  283. CursorMoved,
  284. ButtonPressed,
  285. ButtonReleased,
  286. DoubleClick
  287. };
  288. /**
  289. * Event that gets sent out when user interacts with the screen in some way, usually by moving the mouse cursor or
  290. * using touch input.
  291. */
  292. struct PointerEvent
  293. {
  294. public:
  295. PointerEvent()
  296. : button(PointerEventButton::Left), type(PointerEventType::CursorMoved), shift(false)
  297. , control(false), alt(false), mouseWheelScrollAmount(0.0f), mIsUsed(false)
  298. {
  299. buttonStates[0] = false;
  300. buttonStates[1] = false;
  301. buttonStates[2] = false;
  302. }
  303. Vector2I screenPos; /**< Screen position where the input event occurred. */
  304. Vector2I delta; /**< Change in movement since last sent event. */
  305. /** States of the pointer buttons (for example mouse buttons). */
  306. bool buttonStates[(UINT32)PointerEventButton::Count];
  307. /**
  308. * Button that triggered the pointer event. Might be irrelevant depending on event type. (for example move events
  309. * don't correspond to a button.
  310. */
  311. PointerEventButton button;
  312. PointerEventType type; /**< Type of the pointer event. */
  313. bool shift; /**< Is shift button on the keyboard being held down. */
  314. bool control; /**< Is control button on the keyboard being held down. */
  315. bool alt; /**< Is alt button on the keyboard being held down. */
  316. /** If mouse wheel is being scrolled, what is the amount. Only relevant for move events. */
  317. float mouseWheelScrollAmount;
  318. /**
  319. * Check if the event has been marked as used. Internally this means nothing but caller might choose to ignore an
  320. * used event.
  321. */
  322. bool isUsed() const { return mIsUsed; }
  323. /** Mark the event as used. Internally this means nothing but caller might choose to ignore an used event. */
  324. void markAsUsed() const { mIsUsed = true; }
  325. private:
  326. mutable bool mIsUsed;
  327. };
  328. /** Types of special input commands. */
  329. enum class InputCommandType
  330. {
  331. CursorMoveLeft, CursorMoveRight, CursorMoveUp, CursorMoveDown,
  332. SelectLeft, SelectRight, SelectUp, SelectDown,
  333. Escape, Delete, Backspace, Return, Confirm
  334. };
  335. /**
  336. * Event that gets sent out when user inputs some text. These events may be preceeded by normal button events if user
  337. * is typing on a keyboard.
  338. */
  339. struct TextInputEvent
  340. {
  341. public:
  342. TextInputEvent()
  343. :mIsUsed(false)
  344. { }
  345. UINT32 textChar; /**< Character the that was input. */
  346. /**
  347. * Check if the event has been marked as used. Internally this means nothing but caller might choose to ignore an
  348. * used event.
  349. */
  350. bool isUsed() const { return mIsUsed; }
  351. /** Mark the event as used. Internally this means nothing but caller might choose to ignore an used event. */
  352. void markAsUsed() const { mIsUsed = true; }
  353. private:
  354. mutable bool mIsUsed;
  355. };
  356. /** Types of input devices. */
  357. enum class InputDevice
  358. {
  359. Keyboard,
  360. Mouse,
  361. Gamepad,
  362. Count // Keep at end
  363. };
  364. /** Common input axis types. */
  365. enum class InputAxis
  366. {
  367. MouseX, /**< Mouse axis X. */
  368. MouseY, /**< Mouse axis Y. */
  369. MouseZ, /**< Mouse wheel/scroll axis. */
  370. LeftStickX, /**< Gamepad left stick X */
  371. LeftStickY, /**< Gamepad left stick Y */
  372. RightStickX, /**< Gamepad right stick X */
  373. RightStickY, /**< Gamepad right stick Y */
  374. LeftTrigger, /**< Gamepad left trigger */
  375. RightTrigger, /**< Gamepad right trigger */
  376. Count // Keep at end
  377. };
  378. /** Modifiers used with along with keyboard buttons. */
  379. enum class ButtonModifier
  380. {
  381. None = 0x00,
  382. Shift = 0x01,
  383. Ctrl = 0x02,
  384. Alt = 0x04,
  385. ShiftCtrl = 0x03,
  386. CtrlAlt = 0x06,
  387. ShiftAlt = 0x05,
  388. ShiftCtrlAlt = 0x07
  389. };
  390. /** @} */
  391. }