So, after searching a little bit... have found the following way to capture the input from my USB QR code scanner.
import sys
pipe = open('/dev/input/event3', 'r')
while 1:
for character in pipe.read():
print(character)
It works, but I still have 2 questions regarding the method above.
I'm on a Raspberry device with Debian Wheezy and a GUI, and can confirm Question 2 happening on a GUI... don't know yet the output on a system without GUI
I think I have miss interpreted the result for the code above, as it finally it outputs ASCII characters, so I ended up doing the following:
sys.stdin = open('/dev/tty')
a = raw_input('Scan: ')
Question 1 really depends on your QR scanner. I think you are lucky this works like this, since much of the time, usb devices have complex protocols to communicate with hosts. For example, with a mouse, how would you differentiate between clicks and mouse movement? You need some kind of data format to exchange.
Question 2 is probably because your method blocks at pipe.read(), waiting for input. Somehow, only the right click ends the read() function and allows the print to work out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With