CmInputFwd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmVector2I.h"
  4. namespace CamelotFramework
  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_JOY_BTN1 = 0x4000010F, // Joystick/Gamepad buttons- Second most important bit signifies key is a joystick button
  193. BC_JOY_BTN2 = 0x40000110,
  194. BC_JOY_BTN3 = 0x40000111,
  195. BC_JOY_BTN4 = 0x40000112,
  196. BC_JOY_BTN5 = 0x40000113,
  197. BC_JOY_BTN6 = 0x40000114,
  198. BC_JOY_BTN7 = 0x40000115,
  199. BC_JOY_BTN8 = 0x40000116,
  200. BC_JOY_BTN9 = 0x40000117,
  201. BC_JOY_BTN10 = 0x40000118,
  202. BC_JOY_BTN11 = 0x40000119,
  203. BC_JOY_BTN12 = 0x4000011A,
  204. BC_JOY_BTN13 = 0x4000011B,
  205. BC_JOY_BTN14 = 0x4000011C,
  206. BC_JOY_BTN15 = 0x4000011D,
  207. BC_JOY_BTN16 = 0x4000011E,
  208. BC_JOY_BTN17 = 0x4000011F,
  209. BC_JOY_BTN18 = 0x40000120,
  210. BC_JOY_BTN19 = 0x40000121,
  211. BC_JOY_BTN20 = 0x40000123,
  212. BC_JOY_BTN21 = 0x40000124,
  213. BC_JOY_BTN22 = 0x40000125,
  214. BC_JOY_BTN23 = 0x40000126,
  215. BC_JOY_BTN24 = 0x40000127,
  216. BC_JOY_BTN25 = 0x40000128,
  217. BC_JOY_BTN26 = 0x40000129,
  218. BC_JOY_BTN27 = 0x4000012A,
  219. BC_JOY_BTN28 = 0x4000012B,
  220. BC_JOY_BTN29 = 0x4000012C,
  221. BC_JOY_BTN30 = 0x4000012D,
  222. BC_JOY_BTN31 = 0x4000012E,
  223. BC_JOY_BTN32 = 0x4000012F,
  224. BC_Count = 0x00000130,
  225. BC_NumKeys = 0xEE, // IMPORTANT: Make sure to update these if you modify the values above
  226. BC_NumMouse = 0x20,
  227. BC_NumJoy = 0x20,
  228. };
  229. struct ButtonEvent
  230. {
  231. public:
  232. ButtonEvent()
  233. :mIsUsed(false)
  234. { }
  235. ButtonCode buttonCode;
  236. bool isKeyboard() const { return (buttonCode & 0xC0000000) == 0; }
  237. bool isMouse() const { return (buttonCode & 0x80000000) != 0; }
  238. bool isJoystick() const { return (buttonCode & 0x40000000) != 0; }
  239. bool isUsed() const { return mIsUsed; }
  240. void markAsUsed() const { mIsUsed = true; }
  241. private:
  242. mutable bool mIsUsed;
  243. };
  244. /**
  245. * @brief Positional input buttons. Generally these correspond to mouse
  246. * buttons, but may be used in some form for touch input as well.
  247. */
  248. enum class PositionalInputEventButton
  249. {
  250. Left, Middle, Right, Count
  251. };
  252. enum class PositionalInputEventType
  253. {
  254. CursorMoved,
  255. ButtonPressed,
  256. ButtonReleased,
  257. DoubleClick
  258. };
  259. /**
  260. * @brief Event that gets sent out when user interacts with the screen in some way,
  261. * usually by moving the mouse cursor or using touch input.
  262. */
  263. struct PositionalInputEvent
  264. {
  265. public:
  266. PositionalInputEvent()
  267. :mIsUsed(false), mouseWheelScrollAmount(0.0f), type(PositionalInputEventType::CursorMoved),
  268. shift(false), control(false), alt(false), button(PositionalInputEventButton::Left)
  269. {
  270. buttonStates[0] = false;
  271. buttonStates[1] = false;
  272. buttonStates[2] = false;
  273. }
  274. Vector2I screenPos;
  275. bool buttonStates[PositionalInputEventButton::Count];
  276. PositionalInputEventButton button;
  277. PositionalInputEventType type;
  278. bool shift;
  279. bool control;
  280. bool alt;
  281. float mouseWheelScrollAmount;
  282. bool isUsed() const { return mIsUsed; }
  283. void markAsUsed() const { mIsUsed = true; }
  284. private:
  285. mutable bool mIsUsed;
  286. };
  287. enum class InputCommandType
  288. {
  289. CursorMoveLeft, CursorMoveRight, CursorMoveUp, CursorMoveDown,
  290. SelectLeft, SelectRight, SelectUp, SelectDown, Undo, Redo,
  291. Escape, Delete, Backspace, Return, SelectAll, Copy, Cut, Paste, Tab
  292. };
  293. struct TextInputEvent
  294. {
  295. public:
  296. TextInputEvent()
  297. :mIsUsed(false)
  298. { }
  299. UINT32 textChar;
  300. bool isUsed() const { return mIsUsed; }
  301. void markAsUsed() const { mIsUsed = true; }
  302. private:
  303. mutable bool mIsUsed;
  304. };
  305. }