Capturing input from a usb device in Linux

So after a little searching ... found the following way to capture input from my USB QR code scanner.

import sys
pipe = open('/dev/input/event3', 'r')
while 1:
        for character in pipe.read():
                print(character)

      

This works, but I still have 2 questions regarding the method above.

I am on a raspberry device with Debian Wheezy and a GUI and can confirm question 2 happening in the GUI ... don't know yet what to output to a system without a GUI

  • The best way to do this?
  • The above method, when I right click the script cancels and outputs all the records that were scanned at once. Why is this?

UPDATE

I think I missed interpreting the result for the code above, as it finally outputs ASCII characters, so I ended up doing the following:

sys.stdin = open('/dev/tty')
a = raw_input('Scan: ')

      

+3


source to share


1 answer


Question 1 really depends on your QR scanner. I think you're lucky it works like this, because most of the time USB devices have complex protocols for communicating with hosts. For example, using a mouse, how would you distinguish between clicks and mouse movement? You need some kind of data format to exchange.



Question 2 is probably because your method is blocking pipe.read (), waiting for input. Either way, just a right click ends the read () function and lets you print the print

+1


source







All Articles