Giter VIP home page Giter VIP logo

g910-gkey-uinput's People

Contributors

creimer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

andreee94 djraw

g910-gkey-uinput's Issues

sorta fixed the g-keys

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```

How does it work and how can we install it?

Hi, I would have liked to know how this script works which (if I understood correctly) should allow to use the G keys of the G910 keyboards, and how to install it.

Indeed, I installed, with pip, python-uinput, pyudev, glob3 and hidraw.

┌─(~/g910-gkey-uinput)──────────────────────────────────────────(troupal@name-of-net:pts/0)─┐
└─(18:50:16 on master)──> sudo pip install python-uinput hidraw pyudev glob3  

When I run the script with python, I don't get any answers to indicate that it works, and the G keys are always the same as the Fx keys. And when I stop the script with Ctrl-C, I get an error that says:

┌─(~/g910-gkey-uinput)──────────────────────────────────────────(troupal@name-of-net:pts/0)─┐
└─(18:50:16 on master)──> python g910-gkey-uinput.py  
Traceback (most recent call last):
  File "g910-gkey-uinput. py", line 33, in <module>
    binary = f. read (20)
KeyboardInterrupt

Getting this to work on my setup

I've been trying for ages to get my g910 g/m keys to work. This repo seems to handle this issue

Current setup:
Tested with xev/showkey:

  • My g keys are recognized as F keys.
  • My m keys are unresponsive

Edited the file to get this usbcode(or whatever it is ^^):
Device('/sys/devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9:1.1/0003:046D:C32B.000B/hidraw/hidraw1')
Device('/sys/devices/pci0000:00/0000:00:14.0/usb3/3-9/3-9:1.0/0003:046D:C32B.000A/hidraw/hidraw0')

It runs, but neither work. I've unplugged every usb and this is what remains, so I'm 99.99% sure that that is my g910.

I've read here: MatMoul/g810-led#39 that you also use that repo.
Is it neccecary?

If you have time, could you give me a push in the right direction?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.