Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2006, 03:05 PM
DavidM DavidM is offline
Member
 
Join Date: Mar 2006
Posts: 37
Default WM_INPUT (RawData) to *Selectively* Intercept Keyboard Input?

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.
Reply With Quote
  #2  
Old 04-01-2006, 06:34 AM
DavidM DavidM is offline
Member
 
Join Date: Mar 2006
Posts: 37
Default RE: WM_INPUT (RawData) to *Selectively* Intercept Keyboard Input?

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 ...
Reply With Quote
  #3  
Old 08-20-2008, 04:59 AM
7gsoft 7gsoft is offline
Junior Member
 
Join Date: Aug 2008
Posts: 1
Default RE: WM_INPUT (RawData) to *Selectively* Intercept Keyboard Input?

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 !
Reply With Quote
  #4  
Old 03-10-2010, 11:08 AM
usear usear is offline
Junior Member
 
Join Date: Feb 2001
Posts: 5
Default

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
Reply With Quote
  #5  
Old 07-29-2012, 10:44 AM
talexone talexone is offline
Junior Member
 
Join Date: Jul 2012
Posts: 1
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:15 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.