usrinput.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. usrinput.h
  9. Abstract:
  10. This header contains definitions for the User Input library.
  11. Author:
  12. Evan Green 16-Feb-2013
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. #ifndef USER_INPUT_API
  21. #define USER_INPUT_API __DLLIMPORT
  22. #endif
  23. //
  24. // Define the name of the pipe where all user input is fed in to.
  25. //
  26. #define USER_INPUT_PIPE_NAME "/Pipe/UserInput"
  27. //
  28. // Define the current version of the user input keyboard device interface.
  29. //
  30. #define USER_INPUT_KEYBOARD_DEVICE_INTERFACE_VERSION 1
  31. //
  32. // Define the bitmask for a user input keyboard's LED state.
  33. //
  34. #define USER_INPUT_KEYBOARD_LED_NUM_LOCK 0x00000001
  35. #define USER_INPUT_KEYBOARD_LED_CAPS_LOCK 0x00000002
  36. #define USER_INPUT_KEYBOARD_LED_SCROLL_LOCK 0x00000004
  37. #define USER_INPUT_KEYBOARD_LED_COMPOSE 0x00000008
  38. #define USER_INPUT_KEYBOARD_LED_KANA 0x00000010
  39. //
  40. // Define the mouse event standard button flags.
  41. //
  42. #define MOUSE_BUTTON_LEFT 0x00000001
  43. #define MOUSE_BUTTON_RIGHT 0x00000002
  44. #define MOUSE_BUTTON_MIDDLE 0x00000004
  45. //
  46. // ------------------------------------------------------ Data Type Definitions
  47. //
  48. typedef enum _USER_INPUT_DEVICE_TYPE {
  49. UserInputDeviceInvalid,
  50. UserInputDeviceKeyboard,
  51. UserInputDeviceMouse,
  52. UserInputDeviceTypeCount
  53. } USER_INPUT_DEVICE_TYPE, *PUSER_INPUT_DEVICE_TYPE;
  54. typedef enum _USER_INPUT_EVENT_TYPE {
  55. UserInputEventInvalid,
  56. UserInputEventKeyDown,
  57. UserInputEventKeyUp,
  58. UserInputEventMouse,
  59. UserInputEventCount
  60. } USER_INPUT_EVENT_TYPE, *PUSER_INPUT_EVENT_TYPE;
  61. typedef enum _KEYBOARD_KEY {
  62. KeyboardKeyInvalid, /* 00 */
  63. KeyboardKeyEscape,
  64. KeyboardKey1,
  65. KeyboardKey2,
  66. KeyboardKey3,
  67. KeyboardKey4,
  68. KeyboardKey5,
  69. KeyboardKey6,
  70. KeyboardKey7,
  71. KeyboardKey8,
  72. KeyboardKey9,
  73. KeyboardKey0,
  74. KeyboardKeyDash,
  75. KeyboardKeyEquals,
  76. KeyboardKeyBackspace,
  77. KeyboardKeyTab,
  78. KeyboardKeyQ, /* 10 */
  79. KeyboardKeyW,
  80. KeyboardKeyE,
  81. KeyboardKeyR,
  82. KeyboardKeyT,
  83. KeyboardKeyY,
  84. KeyboardKeyU,
  85. KeyboardKeyI,
  86. KeyboardKeyO,
  87. KeyboardKeyP,
  88. KeyboardKeyLeftBracket,
  89. KeyboardKeyRightBracket,
  90. KeyboardKeyEnter,
  91. KeyboardKeyLeftControl,
  92. KeyboardKeyA,
  93. KeyboardKeyS,
  94. KeyboardKeyD, /* 20 */
  95. KeyboardKeyF,
  96. KeyboardKeyG,
  97. KeyboardKeyH,
  98. KeyboardKeyJ,
  99. KeyboardKeyK,
  100. KeyboardKeyL,
  101. KeyboardKeySemicolon,
  102. KeyboardKeyApostrophe,
  103. KeyboardKeyTilde,
  104. KeyboardKeyLeftShift,
  105. KeyboardKeyBackslash,
  106. KeyboardKeyZ,
  107. KeyboardKeyX,
  108. KeyboardKeyC,
  109. KeyboardKeyV,
  110. KeyboardKeyB, /* 30 */
  111. KeyboardKeyN,
  112. KeyboardKeyM,
  113. KeyboardKeyComma,
  114. KeyboardKeyPeriod,
  115. KeyboardKeySlash,
  116. KeyboardKeyRightShift,
  117. KeyboardKeyKeypadAsterisk,
  118. KeyboardKeyLeftAlt,
  119. KeyboardKeySpace,
  120. KeyboardKeyCapsLock,
  121. KeyboardKeyF1,
  122. KeyboardKeyF2,
  123. KeyboardKeyF3,
  124. KeyboardKeyF4,
  125. KeyboardKeyF5,
  126. KeyboardKeyF6, /* 40 */
  127. KeyboardKeyF7,
  128. KeyboardKeyF8,
  129. KeyboardKeyF9,
  130. KeyboardKeyF10,
  131. KeyboardKeyF11,
  132. KeyboardKeyF12,
  133. KeyboardKeyF13,
  134. KeyboardKeyF14,
  135. KeyboardKeyF15,
  136. KeyboardKeyF16,
  137. KeyboardKeyF17,
  138. KeyboardKeyF18,
  139. KeyboardKeyF19,
  140. KeyboardKeyF20,
  141. KeyboardKeyF21,
  142. KeyboardKeyF22, /* 50 */
  143. KeyboardKeyF23,
  144. KeyboardKeyF24,
  145. KeyboardKeyNumLock,
  146. KeyboardKeyScrollLock,
  147. KeyboardKeyKeypad0,
  148. KeyboardKeyKeypad1,
  149. KeyboardKeyKeypad2,
  150. KeyboardKeyKeypad3,
  151. KeyboardKeyKeypad4,
  152. KeyboardKeyKeypad5,
  153. KeyboardKeyKeypad6,
  154. KeyboardKeyKeypad7,
  155. KeyboardKeyKeypad8,
  156. KeyboardKeyKeypad9,
  157. KeyboardKeyKeypadMinus,
  158. KeyboardKeyKeypadPlus, /* 60 */
  159. KeyboardKeyKeypadPeriod,
  160. KeyboardKeySysRq,
  161. KeyboardKeyInternational1,
  162. KeyboardKeyInternational2,
  163. KeyboardKeyInternational3,
  164. KeyboardKeyInternational4,
  165. KeyboardKeyInternational5,
  166. KeyboardKeyInternational6,
  167. KeyboardKeyInternational7,
  168. KeyboardKeyInternational8,
  169. KeyboardKeyInternational9,
  170. KeyboardKeyHangul,
  171. KeyboardKeyHanja,
  172. KeyboardKeyKatakana,
  173. KeyboardKeyFurigana,
  174. KeyboardKeyKanji, /* 70 */
  175. KeyboardKeyHirijana,
  176. KeyboardKeyZenkaku,
  177. KeyboardKeyLanguage6,
  178. KeyboardKeyLanguage7,
  179. KeyboardKeyLanguage8,
  180. KeyboardKeyLanguage9,
  181. KeyboardKeyRedo,
  182. KeyboardKeyUndo,
  183. KeyboardKeyPaste,
  184. KeyboardKeySkipBack,
  185. KeyboardKeyCut,
  186. KeyboardKeyCopy,
  187. KeyboardKeySkipForward,
  188. KeyboardKeyKeypadEnter,
  189. KeyboardKeyRightControl,
  190. KeyboardKeyMail, /* 80 */
  191. KeyboardKeyMute,
  192. KeyboardKeyPlay,
  193. KeyboardKeyStop,
  194. KeyboardKeyEject,
  195. KeyboardKeyVolumeDown,
  196. KeyboardKeyVolumeUp,
  197. KeyboardKeyWeb,
  198. KeyboardKeyRightAlt,
  199. KeyboardKeyHelp,
  200. KeyboardKeyMusic,
  201. KeyboardKeyHome,
  202. KeyboardKeyUp,
  203. KeyboardKeyPageUp,
  204. KeyboardKeyLeft,
  205. KeyboardKeyRight,
  206. KeyboardKeyEnd, /* 90 */
  207. KeyboardKeyDown,
  208. KeyboardKeyPageDown,
  209. KeyboardKeyInsert,
  210. KeyboardKeyDelete,
  211. KeyboardKeyLeftWindows,
  212. KeyboardKeyRightWindows,
  213. KeyboardKeyMenu,
  214. KeyboardKeyPower,
  215. KeyboardKeySleep,
  216. KeyboardKeyWake,
  217. KeyboardKeyPictures,
  218. KeyboardKeyVideo,
  219. KeyboardKeyNonUsCurrency,
  220. KeyboardKeyBreak,
  221. KeyboardKeyKeypadSlash,
  222. KeyboardKeyNonUsBackslash, /* A0 */
  223. KeyboardKeyApplication,
  224. KeyboardKeyKeypadEquals,
  225. KeyboardKeyExecute,
  226. KeyboardKeySelect,
  227. KeyboardKeyAgain,
  228. KeyboardKeyFind,
  229. KeyboardKeyKeypadComma,
  230. KeyboardKeyCancel,
  231. KeyboardKeyClear,
  232. KeyboardKeyPrior,
  233. KeyboardKeySeparator,
  234. KeyboardKeyOut,
  235. KeyboardKeyOperator,
  236. KeyboardKeyCrSel,
  237. KeyboardKeyExSel,
  238. KeyboardKeyKeypad00, /* B0 */
  239. KeyboardKeyKeypad000,
  240. KeyboardKeyThousandsSeparator,
  241. KeyboardKeyDecimalSeparator,
  242. KeyboardKeyCurrencyUnit,
  243. KeyboardKeyCurrencySubunit,
  244. KeyboardKeyKeypadOpenParentheses,
  245. KeyboardKeyKeypadCloseParentheses,
  246. KeyboardKeyKeypadOpenCurlyBrace,
  247. KeyboardKeyKeypadCloseCurlyBrace,
  248. KeyboardKeyKeypadTab,
  249. KeyboardKeyKeypadBackspace,
  250. KeyboardKeyKeypadA,
  251. KeyboardKeyKeypadB,
  252. KeyboardKeyKeypadC,
  253. KeyboardKeyKeypadD,
  254. KeyboardKeyKeypadE, /* C0 */
  255. KeyboardKeyKeypadF,
  256. KeyboardKeyKeypadXor,
  257. KeyboardKeyKeypadCaret,
  258. KeyboardKeyKeypadPercent,
  259. KeyboardKeyKeypadLessThan,
  260. KeyboardKeyKeypadGreaterThan,
  261. KeyboardKeyKeypadAmpersand,
  262. KeyboardKeyKeypadDoubleAmpersand,
  263. KeyboardKeyKeypadPipe,
  264. KeyboardKeyKeypadDoublePipe,
  265. KeyboardKeyKeypadColon,
  266. KeyboardKeyKeypadHash,
  267. KeyboardKeyKeypadSpace,
  268. KeyboardKeyKeypadAt,
  269. KeyboardKeyKeypadExclamationPoint,
  270. KeyboardKeyKeypadMemoryStore, /* D0 */
  271. KeyboardKeyKeypadMemoryRecall,
  272. KeyboardKeyKeypadMemoryClear,
  273. KeyboardKeyKeypadMemoryAdd,
  274. KeyboardKeyKeypadMemorySubtract,
  275. KeyboardKeyKeypadMemoryMultiply,
  276. KeyboardKeyKeypadMemoryDivide,
  277. KeyboardKeyKeypadPlusMinus,
  278. KeyboardKeyKeypadClear,
  279. KeyboardKeyKeypadClearEntry,
  280. KeyboardKeyKeypadBinary,
  281. KeyboardKeyKeypadOctal,
  282. KeyboardKeyKeypadDecimal,
  283. KeyboardKeyKeypadHexadecimal,
  284. KeyboardKeyPrintScreen,
  285. KeyboardKeyMax
  286. } KEYBOARD_KEY, *PKEYBOARD_KEY;
  287. typedef struct _USER_INPUT_DEVICE USER_INPUT_DEVICE, *PUSER_INPUT_DEVICE;
  288. /*++
  289. Structure Description:
  290. This structure describes a mouse movement event.
  291. Members:
  292. MovementX - Stores the movement in the X direction.
  293. MovementY - Stores the movement in the Y direction.
  294. ScrollX - Stores the scroll wheel movement in the X direction.
  295. ScrollY - Stores the scroll whell movement in the Y direction.
  296. Flags - Stores additional flags.
  297. Buttons - Stores the button state.
  298. --*/
  299. typedef struct _MOUSE_EVENT {
  300. LONG MovementX;
  301. LONG MovementY;
  302. LONG ScrollX;
  303. LONG ScrollY;
  304. USHORT Flags;
  305. USHORT Buttons;
  306. } MOUSE_EVENT, *PMOUSE_EVENT;
  307. /*++
  308. Structure Description:
  309. This structure describes a user input device event.
  310. Members:
  311. EventIdentifier - Stores a unique event ID, assigned when the event is
  312. reported.
  313. DeviceIdentifier - Stores the unique identifier assigned to the device.
  314. DeviceType - Stores the type of device reporting the event.
  315. EventType - Stores the type of event occurring.
  316. Timestamp - Stores the time counter value when the event occurred.
  317. U - Stores the union of possible event data.
  318. Key - Stores the keyboard key being affected.
  319. Mouse - Stores the mouse event.
  320. --*/
  321. typedef struct _USER_INPUT_EVENT {
  322. ULONG EventIdentifier;
  323. ULONG DeviceIdentifier;
  324. USER_INPUT_DEVICE_TYPE DeviceType;
  325. USER_INPUT_EVENT_TYPE EventType;
  326. ULONGLONG Timestamp;
  327. union {
  328. KEYBOARD_KEY Key;
  329. MOUSE_EVENT Mouse;
  330. } U;
  331. } USER_INPUT_EVENT, *PUSER_INPUT_EVENT;
  332. typedef
  333. KSTATUS
  334. (*PUSER_INPUT_KEYBOARD_DEVICE_SET_LED_STATE) (
  335. PVOID Device,
  336. PVOID DeviceContext,
  337. ULONG LedState
  338. );
  339. /*++
  340. Routine Description:
  341. This routine sets a keyboard's LED state (e.g. Number lock, Caps lock and
  342. scroll lock). The state is absolute; the desired state for each LED must be
  343. supplied.
  344. Arguments:
  345. Device - Supplies a pointer to the OS device representing the user input
  346. device.
  347. DeviceContext - Supplies the opaque device context supplied in the device
  348. description upon registration with the user input library.
  349. LedState - Supplies a bitmask of flags describing the desired LED state.
  350. See USER_INPUT_KEYBOARD_LED_* for definition.
  351. Return Value:
  352. Status code.
  353. --*/
  354. /*++
  355. Structure Description:
  356. This structure defines an interface for a keyboard device that allows the
  357. user input library to update keyboard state.
  358. Members:
  359. SetLedState - Stores a pointer to a function used to set the keyboard's LED
  360. state.
  361. --*/
  362. typedef struct _USER_INPUT_KEYBOARD_DEVICE_INTERFACE {
  363. PUSER_INPUT_KEYBOARD_DEVICE_SET_LED_STATE SetLedState;
  364. } USER_INPUT_KEYBOARD_DEVICE_INTERFACE, *PUSER_INPUT_KEYBOARD_DEVICE_INTERFACE;
  365. /*++
  366. Structure Description:
  367. This structure describes a user input device that is being registered with
  368. the user input library.
  369. Members:
  370. Device - Stores a pointer to the OS device representing the user input
  371. device.
  372. DeviceContext - Stores an opaque token to device specific context.
  373. Type - Stores the type of user input device being described.
  374. InterfaceVersion - Stores the version of the device interface. For
  375. keyboards, set to USER_INPUT_KEYBOARD_DEVICE_INTERFACE_VERSION.
  376. KeyboardInterface - Stores the interface (function table) for a keyboard
  377. user input device.
  378. --*/
  379. typedef struct _USER_INPUT_DEVICE_DESCRIPTION {
  380. PVOID Device;
  381. PVOID DeviceContext;
  382. USER_INPUT_DEVICE_TYPE Type;
  383. ULONG InterfaceVersion;
  384. union {
  385. USER_INPUT_KEYBOARD_DEVICE_INTERFACE KeyboardInterface;
  386. } U;
  387. } USER_INPUT_DEVICE_DESCRIPTION, *PUSER_INPUT_DEVICE_DESCRIPTION;
  388. //
  389. // -------------------------------------------------------------------- Globals
  390. //
  391. //
  392. // -------------------------------------------------------- Function Prototypes
  393. //
  394. USER_INPUT_API
  395. HANDLE
  396. InRegisterInputDevice (
  397. PUSER_INPUT_DEVICE_DESCRIPTION Description
  398. );
  399. /*++
  400. Routine Description:
  401. This routine registers a new user input device.
  402. Arguments:
  403. Description - Supplies a pointer to the description of the user input
  404. device being registered.
  405. Return Value:
  406. Returns a handle to the user input device on success.
  407. INVALID_HANDLE on failure.
  408. --*/
  409. USER_INPUT_API
  410. VOID
  411. InDestroyInputDevice (
  412. HANDLE Handle
  413. );
  414. /*++
  415. Routine Description:
  416. This routine tears down state associated with a user input device created
  417. when the device was registered.
  418. Arguments:
  419. Handle - Supplies the handle to the registered device. When this function
  420. returns, the handle will be invalid.
  421. Return Value:
  422. None.
  423. --*/
  424. USER_INPUT_API
  425. KSTATUS
  426. InReportInputEvent (
  427. HANDLE Handle,
  428. PUSER_INPUT_EVENT Event
  429. );
  430. /*++
  431. Routine Description:
  432. This routine processes a new input event from the given device. This
  433. routine must be called at low level. The caller is expected to synchronize
  434. calls to report input for a device.
  435. Arguments:
  436. Handle - Supplies the handle to the registered device reporting the event.
  437. Event - Supplies a pointer to the event that occurred. The caller must
  438. supply this buffer, but it will only be used for the duration of the
  439. routine (a copy will be made). The caller must fill out the event type
  440. and union, and should expect all other fields to be overwritten.
  441. Return Value:
  442. STATUS_SUCCESS on success.
  443. STATUS_BUFFER_FULL if the input pipe is full of events and this one was
  444. dropped.
  445. --*/