BsInputFwd.h 14 KB

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