I got a simple test using cython-hidapi (you can install as pip install hidapi
- note that this is different from the link linked in the comment, but similar in function). I also installed hidapi-devel
from macports, but I'm not sure if this is necessary as it continues to work after the port is deactivated.
After changing the try.py example, use the VID / PID of the Microsoft USB Wireless Keyboard / Mouse device as follows
from __future__ import print_function import hid import time print("Opening the device") h = hid.device() h.open(1118, 2048)
And working with $ sudo python try.py
, I was able to get the following output:
Opening the device Manufacturer: Microsoft Product: Microsoft® Nano Transceiver v2.0 Serial No: None read: "[0, 0, 0, 0, 0, 0, 0, 0]" read: "[0, 0, 0, 0, 0, 0, 0, 0]" read: "[0, 0, 0, 0, 0, 0, 0, 0]" --8<-- snip lots of repeated lines --8<-- read: "[0, 0, 0, 0, 0, 0, 0, 0]" read: "[0, 0, 0, 0, 0, 0, 0, 0]" read: "[0, 0, 21, 0, 0, 0, 0, 0]" read: "[0, 0, 21, 0, 0, 0, 0, 0]" read: "[0, 0, 21, 0, 0, 0, 0, 0]" read: "[0, 0, 21, 0, 0, 0, 0, 0]" read: "[0, 0, 0, 0, 0, 0, 0, 0]" read: "[0, 0, 4, 0, 0, 0, 0, 0]" read: "[0, 0, 4, 22, 0, 0, 0, 0]" read: "[0, 0, 4, 22, 0, 0, 0, 0]" read: "[0, 0, 4, 22, 0, 0, 0, 0]" read: "[0, 0, 4, 22, 0, 0, 0, 0]" read: "[0, 0, 4, 22, 0, 0, 0, 0]" read: "[0, 0, 4, 0, 0, 0, 0, 0]" read: "[0, 0, 4, 0, 0, 0, 0, 0]" read: "[0, 0, 4, 9, 0, 0, 0, 0]" read: "[0, 0, 4, 9, 0, 0, 0, 0]" read: "[0, 0, 4, 9, 0, 0, 0, 0]" read: "[0, 0, 4, 9, 0, 0, 0, 0]" read: "[0, 0, 4, 9, 7, 0, 0, 0]" read: "[0, 0, 4, 9, 7, 0, 0, 0]" read: "[0, 0, 7, 0, 0, 0, 0, 0]" ^CClosing the device Traceback (most recent call last): File "try.py", line 17, in <module> d = h.read(64) KeyboardInterrupt
The particular device that I use seems to list as several HID devices for the keyboard and mouse among other things, so it seems like it's a bit random what you get, but for a barcode scanner it should be pretty straight forward.