usrinput.h 12 KB

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