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?
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.)