Equivalent to Python evdev for OSX

I wrote a python script that will query evdev for a HID barcode scanner (emulates a keyboard): the script works well on Linux (Ubuntu) platforms. Is there an OS X Python equivalent for evdev that would allow minor porting of an existing python script?

If you have Python experience and configured it to enter a HID device, indicate this in your answer.

+6
source share
2 answers

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) # A Microsoft wireless combo keyboard & mouse print("Manufacturer: %s" % h.get_manufacturer_string()) print("Product: %s" % h.get_product_string()) print("Serial No: %s" % h.get_serial_number_string()) try: while True: d = h.read(64) if d: print('read: "{}"'.format(d)) finally: print("Closing the device") h.close() 

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.

+4
source

I think there is no evdev port for mac os, because the latter depends on the linux kernel. If you want to embed some business logic in HID on mac os, you should use, as in the comments, a high-level abstraction is suggested. But if you want evdev at a low level, I think this is an easy way to do this with Docker . I have no experience with HID devices on Mac OS, but I solved this problem with a different driver.

+2
source

Source: https://habr.com/ru/post/1013051/


All Articles