BsInputFwd.h 14 KB

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