1

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:

  1. 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.

  2. 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!

asked Aug 23, 2011 at 12:42
2
  • How do you get the RFID input then? As keyboard events? Weird. Commented 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. Commented Aug 23, 2011 at 15:10

3 Answers 3

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.

answered Aug 23, 2011 at 12:50
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the quick reply! Sorry, I didn't explain enough, as I said though I litteraly no next to nothing about C++ i'm actualy a PHP web programmer, but my job has called me to try and make this little program. I just downloaded DevC++ to write/compile my program (Is there a better one I should be using) Oh and I got stumped when you said what framework library do you prefer to use, because I don't even know what that means (Is that somthing to do with using namespace xxx;?)... This is embarressing.. I will look at your links now, thank you
Oh and yes it does show up as a HID in device manager when I plug it in to the USB
0

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.

answered Aug 23, 2011 at 13:12

3 Comments

You don't need focus to subscribe and capture all events from a particular specified input device.
@Ben: The OP wrote about keeping focus ... I attempted to prevent the associated pain of trying that rabbit hole.
@Ben Is there any simpler way of doing this rather than all this complicated programming? It shows up as a HID device btw.
-1

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.

Rohit416
3,4963 gold badges27 silver badges42 bronze badges
answered Jul 7, 2016 at 10:02

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.