![]() |
|
#1
|
|||
|
|||
|
I am working on an application that needs to intercept keystrokes from a specific keyboard device without affecting the standard "legacy" messages from other keyboard devices. I have successfully implemented the RegisterRawInputDevices() function, and I can receive and read the WM_INPUT message and data. By checking the device handle in the RAWINPUTHEADER, I can determine which keystrokes are from the device of interest. I can then send an application message indicating the action to be taken. However, when the keystroke comes from some other keyboard device, i.e. the standard keyboard, I really just want to let the system handle the keystroke normally.
If I register the devices with the RIDEV_NOLEGACY flag, then none of these messages (WM_KEYDOWN, WM_KEYUP, etc) is sent by the system for any of the keyboard devices. If I do not use the RIDEV_NOLEGACY flag, then these messages are sent for all keyboard devices, including the one I want to intercept. Is there any way to suppress the "legacy" messages for the keystrokes I intercept, or to force the legacy messages for the keystrokes I don't? I would welcome comments or suggestions from anyone who has used this process, especially in a Delphi application. I am developing on Windows XP Professional (SP1) using Delphi 2005. |
|
#2
|
|||
|
|||
|
Quote: Text Previous Post
I am working on an application that needs to intercept keystrokes from a specific keyboard device without affecting the standard "legacy" messages from other keyboard devices. ... Just in case anyone is interested, I solved this problem myself, although I think it is a hack. When I register for the raw input, I did NOT use the RIDEV_NOLEGACY flag, so all messages are sent. Then assigned the following function to the Application.OnMessage property: [DELPHI]procedure TRawObj.AppMsgHandler (var Msg: TMsg; var Handled: Boolean); begin Handled := False; if ((hSendMsg <> 0) and ((oDevList.Count > 0) or (bScanning))) then begin case Msg.message of WM_INPUT: Handled := AppMsg_WMINPUT(Msg); WM_KEYFIRST..WM_KEYLAST: Handled := bSkipLegacy; end; end; end; [/DELPHI] Note that bSkipLegacy is a private property of the TRawObj class. It is set to True in the AppMsg_WMINPUT funtion if the message came from my device. If Handled is set to true, then the message will not be handled by the default processing. The AppMsg_WMINPUT function is rather long, so I will not post it here, but if anyone is interested, I will be glad to provide the source. In essence the function: 1) uses GetRawData to retrieve the HEADER and DATA; 2) if the HEADER.hDevice is NOT my device: then Set bSkipLegacy = False; and return false; else Set bSkipLegacy = True; PostMessage to my form; return true; Talking to yourself is OK, unless you start answering your own questions. ... Hmm ... |
|
#3
|
|||
|
|||
|
Many thanks for this tip, handling WM_INPUT (that doesn't accept obviously a result) then giving it's handled state to WM_Keydown and others to block messages that we don't want farther in the application is exactly what i've been searching for for nearly 4 days !!
i used your trick to handle a keypad for secure identification; it was declared in windows peripherals as a Keyboard, so intercepting its messages with rawinput and WM_INPUT was quite easy, but avoiding its WM_KEYDOWN message from displaying the identifier was my main problem. many thanks again ! |
|
#4
|
|||
|
|||
|
Hello all,
I am really interested in using the wm_input api and have a slightly different application for it. If any of you can share the source for your implementation I will be grateful. Basically I have an application with multiple touch screens and I want to identify which touch screen the input is comming from do decide whether to use or ignore the input. Kind Regards Umar |
|
#5
|
|||
|
|||
|
Hello,
I use usb rfid reader as hid keyboard device. I put together a pieces of DavidM code I found on this site and it works well just for one instance, others apps still get input from both keyboards. Tried with SetWindowsHookEx, but can't get deviceid with it. DavidM: Your solution can solve it, or you just use one app? Regards, Alex |
![]() |
| Thread Tools | |
| Display Modes | |
|
|