Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sorta fixed the g-keys #3

Open
xShirase opened this issue Jul 21, 2018 · 3 comments
Open

sorta fixed the g-keys #3

xShirase opened this issue Jul 21, 2018 · 3 comments

Comments

@xShirase
Copy link

So, once you deactivate the default mapping to f1-f9 with g910-led -gkm 1, you can capture / map / do whatever you want:

here's the dirty version that maps g1/g2 to copy/paste

import usb.core
import usb.util
import time


import uinput

gkeys = {
    'dump': bytearray(b'\x11\xff\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g1': bytearray(b'\x11\xff\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g2': bytearray(b'\x11\xff\x08\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g3': bytearray(b'\x11\xff\x08\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g4': bytearray(b'\x11\xff\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g5': bytearray(b'\x11\xff\x08\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g6': bytearray(b'\x11\xff\x08\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g7': bytearray(b'\x11\xff\x08\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g8': bytearray(b'\x11\xff\x08\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
    'g9': bytearray(b'\x11\xff\x08\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
}


def emitKeys(key):
    if key is 'g1':
        device.emit(uinput.KEY_LEFTCTRL, 1)
        device.emit(uinput.KEY_C, 1)
        device.emit(uinput.KEY_LEFTCTRL, 0)
        device.emit(uinput.KEY_C, 0)
    elif key is 'g2':
        device.emit(uinput.KEY_LEFTCTRL, 1)
        device.emit(uinput.KEY_V, 1)
        device.emit(uinput.KEY_LEFTCTRL, 0)
        device.emit(uinput.KEY_V, 0)


def first_diff_index(ls1, ls2):
    l = min(len(ls1), len(ls2))
    return next((i for i in range(l) if ls1[i] != ls2[i]), l)


device = uinput.Device([
    uinput.KEY_C, uinput.KEY_LEFTCTRL, uinput.KEY_V
])

USB_IF = 1  # Interface
USB_TIMEOUT = 5  # Timeout in MS

USB_VENDOR = 0x046d
USB_PRODUCT = 0xc335

dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
print(dev[0][(1, 0)])
endpoint = dev[0][(1, 0)][0]

if dev.is_kernel_driver_active(USB_IF) is True:
    dev.detach_kernel_driver(USB_IF)

usb.util.claim_interface(dev, USB_IF)

while True:
    control = None

    try:
        control = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, USB_TIMEOUT)

        if control:
            b = bytearray(control)
            if b in gkeys.values():
                if b == gkeys['dump']:
                    pass
                else:
                    key = list(gkeys.keys())[list(gkeys.values()).index(b)]
                    print(key)
                    emitKeys(key)
            else:
                print(b, 'no match')
    except:
        pass

    time.sleep(0.01)  # Let CTRL+C actually exit```
@JSubelj
Copy link

JSubelj commented Nov 8, 2018

Can i use this code to create a bit more user friendly mapper? Very excited to find this here :D

@xShirase
Copy link
Author

sure, go for it and let me know, please!

@JSubelj
Copy link

JSubelj commented Nov 26, 2018

Again thank you very much. I made it to the first release, you can find it here:
https://github.com/JSubelj/g910-gkey-macro-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants