About the original input
In fact, in addition to traditional keyboards and mice, there are many input devices, such as game rods, touch screens, microphones, or other more flexible input devices. These devices are collectively referred to as HUMAN Interface Devices. The Raw INPUT API provides stability and robust support for any HID original input, including keyboards and mice.
This section covers the following:
Original input model registration Original input device Get original input data
Original input model
Previously, use the keyboard and the mouse as an input device, and the system is to interpret these device data by removing device specific description in the original information. For example, a keyboard generates a specific scan code, but the system is provided to the application of Virtual Key Code. In addition to supporting the equipment that hides the original input detail, the window manager does not support all new HIDs. To get an input from the hid that does not support, the application has to do many things: open a device, manage sharing mode, periodically read devices, or establish I / O Completion ports, etc. The original input model and the API simplifies these operations, making us very simple access to the original input data of all original input devices, where the keyboard and mouse are included.
The original input model is the same as the original keyboard, the mouse Microsoft® Windows® input model, the original model, the application receives the device in the form of a message that sends or submits to the form, such as
WM_CHAR
, WM_MOUSEMOVE and
WM_APPCommand.
In contrast, the originally entered application must register the device that needs to obtain data. Then, the application can receive the original input via the WM_INPUT message.
Here are the advantages of some original input models:
The application does not have to detect or open an input device; the application acquires data directly from the device, and can process only the data it needs; even if there is a user, the application can identify the source input. For example, there are two mice. Applications can specify a particular set of devices or specify only device types to perform data communication. As long as the market is available, the HID device can be used without having to wait for the system to support the new message type or update the OS to include the new command in WM_APCommand.
Note: WM_AppCommand is indeed support for some HID devices, however, WM_AppCommand is a more advanced device-independent input event, while WM_INPUT sends low raw data.
Register the original input device
By default, the application does not receive the original input. If you receive the original data, you must first register the input device.
To register the device, first create an array of RAWINPUTDEVICE structure, which contains top level collection (TLC). The TLC is defined by a usage page and a usage (class internal device). For example, if you want to get the keyboard TLC, you need to set USAGEPAGE = 1 and use usage = 6, then call RegisterRawinputDevices to complete the registration device.
Note: The application can register a device that is not currently not connected to the system. Once the device is connected, the window manager automatically sends the original input to the application. To get a list of original input devices in the system, you can call GetrawInputDeviceList. Use HDEvice in the call and then call GetRawinputDeviceInfo to get device information.
Through RAWINPUTDEVICE dwflags, the application can select the required device or which devices do not need. For example, an application requests input of all phones, but does not include a handle. For the sample code, see "Register the original input device". Note: The mouse, the keyboard is also HID, so their data can be obtained by HID messages WM_INPUT, or by traditional messages. Applications can select different methods to select different methods by setting the options in RAWINPUTDEVICE.
To get an app registration, you can call it via getRegisteredRawinputDevices.
Get raw input data
The application will receive the original input of the HID that has been registered. When you receive the original input, you get a WM_INPUT message in the message queue, and the queue status flag QS_RAWINPUT is set (QS_INPUT also contains the flag). Applications are reclaimed in the front desk or the background.
There are two ways to obtain raw data: methods for cache (standard) and cache methods. The non-caching method sequentially reads data of a RAWINPUT structure, and this method is suitable for many HIDs. Here, the application gets the WM_INPUT message by calling getMessage, and then calls GetrawInputData with the RAWINPUT handle in WM_INPU. See "Standard Method Get Original Input" for example.
Relatively, the cache method gives an array of RAWINPUT structures at a time. This is more suitable for those devices that may generate a lot of original input. In this method, the application gets the RAWINPUT structure array by calling getRawinputBuffer. Note that the NextRawinuptBlock macro is to traverse the RAWINPUT structure array. For example, please refer to "Cache Mode Read Original Input".
To explain the original input, you need the details of the HID to get the device information through getRawinputDeviceInfo, which can be obtained by WM_INPUT or RAWINPUTHEADER.HDEVICE.
Original: About Raw INPUT, MSDN.
© 2003 Microsoft Corporation. All Rights Reserved.
Translation: Room3rd @ Hotmail.com, 2004-11-25