3

I have a USB barcode scanner and am running a python script that collects data from /dev/hidraw0 and inputs the data into a database. The issue is that every time the scanner collects a code it additionally send it to the terminal and actually tries to log on to the system via the tty.

Is there a way to disable the HID from accessing the terminal and trying to log on, but still allowing the python script to collect the data?

Thank you in advance for any help that you can provide.

3
  • what do you mean when you say that the scanner tries to log in? ... is the scanner on a serial port or does it emulate a USB keyboard? Commented Jul 4, 2020 at 1:37
  • The scanner is emulating a USB keyboard. journalctl shows - login[800]: FAILED LOGIN 3 FROM tty1 FOR 012345678901, Authentication failure. The "012345678901" would be the scanned barcode. Commented Jul 4, 2020 at 1:47
  • so, your post is about ignoring keystrokes from a particular keyboard ... there should be info on the web dealing with that Commented Jul 4, 2020 at 1:49

2 Answers 2

3

Open /dev/input/path-to-your-scanner with the grab option. Use the path with symlinks that are constant across boots, not /dev/input/eventX.

See e.g. here for a Python evdev library that makes it easy to do from Python.

You cannot grab on the hidraw level, and unless you need the HID reports themselves for some reason, this is not necessary.

If you do need the hidraw level, then it will get tricky - you'll have to disengage the hidraw level from feeding into the input level. Or maybe open both the input device and the hidraw device, I've never tried that.

1
  • Thank you for responding and helping me get on the right track. None of the other answers I found were as clear as this one. I had to rewrite my code from python2 to python3 for the evdev module. Thanks again dirkt! Commented Jul 6, 2020 at 19:11
2

Here is a python script I wrote for a USB barcode scanner using the evdev library with grabbing functionality as suggested by @dirkt:

https://gist.github.com/michalfapso/1755e8a35bb83720c2559ce8ffde5f85

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.