-1

I have an RFID tag reader. But it works like a HID device (like a keyboard). It sends keystrokes to the computer when a tag is scanned. When I open notepad and scan a tag - it types the ID one digit at a time. Is there a way to create a program to listen to this device (or this port) and capture (intercept) all input. So that the keystrokes wouldn't appear on my system but I could assign my own events when the device sends and input. I don't want it to show up on Notepad.

I realize that the implementation can differ depending on the OS and programming language used. Ideally, I would like to make this work on both Windows and Linux. I would prefer to use something like Node.js but I suppose C could also be good.

I would appreciate any hints or pointing me in the right direction.

enter image description here

Liga
  • 3,291
  • 5
  • 34
  • 59

1 Answers1

1

You could open the raw input device for reading (basically ioctl with parameter EVIOCGRAB for Linux and RegisterRawInputDevices() for Windows as discussed here and here). However, the mechanisms are quite different for Windows and Linux, so you will end up implementing all the low-level logic twice.

It should also be possible to read the input data stream from the standard input just like you would read an input from the keyboard (e.g. scanf() or fgets() in C) with some logic that recognizes when a data set (= tag ID) is complete - the reader device might for example terminate an input with a newline '\n' or null character '\0'.

You should probably do this in a separate thread and have some kind of producer-consumer mechanism or event model for communication with your main application.

Gerd
  • 2,568
  • 1
  • 7
  • 20
  • yes I am able to read from the USB port. But how do I prevent it from sending HID keystrokes to the OS? I would like to intercept them. – Liga Jan 21 '20 at 10:57
  • I think this is explained in the linked questions: `ioctl` with parameter `EVIOCGRAB` for Linux and `RegisterRawInputDevices()` for Windows should give you exclusive access. Edited my answer, too. – Gerd Jan 21 '20 at 12:12
  • Thank you, Gerd! I was search all day for this! That seems to be what I was looking for! – Liga Jan 21 '20 at 13:12
  • Also found a Node.js package that uses ````ioctl```` and ````EVIOCGRAB```` here https://github.com/pfirpfel/node-exclusive-keyboard – Liga Jan 21 '20 at 14:38
  • Seems like for Windows I needed to install a hook using ````SetWindowsHookEx```` – Liga Jan 22 '20 at 06:05