Link to home
Start Free TrialLog in
Avatar of David Williams
David WilliamsFlag for Australia

asked on

Capture keyboard input into another window

I have a program (without source code) that reads in barcodes from a hand-held scanner and performs database operations. The scanner just connects to the serial port and its driver simply inserts data into the keyboard buffer. So, I'm pretty sure the details of the scanner are irrelevant.

Now, I need a second program that can run at the same time and _also_ grab the data that has been input for processing of its own.  I don't have the source code for the 1st program so I guess (for the moment, anyway) this needs to be a separate stand-alone app.

Can anyone give me some working Delphi code that will grab keyboard input for the active window - while still letting the active window run as normal and process it?
Avatar of Tussin
Tussin
Flag of Thailand image

I have had a problem like this before.

try this component. It's easy to use and come with demo.

http://www.utilmind.com/delphi/keyspy.zip
http://www.utilmind.com/delphi/exe-demo/KeySpyDemo.exe

Cheers,
Tussin
Avatar of Tasomia
Tasomia

The component keyspy only works for win 95/98 but
not NT.
This is the another URL ... load the component "KeySpy" and its demo

http://homepages.borland.com/torry/keysandkeyboard.htm#3367
Avatar of David Williams

ASKER

Thanks, I've got it now.

Unfortunately, I'm using Windows 2000.  I can install the keyspy component but whenever I drop it onto my form, Delphi gives an error message and closes.

Perhaps you can help me with my app -

I have a program running which takes data from a barcode scanner.  The barcodes are in the form Q0321117[Enter].  This program has to run without interruption.

I need a second program which starts and prompts for a four digit number.  The user then clicks 'Start' and the program begins intercepting keyboard messages.  Whenever any barcodes are scanned (which are stuffed into the keyboard buffer) the program should compare the last four digits with the four digit number that was input at the beginning.  If they don't match, it should beep three times.  This should keep happening until the user clicks 'Stop'.

I think this program will be dead simple to write once I can intercept keyboard messages for another application.  It looks like keyspy can do that for me.

So, this is what I'd like -

 - a Windows NT/2000 equivalent to keyspy
 - or, source code and compiled exe for a program to do precisely the above.  The run-time machine is Windows 98 so this isn't a problem.  It's just that my development system is Windows 2000.  If you provide a working project I'll increase the number of points.  My email is dave@qed.newcastle.edu.au

Thanks !
Just an idea why down't y use a keyboard hook then the prog would work on NT and on win9x. The only problem that a keyboard hook has it that it doesn't work if you run a directx full screen app (a game) or if you set another keyboard hook after your first one, then the first one sometimes doesn't work
Can you supply working Delphi code for a keyboard hook?
ASKER CERTIFIED SOLUTION
Avatar of lfrodrigues
lfrodrigues

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That looks really great; let me just take a moment to test it out, and then I'll get back to you!
That code is excellent!!  I made a program group for the DLL and the test form and I was able to start notepad and see that the test form accurately grabbed and recorded the number of keystrokes.  Brilliant stuff!

The only thing left is to be able to interpret the data meaningfully.  How can I modify the test app to actually read the actual keystrokes pressed, rather than just sum the up?  What is needed there?  Thanks !!
Not to worry, I managed to make the mods to save a string easily enough.  The DLL code you gave, and sample app, certainly saved me absolutely days and days of time !  Many thanks!
I'm glad i could help.

thanks,bye
                        LR