Intercept USB keyboard input

With a Delphi application, how can I intercept USB keyboard input from a Delphi application running in the background.  Unless the data starts with a particular character, the Delphi application would let pass through the keystrokes to the forground application.  The keyboard input is coming from a USB magnetic card reader.

I can do this with a serial port.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A USB keyboard or any keyboard interface for that matter usually presents itself as a wedge, whereby the keystrokes are filled into the normal keyboard buffer, so it looks no different to input from any keyboard, magnetic card reader or normal.  Is the distinction important?  I have a feeling it is, in which case it could be quite difficult to identify the actual source.

Otherwise, just set up a normal keyboard hook - but you need to identify some start/end keystrokes, and buffer up some input to return to the stream if they keys were not intended for your app.

An example keyboard hook:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.