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

General question: How to get G keys and M keys working #39

Closed
CReimer opened this issue Jan 11, 2017 · 40 comments
Closed

General question: How to get G keys and M keys working #39

CReimer opened this issue Jan 11, 2017 · 40 comments

Comments

@CReimer
Copy link
Contributor

CReimer commented Jan 11, 2017

Is there some Linux tool to make the M and G keys work as they do in Windows or at least something to give them unique events?

@MatMoul
Copy link
Owner

MatMoul commented Jan 12, 2017

At this time, I don't have idea how work G and M keys.

@CReimer
Copy link
Contributor Author

CReimer commented Jan 12, 2017

There's a kernel module for the G710+ keyboard. https://github.com/Wattos/logitech-g710-linux-driver
But I couldn't get it to work by just switching the ids.

It's the only thing I could find which is even remotely related to the G910.

@MatMoul
Copy link
Owner

MatMoul commented Feb 10, 2017

If possible, report to later...

@MatMoul MatMoul closed this as completed Feb 10, 2017
@CReimer
Copy link
Contributor Author

CReimer commented Feb 10, 2017

Sorry. I was busy the last couple of weeks. I made some Wireshark dumps of the M-Keys. Please let me know if this helps. You have to filter to 3.2.0. I don't know if it's possible save with this filter already enabled.

Mkey-Dumps.zip

Filenames are like that. M1-LEDisOff-press.pcapng is a dump of pressing the M1 key while the LED on the key is not on.

The LED switches between the M keys.

The concept behind this is. That you can press MR (MR lights up) press a G-key (MR starts flashing), press any other key to set this G key to the this key and press MR again to save (MR turns off)
M1 to M3 are different profiles.

@CReimer
Copy link
Contributor Author

CReimer commented Feb 11, 2017

BTW: is there any documentation for these protocols? I'd really like to get the M keys and G keys to work properly. But it's difficult for me to find the right place to start understanding the protocol.

@MatMoul
Copy link
Owner

MatMoul commented Feb 11, 2017

I just looked the dumps but I don't see anything, it's not the same format as my dumps...
Because I don't have a g910, it's difficult for me to understand how G and M keys work...
I don't understant what the problem with M and G keys...
Is the led color but it seem that it is not possible to set the color ?
Is the programmation of G keys but I'm not sure is the best app for this ?
Is MR keys or Mx react on press ?
...

is there any documentation for these protocols?

Sorry, It's retro engineer...
But you can look here http://gaming.logitech.com/en-us/developers

@CReimer
Copy link
Contributor Author

CReimer commented Feb 11, 2017

No the M keys don't have a RGB led. It's orange for M1-3 and red for MR
For the key events itself I also think it shouldn't be in g810-led.

The G910 seems to create three devices.

0 Sends key events for G and M keys. But these are not recognized by the Linux kernel.
1 Sends normal keycodes
2 Sends normal keycodes when more than 6 keys are pressed at once.

By default all G keys are mapped to the F keys (G1 -> F1, ...). The Logitech Gaming Software sends some kind of initialization to the keyboard to disable these mapped keycodes, interprets the special key events on the 0 device and translates them for Windows.

@frostworx
Copy link

hi,
today I got my g910. the g810-led project is great, thank you very much for that! (some communication with hyperion would rock :}). I noticed the same wrong behaviour with the G-keys and wonder why this issue was closed.

@MatMoul
Copy link
Owner

MatMoul commented Mar 5, 2017

@frostworx Look the TODO : https://github.com/MatMoul/g810-led/blob/master/TODO.md
I have moved G Keys to "Possible enhancements" because I don't have a G910 and I can not test...
If it's possible to manage G Keys, I need dump or pull request...

@frostworx
Copy link

hi MatMoul, I see. thank you for the quick reply!

@frostworx
Copy link

frostworx commented Mar 6, 2017

hi, me again.
no idea if that would help, but I just dumped one "G5" and one "F5" keypress via wireshark
for comparision. looks like some bits are different, so maybe it is a beginning to remap the G keys (f.e. >=F13). the first two lines of both files were written before the actual keypress and therefore are probably useless white noise. if that helps, I'd be glad to capture the other keys as well of course :)
edit:
sorry, my upload wasn't filtered. reuploading later.
before I'll try to find out if I can build some basic test with something like:
https://julien.danjou.info/blog/2012/logitech-k750-linux-support

new upload - sorry for the noise (again) :}
g5_and_f5_keys_g910.zip

@MatMoul
Copy link
Owner

MatMoul commented Mar 6, 2017

I just looked the dump, it can help me but the best is to make a dump when you set your g keys configuration.
At this time, my code is launched one time and don't stay in memory...
I can only set features but not listen for events.

@CReimer
Copy link
Contributor Author

CReimer commented Mar 6, 2017

I'm not sure if I mentioned this already. But it's acutally the Logitech daemon which handles the key events. If you kill the LGS with the taskmanager the G keys do no longer work.

