creimer / g910-gkey-uinput Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v3.0
License: GNU General Public License v3.0
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```
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
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:
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.