The Corsair User Forums

The Corsair User Forums (https://forum.corsair.com/forums/index.php)
-   CUE 1.x and 2.x SDK (https://forum.corsair.com/forums/forumdisplay.php?f=271)
-   -   How to get K95's G key presses through USB without CUE software? (https://forum.corsair.com/forums/showthread.php?t=172374)

ygolohcisp 11-15-2017 07:16 AM

How to get K95's G key presses through USB without CUE software?
 
How can I get the K95's G key presses through USB without CUE software?

The K95 shows up as these HID devices:
Code:

ID 1b1c:1b11 \\?\hid#vid_1b1c&pid_1b11&mi_01&col01#8&2dd5e1ac&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} Corsair K95 RGB Gaming Keyboard
ID 1b1c:1b11 \\?\hid#vid_1b1c&pid_1b11&mi_01&col02#8&2dd5e1ac&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030} Corsair K95 RGB Gaming Keyboard
ID 1b1c:1b11 \\?\hid#vid_1b1c&pid_1b11&mi_01&col03#8&2dd5e1ac&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030} Corsair K95 RGB Gaming Keyboard
ID 1b1c:1b11 \\?\hid#vid_1b1c&pid_1b11&mi_01&col04#8&2dd5e1ac&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030} Corsair K95 RGB Gaming Keyboard
ID 1b1c:1b11 \\?\hid#vid_1b1c&pid_1b11&mi_02#8&9fea3ea&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} Corsair K95 RGB Gaming Keyboard
ID 1b1c:1b11 \\?\hid#vid_1b1c&pid_1b11&mi_00#8&16125567&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} Corsair K95 RGB Gaming Keyboard

But when I try to open any one of these for reading, I get an error.

What's the correct way to read from it to get the G key presses? And which of these HID devices is used for them?

I'm already successfully sending the LED data via libusb but now I still need to get G key presses. They are sent via normal HID, right?

Darth Affe 11-15-2017 12:51 PM

Yes, it is possible to read the keys from the hid-device. If you read from the one with "col03" with a buffer size of 64 it should be working.
I tried around with this a while ago and got some working (C#) code here.

ygolohcisp 11-16-2017 05:57 PM

I tried that but it's not working. I can't open the HID device with this hidapi lib.

Apparently Windows doesn't allow to open keyboards/mice for security reasons:
https://github.com/signal11/hidapi/i...ment-345071855

But isn't your C# program running in userspace, not as a driver in kernel space?

ygolohcisp 11-16-2017 07:06 PM

I captured these packets with wireshark/UsbPcap when pressing and releasing each G key one after another (G1 to G18).
The key release packets all look the same (not key specific) for some reason, only the keypress packets are key-specific..

https://image.prntscr.com/image/zPDf...9OGcpW9niw.png

So I have to use 0x82 for wIndex, but what should I use for bmRequestType, bRequest and wValue when calling libusb_control_transfer()?
http://libusb.sourceforge.net/api-1....a07f4568d56f38

Darth Affe 11-17-2017 06:59 AM

Quote:

Originally Posted by ygolohcisp (Post 926589)
I tried that but it's not working. I can't open the HID device with this hidapi lib.

Apparently Windows doesn't allow to open keyboards/mice for security reasons:
https://github.com/signal11/hidapi/i...ment-345071855

But isn't your C# program running in userspace, not as a driver in kernel space?

Yes it is running in userspace. I've no idea how windows 8 handles such things but for me (win 7) it works fine, and as far as i know on win 10 it works too.


Quote:

Originally Posted by ygolohcisp (Post 926589)
The key release packets all look the same (not key specific) for some reason, only the keypress packets are key-specific..

Yes, this is expected. The keyboard always sends data containing isPressed-flags for every key. Therefore after releasing a key (if you only pressed one) it's always 0 only. if you press multiple keys and release one you'll still see the remaining ones as 1.
That's what is parsed here:
https://github.com/DarthAffe/CUE.NET...ceInput.cs#L90


Quote:

Originally Posted by ygolohcisp (Post 926589)
So I have to use 0x82 for wIndex, but what should I use for bmRequestType, bRequest and wValue when calling libusb_control_transfer()?

Sorry i can't help with that. I've no idea how that lowlevel usb-libraries work.

ygolohcisp 11-23-2017 01:24 PM

Thanks for explaining the keypress msgs.

I also tried with the hidapi lib again, but apparently userspace programs on Windows are not allowed (by the OS) to read HID devices that are keyboards or mice, for security reasons:
https://github.com/signal11/hidapi/i...ment-161152387

So how did you get your program to open the keyboard's HID device while running in userspace (without having to override the Corsair HID driver)? :)

Darth Affe 11-23-2017 02:40 PM

1 Attachment(s)
Quote:

Originally Posted by ygolohcisp (Post 927471)
So how did you get your program to open the keyboard's HID device while running in userspace (without having to override the Corsair HID driver)? :)

I've no idea. Like I said this might be a win 8 issue.
The only thing I can do to help with this is to give you the application I used to test back when I worked with this. I works 100% for me (just tested it again). If it doesn't work for you it's likely a os problem, if it does you're doing something wrong :p

Just run it, open a notepad and press some keys. It should light up the pressed keys on the keyboard. (Don't press keys in the console-window of the application except you want to close it.)

ygolohcisp 12-06-2017 10:00 AM

For me InputTest.exe crashes at start with an exception, even after I installed .NET and the VC++ redistributable :(

hastegag 12-10-2017 10:57 PM

Quote:

Originally Posted by ygolohcisp (Post 929322)
For me InputTest.exe crashes at start with an exception, even after I installed .NET and the VC++ redistributable :(

This has been on my back burner, but I've been dying to try it

just tried it and it works on win10x64, but again as he said, you need to be inside a notepad. I had 2.20.xxx installed with the SDK enabled.

If i was outside of notepad and hit the G keys it does not necessarily work and may crash, but ultimately, i know this is going to be a cool thing...I'm excited to look at how Darth Affe set this up and go from there

ygolohcisp 12-12-2017 05:25 PM

How did you get it to work instead of throw an exception?

I got the exception right after starting it on the command line.

Before I could even run it, I had to install .Net and VC++ redistributable because of msvcp140.dll, what else is missing?

ygolohcisp 12-13-2017 06:09 PM

Quote:

Originally Posted by Darth Affe (Post 927483)
The only thing I can do to help with this is to give you the application I used to test back when I worked with this. I works 100% for me (just tested it again). If it doesn't work for you it's likely a os problem, if it does you're doing something wrong :p

Could you maybe upload the source of InputTest.exe somewhere so I can translate it into the language I'm using and try if that works? :)
I'd really appreciate it.

Darth Affe 12-16-2017 03:14 AM

Just take the example project in the repo: https://github.com/DarthAffe/CUE.NET.../SimpleDevTest

hastegag 12-16-2017 06:13 PM

Quote:

Originally Posted by ygolohcisp (Post 930418)
Could you maybe upload the source of InputTest.exe somewhere so I can translate it into the language I'm using and try if that works? :)
I'd really appreciate it.

hey did you run it with CUE running and FULLY Loaded up? I tried again without cue running, got an exception in the command line. I tried running after running CUE but before loading all the devices and got a different error.

Maybe just try again? I am going to try to take a closer look at what this code does and see if I can extrapolate for my purposes. I really just was looking for a way to fill in the gaps with CUE, like decision making macros on the Gkeys that can in and of themselves test for modifiers being pressed or something else happening at the same time to make them context sensitive/intelligent. Right now I have to often remap these G keys to an autohotkey recognizable key which limits my other possibilities on the keyboard at the same time (there are only so many Fkeys and in photoshop for example you have to sort of reserve fkeys and modifier states for actions - it gets crowded quickly).

I think this would be the fix, bc there is clearly a way to see when the G keys are depressed...and he showed us how so i can go from here.

Darth Affe 12-17-2017 04:29 AM

If you only need the G-keys you can use the original SDK or CUE.NET since there is an event for them for a few weeks now.

hastegag 12-17-2017 01:04 PM

Quote:

Originally Posted by Darth Affe (Post 930881)
If you only need the G-keys you can use the original SDK or CUE.NET since there is an event for them for a few weeks now.

I think I will try that. I did download your repository last night for InputTest / SimpleDevTest and got it to compile after some fiddling on Visual Studio 2017, I had to comment out a couple lines and I didn't get too far.

It asked me to use the more modern .net targets which seemed to work finally when i opened the input project before the simple dev test. It wasn't getting where the namespace came from for CUE.Net.Input. The .net4.5 targets lower than version 4.5.2 don't seem to be able to be installed in VS Community '17, but it seems to play ok with the newer version.


In the meantime, while I will definitely look into the Cue.net original SDK, i am going to hotfix this for myself a different route by making 18 executables in AHK that are linked to in CUE on each G key. The script/exe polls for whether a modifier key is pressed at execution and save out the keystate into an ini and i can read that back in with my primary script. Tricky part is telling Script 1 when to update and fire a hotkey. I suppose I could poll every second or so the same ini file for state changes and erase it after each iteration, but that is slow and even on an nvme its probably not a great method. I'm probably going to see if i can just save the keystate in memory someplace and read it back in periodically (which is i am sure less taxing on the system and should be faster).

Obviously this is hacky and not the best approach, I am sure the SDK will prove to be a better method.


All times are GMT -4. The time now is 04:42 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.