I suspect it sends some kind of initialization to the keyboard to disable the default behaviour (Gx -> Fx) and that's it. There are special key events for the G keys, but Linux doesn't recognize them on its own. So after we figured out how to disable the default behaviour I can try to build a daemon which redirects the unknown key events to known ones. e.g. F13-F21

@frostworx
Copy link

hi,
unfortunately I do not have any useable windows (vm-)installation, so I can't launch any logitech g-keys configuration (as wine doesn't accept usb devices). by wife has a dual boot laptop, so with some more time I'll take that instead. didn't get very far with both logitech-k750-linux-support and https://github.com/tolga9009/sidewinderd, but I'm not really good in low-level programming so I do not even know if that would be that easy to add 910 support. would love to have it in one application anyway, and as your led control works very nice, I'd prefer that of course :}

@frostworx
Copy link

frostworx commented Mar 6, 2017

hi CReimer (OT: afair I know your avatar from some german vdr threads, but I wasn't very active there, so I might be wrong. for whatever reason I even remember a nickname, but do not call it here, it is not "CReimer" :} - EDIT: googled the nick I rembembered and I was right indeed :}).
yeah, that was my rough idea as well. detect the real G-keys on low level and redirect the (wrong) F1-F9
to zero or some predefined other keys like F13-F21. if we're there everything else should be already doable within userspace. nice to see communication in here btw, so thank you both! :}

@CReimer
Copy link
Contributor Author

CReimer commented Mar 6, 2017

You are right. I'm also active with the same avatar as "Copperhead"

@frostworx
Copy link

hehe, I'm really surprised, why I remembered that, as my last comment was in 2012.
looks like you chose both a memorable nick and avatar

@CReimer
Copy link
Contributor Author

CReimer commented Mar 6, 2017

OK. Here's another dump. This time with Arch Linux and Windows 10 in a VirtualBox. This dump starts with an already running LGS inside the VBox and a device link in Vbox shortly afterwards.

This dump should cover the whole initialization process for the G910

g910_dump_170306.pcapng.zip

@CReimer
Copy link
Contributor Author

CReimer commented Mar 9, 2017

OK. I tried to find my way through these dumps. It's difficult, because I really don't get how these keyboards communicate.
I think I figured out, that all commands to the G910 start with 11:FF:10. What I don't understand is what comes afterwards.

Could you at least try to write a few informations down somewhere to help a newcomer to figure this out? Thanks.

@MatMoul
Copy link
Owner

MatMoul commented Mar 10, 2017

Look at /wireshark_dumps/g810-spectrum/set_keys_colors.pcapng
With this file you can use the next filter in Ŵireshard : usb.dst == "3.2.0" (for your dump, adjust the 3.2.0 value)
My software send data find in URB_CONTROL out, URB setup - Data Fragment
I have found the good data with "Find a packet, HEX value : 00dcff" where 00dcff is the color I have used for my dump

@CReimer
Copy link
Contributor Author

CReimer commented Mar 11, 2017

OK. I'm getting there.
I found out what to send to enable and disable the leds for the M-Keys

11ff091e01000000000000000000000000000000 #M1
11ff091e02000000000000000000000000000000 #M2
11ff091e03000000000000000000000000000000 #M1 M2
11ff091e04000000000000000000000000000000 #M3
11ff091e05000000000000000000000000000000 #M1 M3
11ff091e06000000000000000000000000000000 #M2 M3
11ff091e07000000000000000000000000000000 #M1 M2 M3
11ff091e00000000000000000000000000000000 #M1-3 off
11ff0a0e01000000000000000000000000000000 #MR on
11ff0a0e00000000000000000000000000000000 #MR off

@MatMoul
Copy link
Owner

MatMoul commented Mar 11, 2017

Very interresting...
I reopen issue with enhancement

@MatMoul MatMoul reopened this Mar 11, 2017
@MatMoul
Copy link
Owner

MatMoul commented Mar 11, 2017

Can you try the mkeys branch ?
git clone https://github.com/MatMoul/g810-led.git
cd g810-led
git checkout mkeys
make
sudo make install
and
g910-led -mr 1 # or 0
g910-led -mn 1 # or 0 to 7

@CReimer
Copy link
Contributor Author

CReimer commented Mar 11, 2017

And here are a few more.

11ff082e01 #Disable mapping of G1-9 to F1-9
11ff082e00 #Enable mapping

Your branch is working btw. But wouldn't it be better to set them as they actually are.
Something like -mn 1 2 Enables M1 and M2

The hex value seems to be a reversed three-digit binary number.

0 --> 000 | M3 off | M2 off | M1 off
1 --> 001 | M3 off | M2 off | M1 on
2 --> 010 | M3 off | M2 on | M1 off
3 --> 011 | M3 off | M2 on | M1 on
4 --> 100 | M3 on | M2 off | M1 off
5 --> 101 | M3 on | M2 off | M1 on
6 --> 110 | M3 on | M2 on | M1 off
7 --> 111 | M3 on | M2 on | M1 on

@MatMoul
Copy link
Owner

MatMoul commented Mar 11, 2017

@CReimer Thank you for your return,
For the -mn, I acknoŵledge but need more code... I will work on it...
Can you confirm that -mnn require a commit (-c) to work ?
And for G to F mapping, I try to include it but need a arg name -? and a return if a commit is required

@CReimer
Copy link
Contributor Author

CReimer commented Mar 11, 2017

The m key leds don't need a commit and neither does the G->F mapping

And as argument something like:

--gkey-fkey-mapping Enable or disable the internal mapping of G1-9 to F1-9

@MatMoul
Copy link
Owner

MatMoul commented Mar 11, 2017

--gkey-fkey-mapping can be used if the command is persistant after a shutdown...
If not, is best to use a 2 or 3 char arg for a simple use in profile...
-gkm in relation on the function setGKeysMode

@CReimer
Copy link
Contributor Author

CReimer commented Mar 11, 2017

Sounds good to me. I wasn't aware that you only use the double hyphen arguments for persistent settings.

@MatMoul
Copy link
Owner

MatMoul commented Mar 11, 2017

Can you try the last pushed version with -mr or -mn, I have removed the commit.
-gkm is implemented with no commit but I not sure if is easy to test the result

@CReimer
Copy link
Contributor Author

CReimer commented Mar 11, 2017

All three commands work perfectly.

@MatMoul
Copy link
Owner

MatMoul commented Mar 11, 2017

Thank for your work...
If you want figure in contributor, make a PR with your dump in /wireshark_dumps/g910-spark

MatMoul added a commit that referenced this issue Mar 11, 2017
Add wireshark dump which helped fix #39
@CReimer
Copy link
Contributor Author

CReimer commented Mar 12, 2017

Just a little follow up.
I wrote a small python script which checks for the G and M keys and creates proper events via uinput

https://github.com/CReimer/g910-gkey-uinput

It's nice and small but I would prefer to tell the kernel somehow about these keys. So if anyone finds some information about that. Please let me know.

@MatMoul
Copy link
Owner

MatMoul commented Mar 13, 2017

Good work for you g910-gkey-uinput...

https://github.com/Wattos/logitech-g710-linux-driver seem the best way to start a driver...

I'm also interested to make a driver but It's more hard to debug...

@frostworx
Copy link

thank you both for your good work! unfortunately I do have too many open projects atm to make something useful with the new build. disabling the G keys works fine. Not sure if I get you right, but as this happens in userspace I wonder how a kernel module should remap the unmapped keys afterwards. wouldn't the kernel code depend on the userspace program then?
haven't actually tested the gkey-uinput python code, but will do so for sure later.

@JSubelj
Copy link

JSubelj commented Nov 26, 2018

Hey,
I've written the driver for gkeys in Python. Gkeys can be used to typeout stuff, press a shortcut or run a shell script (the functionality and everything you need should be covered in wiki). You can find the project here:
https://github.com/JSubelj/g910-gkey-macro-support

I would also like to thank @MatMoul for his great controller and everyone here. Your information really helped me.

@cornernote
Copy link
Contributor

@CReimer I'm trying to get M and G keys working on my G815, and I can't seem to find the code to unmap the G keys from the F keys. Are you able to explain what you did while recording to capture that?

@CReimer
Copy link
Contributor Author

CReimer commented Dec 19, 2019

I'm actually Not Sure how exactly I did it (this was 3 years ago). But my uinput Script relies in the g810-led tool. I found this issue #39 with all infos on how we figured it out

@cornernote
Copy link
Contributor

@CReimer #39 is the issue I contacted you from :)

I have tried sending everything the windows software sends on startup to the USB, using this test script:

https://gist.github.com/cornernote/805de3ae9d50922e1769ef78296da60d

Nothing seems to enable the G-Keys :(

I basically got the wireshark dump, extracted everything from the startup before the colour settings, then ran that in a python script.

Is that how you found it?

@CReimer
Copy link
Contributor Author

CReimer commented Dec 26, 2019

@CReimer #39 is the issue I contacted you from :)

Oops

Is that how you found it?

I hacked it into @MatMoul's g810-led. But yes. That's more or less how I figured it out.

The first thing you need to figure out is how to disable the default mapping. I don't expect it to be much different (if at all) from the G910 keyboard.

You need g810-led up and running with the -gkm 1 parameter. This disables the Gx --> Fx mapping. From now on the G-keys send their own keycodes. To make these known to the system, you need the g910-gkey-uinput Python script.

As far as I remember I often watched the wrong device with Wireshark. To work around N-Key-Rollover issues there are two keyboard devices. And the special keys M and G are only available on the second device

@cornernote
Copy link
Contributor

@CReimer I found the code to enable the G-Keys!

I have documented everything here:
https://gist.github.com/cornernote/82972cc307985df29f3ddca214a4dc39

It's also worth linking to the issue for the G815 keyboard - #188

I plan on adding G815 support to sidewinderd for full G-Key support - tolga9009/sidewinderd#40

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

No branches or pull requests

5 participants