Determining source of keyboard input (BEEP! Orange juice added to shopping list)

Dec 12, 2008 at 7:27am
Hi all

BACKGROUND (you can skip to the question if you like):
I have a PC hanging in my living room, right next to the fridge. My family and I use that PC for everything - shopping list, file/print server, notes, calendars, email, surfing, etc. The input source is, of course, a USB keyboard.

Now, I got my hands on an old barcode scanner. It connects via PS2. I would LOVE to be able to scan the barcode of the last carton of orange juice and have that added to the shopping list instead of typing it in myself. I mean, just for the heck of it...

Now, here's the problem: The barcode scanner acts like a keyboard. When scanned, a barcode simply translates to a series of (typically 8) digits. No start/stop code or anything that I can use to identify that these characters originate from a barcode and is not charcters input on the USB keyboard.

I figure what I need to do is to create a program that runs in the background and continuously sniffs input characters and, when detected, determines if they originate from a PS2 device. If so, it finds the shopping item corresponding to the input and adds it to the shopping list.

QUESTION: How do you detect the input source (PS2 vs. USB keyboard) of a character input by the user?

TIA,
Corpus
Dec 12, 2008 at 12:53pm
Are both devices connected to the PC at the same time? Or do you unplug the KBD to plug-in the PS2?

I'm pretty sure that part of the USB specification is to identify the type of device that is connected. I really haven't messed with it before (so basically I don't know what I'm talking about :-| ) but you might want to take a look through here
http://msdn.microsoft.com/en-us/library/ms791083.aspx
http://msdn.microsoft.com/en-us/library/ms791080.aspx
to get started.

Hope this helps.
Dec 12, 2008 at 1:12pm
Hi again

Yes, both are plugged in - the KBD in the USB port, the scanner in the PS2 port. Thanks for the links.
Dec 12, 2008 at 10:01pm
Hmm, you could use GetConsoleMode() to test the input (the function returns failure if it is not a console). If it is not coming from a console (or keyboard) then it must be the scanner...

But alas, I don't know any better than that. (That might very well be a really bad solution.)
Last edited on Dec 12, 2008 at 10:01pm
Topic archived. No new replies allowed.