0

So, I have a small python scriptlet that remaps my logitech g710 gkeys from the default of 1-6 to F13-18, which works fine when called manually, eg: ./script.py /dev/hidraw3

The issue I'm having is autorunning the script on device plugin. Currently I have a udev rule that theoretically should work, but does not.

SUBSYSTEM=="hidraw", KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c24d", ATTRS{bInterfaceNumber}=="01", ACTION=="add", RUN+="/usr/local/bin/g710.py %k"

whole script:

#!/usr/bin/python3
import sys
import hid

def bindkeys(node):
    board = hid.device()
    board.open_path(sys.argv[1].encode())
    board.send_feature_report([9, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0, 0, 0, 0, 0, 0])
    print("script fired")
    print(board.get_manufacturer_string())
    board.close()

def main(args):
    bindkeys(args)

if __name__ == '__main__':
    main(sys.argv[1].encode())

I'm at a serious loss as to what's wrong.

0

Well, it seems that the SUBSYSTEM=="hidraw" is too far removed from SUBSYSTEM=="usb" to be able to use ATTRS{bInterfaceNumber}, so, I just retooled the script to find the proper hidraw node itself and only fire it when the proper device is inserted:

#!/usr/bin/python3
import hid

def bindkeys(node):
    board = hid.device()
    board.open_path(node)
    board.send_feature_report([9, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0, 0, 0, 0, 0, 0])
    board.close()

def find_g710():
    for device in hid.enumerate():
        if device['vendor_id'] == 0x046d and device['product_id'] == 0xc24d and device['interface_number'] == 1:
            return device['path']

def main():
    g710 = find_g710()
    bindkeys(g710)

if __name__ == '__main__':
    main()

with the following udev rule:

SUBSYSTEM=="hidraw", ACTION=="add", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c24d", RUN+="/usr/local/bin/g710.py"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.