I am not profficient in C++ so answers explained well/in detail would be appreciated thank you. I have made a small C++ program that takes the input from an RFID reader (Similar to a barcode scanner) I have tried searching all over the internet for a simple answer but have had some mixed results.
I have two options, the first is much preffered:
Keep the console application in the background (just minimized is fine) and take keystrokes from the USB RFID reader, and ONLY from that source, so the user on the PC can use his/her keyboard and open other programs without the application being in focus.
Keep the application in focus even if the keyboard or mouse is accidently pressed, so even if the taskbar is clicked, or the application loses focus it will regain focus so it can carry on doing it's job
The answer I need cannot just be "Use this function SetWindowFocus()" or "Use this library and bla bla", I need a detailed answer on exactly what I need to do, because I don't even know where to start, thank you very much for your help!
-
How do you get the RFID input then? As keyboard events? Weird.wilx– wilx2011年08月23日 13:45:04 +00:00Commented Aug 23, 2011 at 13:45
-
@wilx: That makes sense, historically. RFID is sold as a successor to barcode readers, and those have been traditionally implemented as keyboards, too. Even before USB came on the market, they implemented PS/2 pass-though connectors. Quite useful, too: if the scanner couldn't read a barcode, you'd just manually enter the printed digits. No recoding needed at all.MSalters– MSalters2011年08月23日 15:10:56 +00:00Commented Aug 23, 2011 at 15:10
3 Answers 3
Does the RFID reader appear as an HID keyboard? The Win32 Raw Input API will allow you to subscribe to a particular keyboard and differentiate its input from the real keyboard.
Start by reading http://www.toymaker.info/Games/html/raw_input.html
To do this, your console application will need to create a normal window (I think it can be hidden) in addition to the console window.
It sounds like you really need some tutorials on Win32 programming.
Since you haven't given us any details (what compiler, are you using an IDE, is there a particular framework library you prefer to use) it's very difficult for us to give you specific advice. But there are some good introductory articles on Win32 window creation and message processing at Raymond Chen's blog "The Old New Thing". There's even a complete skeleton example you can use to start your own programs.
2 Comments
W.r.t, always retaining focus, you can't really do that.
See this blog post about the steps Microsoft has taken in newer versions of windows to avoid applications stealing focus and being "always on top".
I suggest either going fullscreen, thus avoiding the possibilty to click the taskbar (but one could use the windows button), or, hooking deep into the input device to always get events, no matter what the user is doing.
Neither solution is neat, but on Windows, that's the rules.
3 Comments
I had the same problem. I searched and tried many things.
With hidapi e.g. the RFID show info, but I couldn't read data. The C++ program works but the RFID reader write hex number everywhere. Maybe everyone have some code to initialize the reader into my program.