BsInputFwd.h 14 KB

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