darthaffe / cue.net Goto Github PK
View Code? Open in Web Editor NEWC# (.NET) library to work with the Corsair CUE-SDK.
License: GNU Lesser General Public License v2.1
C# (.NET) library to work with the Corsair CUE-SDK.
License: GNU Lesser General Public License v2.1
I just plugged in a new K70 RGB keyboard and went searching on GitHub for something like this.
What kinds of things would you like to see in this library? Are you going to stick to just wrapping the SDK, or are convenience methods (say, for lighting effects) allowed?
Hello, I am experiencing an issue with the library. For some reason, the CUE SDK does not want to initialize for some users, throwing an exception.
Exception! Message:System.TypeInitializationException: The type initializer for 'CUE.NET.Native._CUESDK' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: ptr
at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(IntPtr ptr, Type t)
at CUE.NET.Native._CUESDK.LoadCUESDK()
at CUE.NET.Native._CUESDK..cctor()
--- End of inner exception stack trace ---
at CUE.NET.Native._CUESDK.CorsairPerformProtocolHandshake()
at CUE.NET.CueSDK.Initialize(Boolean exclusiveAccess)
at Aurora.Devices.Corsair.CorsairDevice.Initialize() in D:\Repositories\Git\Aurora\Project-Aurora\Devices\Corsair\CorsairDevice.cs:line 67
It works fine for me, even on CUE 2's demo devices. While others cannot even get CUE 1 to work.
Here's an issue that a user posted on my project. antonpup/Aurora#333 (comment)
Hello,
I'm having some trouble with the VOID on CUE2. I'm not sure whether it's related to CUE.NET or the native SDK.
The headset doesn't apply the colors it simply turns the LEDs off. When it does apply colors (seemingly at random) it's at a very slow rate
I did some debugging and it turns out it's a combination of not taking exclusive access and updating something else besides the headset.
I made a Gist showing the issue: https://gist.github.com/SpoinkyNL/6a7903f0a61f1c2d5ec24df1e25ac855
If you think it's not a CUE.NET issue I'll make a post on the CUE2 beta forum
While testing I ran into the problem of stalling the keyboard by completely flashing it every 20ms.
The problem occurred reproducible after round 20 seconds.
Create a post in the corsair forum and ask about limitations (buffers, update rates, etc.) and add some logic to the keyboard to slow down updates if they are about to pass limits.
Specifically when generating a one click installer but I assume the same for others too.
Hi,
i wanted to know if it is possible to tell CUE.NET where to load its native? wrapper from? I am talking about the dll in the "x86" and "x64" folder.
I am developing a Plugin for a music player which loads its plugins from a specified folder. And Plugins should only be installed in that folder. But with the current CUE.NET this is not possible because of the loading of this dll that has to reside in the same folder as the main application.
Another problem arises when the Player is started by another program. For example via the "Launch Application" macro in CUE itself. If that happens, CUE.NET searches for the dll in the CUE folder instead of the one of the started application.
PS: I am pretty new to C# (this is my first project) and don`t know much about how the loading of libraries works, so if I'am missing a basic functionality here please point me in the right direction
hello,
how do i use the FlashEffect correct?
FlashEffect testeffect = new FlashEffect(Color.Blue);
testeffect.Repetitions = 100;
keyboard.AttachEffect(testeffect);
keyboard.Update();
the keyboard light up all leds with blue, but just one time. there is no flash effect.
how do i handle the effect update correctly?
btw: thx, for this nice work!
Hey, I was wondering if it's possible to do this. It would be even better to have a way to check each SDK.
Something like IsSdkAvailable() , IsKeyboardSdkAvailable() etc. etc.
I don't think the native C++ sdk provides a feasible way to do this, I could always ask the guys at Corsair, so please let me know what you think :)
If there's a macro running while Initialize/Reinitialize is called, then the macro will be interrupted. Ran into this issue when trying to workaround losing CUE connection on wake up.
Corsair ticket 6778416, it might be their issue.
For example, dynamically let someone turn off the effects on the keyboard without closing a program.
CueSDK.Disconnect() or something
Hey,
The new K95 Platinum features a lightbar. I was hoping it woulk show up as a LED zone but it doesn't. The regular keys work out of the box.
This leaves me with colored keys but the lightbar sticking to whatever CUE is setting it to (animations stay in tact)
We'll probably have to wait for an SDK update but from what I can gather the dev of Corsair Effect Engine found a way to talk to the light bar, she's also using CUE.NET
Some users of my app, which implements CUE.NET have been reporting some strange behaviour which I have been unable to replicate myself and I was wondering if you might know where to point me in the right direction.
My app uses CUE.NET to set lighting for Corsair devices across specific keys, however what seems to be happening is when an end-user has a device which is missing certain keys (For example a Strafe RGB does not have physical macro buttons like the K95 RGB), the program throws a null reference error, which my program catches (and reports) but this also locks up CUE.NET so the app must be restarted before Corsair lighting functions again.
Now this has been difficult for me to replicate since I use the CUE2 emulators to test my corsair implementation and for the keyboard, it emulates a K95 RGB which does indeed have macro buttons on it.
Assuming the issue is relating to my code trying to poll/set keys which don't exist on the connected physical device; I think I could potentially work around this by polling the device model using CUE.NET and then avoid setting missing keys programatically, however I was wondering if there is code I'm missing, or can be implemented so if a key is set/polled which doesn't exist on a physical device, if CUE.NET can handle this?
Sorry if I'm making it hard to understand, wording this issue has proven to be a bit more difficult than I expected.. so if you would like me to clarify anything please let me know.
CUESDK.x64_2013.dll cannot be referenced, make sure it is a valid assembly, or COM file.
Hi first of all i am a beginner!
I am getting 404 error trying installing from nuget package manager, i have tried with myget feed and nuget repository. In the other hand i cant install manually cause i know how to add dll's as reference but i dont know how to create a post-built event.
Thx !
This is most likely due to new paths and maybe even new configs.
It's still incomplete - effects aren't documented ...
This will make #12 much easier.
I wrote the below C# using CUE.NET 0.1.0-CI00011. Notice that the model came back as Chinese characters rather than the expected "K95 RGB". I then wrote a quick c++ console app with the below lines and the Model is successfully return as well as the correct enumerations for the other values.
C#
CorsairKeyboard keyboard = CueSDK.KeyboardSDK;
if (keyboard == null)
throw new WrapperException("No Keyboard Found!");
txtbxModel.Text = keyboard.KeyboardDeviceInfo.Model.ToString();
txtbxType.Text = keyboard.KeyboardDeviceInfo.Type.ToString();
txtbxPhysLayout.Text = keyboard.KeyboardDeviceInfo.PhysicalLayout.ToString();
txtbxLogicalLayout.Text = keyboard.KeyboardDeviceInfo.LogicalLayout.ToString();
txtbxCapabilites.Text = keyboard.KeyboardDeviceInfo.CapsMask.ToString();
C++
// I only have 1 device so just passing devicecount -1 (essentially 0)/
const auto KBInfo = CorsairGetDeviceInfo(CorsairGetDeviceCount() -1);
std::cout << (*KBInfo).model << std::endl;
std::cout << (*KBInfo).logicalLayout << std::endl;
std::cout << (*KBInfo).physicalLayout << std::endl;
std::cout << (*KBInfo).capsMask << std::endl;
std::cout << (*KBInfo).type << std::endl;
Hello, I am wondering if it would be possible to include a Shutdown function, in the event where the app does not need CUE SDK lighting, to allow CUE itself to take over with lighting profiles. And then at a later point reinitialize again, if CUE SDK lighting is needed.
Because at the moment, you can only CueSDK.Initialize();
and CueSDK.Reinitialize();
I have the keyboard SDK initialized and running in continuous update mode with a handful of keys lit. (ListLedGroup, SolidColorBrush, custom AbstractBrushEffect) The effect will modify the brush color when the key is pressed.
When the PC is locked the entire keyboard changes to the profile stored on the chip. This is expected. However, when the PC is unlocked, the entire keyboard returns to the color configured in CUE and my lighting no longer appears. Sometimes pressing the keys will bring all my lighting back, but sometimes it never comes back (unclear what the difference is here). I have attempted to call CueSDK.ReInitialize after unlock (via SystemEvents.SessionSwitch event) but it returns the error...
"CUE.NET.Exceptions.WrapperException: 'The previously loaded Keyboard got disconnected.'"
...even if I make sure CueSDK.IsSDKAvailable(CorsairDeviceType.Keyboard) is true first.
Could you please explain the correct way (or add an example) to show how to ensure the lighting applied by CUE.NET will always reappear correctly after a PC is unlocked.
I'm using Win 10, VS 2017, .NET 4.5.
Just made a small app with CUE.net. Was thinking it would be nice if you had a page that listed open source projects that use CUE.net to demonstrate it abilities. Maybe in the Wiki?
Thanks again!
Since I can't test more than my keyboard I'll ask @SpoinkyNL to do this.
The test is quite simple:
Get the latest version of the development branch and run the SimpleDevTest.
It should draw an rainbow on all connected devices (this might look not that good on mouse and headset, mousemat should be ok i think).
The rainbow is lacking red (RemoveRedEffect), should pulse slowly (FlashEffect) and change colors over time (MoveRainbowEffect).
Of course it would be great if you could test it inside artemis too, but since this version contains a huge amount of breaking changes I'm not sure if it can just dropped in without adaptation in artemis.
First thanks for all your work on this. Its really great! I have a question about how to turn off an LED through keygroups. I know how to add and remove keys from a keygroup, but only the add functionality seems to work as I expect it.
ListKeyGroup keyGroup = new ListKeyGroup(keyboard, keyboard['R'].KeyId);
keyGroup.Brush = new SolidColorBrush(Color.White);
keyboard.Update();
Wait(2);
keyGroup.RemoveKey(keyboard['R'].KeyId);
keyGroup.AddKey(keyboard['T'].KeyId);
It seems after this code is executed that R and T are both still lit up white, even though I am attempting to remove R. Do I have to specifically overwrite the R to black or no color or something?
This might be useless until corsair adds "real" key events (including G-Keys)
Hey there,
Not an issue, just very lost at the moment.
I'm trying to develop more of a script per se, where I pass in the color I want (going to be via voice) to the application parameters and then change the keyboard LEDs based on that parameter. However, once the program is run, the LEDs change for 0.5s of a second and then goes back to my default profile in Corsair's CUE.
Is it possible to keep the changes that I've made in my console application after the program has stopped running?
Any help would be greatly appreciated!
Hello, and thank you for writing this library! I've been looking for something like this for a small while and this is the only thing that came up on NuGet. But, I've been having a couple of issues with it.
Whenever I try to poll the LEDs, they come up stark white. Using a foreach loop to check both LED's RGBA values, it comes up (R,G,B,A) 255, 255, 255, 0. Headset color isn't that important to me, so I'm not worried about that.
What I am requesting however, is the ability to get the headset's battery level. Sometimes CUE does not behave and refuses to open the main window, so I occasionally have no way to check my charge. Is it possible for you to add that to this library?
Create a brush-base-class containing a method to calculate an "overall" alpha and brightness value over the color calculated by the underlying brush.
TBD: Should this method be forcefully applied or should every brush respect this by convention?
I'm honestly not sure if I'll do this. On first sight it seems to be really complicated without adding functionality that isn't already implemented or easy to add in CUE.NET. But I'll investigate it further before finally deciding.
I'm currently struggling to get MSBuild to copy the x64 CUE DLL into the correct location on build. Perhaps a NuGet package would make this easier?
It appears that CUE.NET.CueSDK.EnableKeypressCallback
does not check to see if the keypress handler mechanism is already enabled. As such, calling EnableKeypressCallback
causes two separate callback functions to be run whenever a key is pressed, resulting in duplicate events. Moreover, the first copy of the delegate goes out of scope, causing the first function pointer to throw a NullReferenceException
when invoked.
A simple test case (in PowerShell) is as follows:
# Uncomment the line below if CUE.NET is not already installed system-wide
# Install-Package CUE.NET -Force
Get-Package CUE.NET -ProviderName NuGet | % Source | Split-Path -Parent | Push-Location
Add-Type -Path .\lib\net45\CUE.NET.dll
[CUE.NET.CueSDK]::PossibleX64NativePaths.Add((Resolve-Path .\build\net45\libs\x64\CUESDK_2015.dll))
[CUE.NET.CueSDK]::PossibleX86NativePaths.Add((Resolve-Path .\build\net45\libs\x86\CUESDK_2015.dll))
[CUE.NET.CueSDK]::Initialize()
Pop-Location
Register-ObjectEvent -InputObject ([cue.net.cuesdk]) -EventName KeyPressed -Action {
Write-Warning "$($EventArgs.KeyId) was $(If ($EventArgs.isPressed) {"Pressed"} Else {"Released"})"
} | sv listener
[CUE.NET.CueSDK]::EnableKeypressCallback()
# Push some G/M-keys - Warning records should be written to the console
[CUE.NET.CueSDK]::EnableKeypressCallback()
# Push some more G/M-keys - Warning records will still be written, but now in duplicate
[GC]::Collect() # force garbage collection
# Push another G/M-key - PowerShell will throw a NullReferenceException and crash
Radial should be easy, image seems to be a bit tricky and random colors are cool.
Think about some more ...
I am experiencing an issue where I cannot set color for some keys on a Corsair Strafe RGB and I cannot change the color of the DPI indicator on Corsair Sabre RGB. I am able to change color of other lights on both the keyboard and mouse, but not the Windows Lock, Brightness, and mouse DPI lights.
//Do not work, keys stay black.
keyboard[CorsairKeyboardKeyId.Brightness].Led.Color = color;
keyboard[CorsairKeyboardKeyId.WinLock].Led.Color = color;
Is this an issue with CUE or on my end?
Hi there,
I'm trying to integrate this library into my application however I've been having quite a bit of trouble. I'm pretty sure I've got the initialization working correctly but the trouble is in sending a color to all keys of all devices/keyboards. I've been trying to use the code:
RectangleKeyGroup yellowGroup = new RectangleKeyGroup(corKeyboard, CorsairKeyboardKeyId.D1, CorsairKeyboardKeyId.D0)
{ Brush = new SolidColorBrush(System.Drawing.Color.Yellow) };
corKeyboard.Update();
yellowGroup.Detach();
taken from your example application source but nothing happens at all and i just get object exception errors all round.
The above code is just doing KeyID D1 through D0 but I've been trying to set the whole keyboard as well to a color without any success.
Any help would be much appreciated
Hi there,
I am encountering some weird behaviour with this library when performing multiple calls which involves brushes and LED groups. Basically what is happening is after about 5 seconds of running my program, I start to see a gradual rise in memory usage which continues to rise, which indicates a memory leak. This doesn't happen when i bypass the Corsair SDK however.
It's worth noting that the code does actually work and updates all the LED's correctly, but the constant build in memory is obviously not good.
A basic extract of the code I'm using is as follows:
private ListLedGroup _CorsairAllKeyboardLED = new ListLedGroup(CueSDK.KeyboardSDK, CueSDK.KeyboardSDK);
//is called regularly from a different function, as the update functions are called multiple times for different keys before and update needs to be made.
public void CorsairUpdateLED()
{
if (CorsairSDK != false)
{
CueSDK.HeadsetSDK.Update();
CueSDK.KeyboardSDK.Update();
CueSDK.MouseSDK.Update();
CueSDK.MousematSDK.Update();
}
}
//Update all keys on a device
public void CorsairUpdateAll(System.Drawing.Color col)
{
if (CorsairDeviceMouse == true)
{
_CorsairAllMouseLED = new ListLedGroup(CueSDK.MouseSDK, CueSDK.MouseSDK);
CueSDK.MouseSDK.Brush = (SolidColorBrush)col;
_CorsairAllMouseLED .Brush = _CorsairAllLEDBrush;
_CorsairAllMouseLED .ZIndex = 1;
}
if (CorsairDeviceKeyboard == true && disablekeys != true)
{
CueSDK.KeyboardSDK.Brush = (SolidColorBrush)col;
_CorsairAllKeyboardLED.Brush = _CorsairAllLEDBrush;
_CorsairAllKeyboardLED.ZIndex = 1;
}
}
//Update a specific LED on the keyboard
public void CorsairApplyMapKeyLighting(string key, System.Drawing.Color col)
{
if (CorsairSDK != false)
{
//Send Lighting
if (CorsairDeviceKeyboard == true)
{
try
{
if (Corsairkeyids.ContainsKey(key))
{
ListLedGroup _CorsairKeyboardIndvLED = new ListLedGroup(CueSDK.KeyboardSDK);
SolidColorBrush _CorsairLEDBrush = new SolidColorBrush(col);
_CorsairKeyboardIndvLED.AddLed(Corsairkeyids[key]);
_CorsairKeyboardIndvLED.ZIndex = 10;
_CorsairKeyboardIndvLED.Brush = _CorsairLEDBrush;
}
}
catch (Exception ex) { }
}
}
}
I've done a bit of debugging and can see by taking multiple memory snapshots and comparing them, that the issue may be resulting from the CueSDK, I have attached a screenshot of the memory snapshot comparison as reference.
Have I just implemented the SDK wrong in my code which is causing a memory leak or is there something more going on here do you think?
Any help would be greatly appreciated.
I tried to initialize the SDK in a C# UWP project, it threw a WrapperException:
Exception thrown: 'CUE.NET.Exceptions.WrapperException' in CUE.NET.dll
My code is as follows:
public MainPage()
{
InitializeComponent();
try
{
CueSDK.Initialize();
Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK");
CorsairKeyboard keyboard = CueSDK.KeyboardSDK;
if (keyboard == null)
throw new WrapperException("No keyboard found");
var ledGroup = new ListLedGroup(keyboard);
ledGroup.AddLed(CorsairLedId.Lightbar1);
ledGroup.AddLed(CorsairLedId.Lightbar2);
ledGroup.AddLed(CorsairLedId.Lightbar3);
ledGroup.AddLed(CorsairLedId.Lightbar4);
ledGroup.AddLed(CorsairLedId.Lightbar5);
ledGroup.AddLed(CorsairLedId.Lightbar6);
ledGroup.AddLed(CorsairLedId.Lightbar7);
ledGroup.AddLed(CorsairLedId.Lightbar8);
ledGroup.AddLed(CorsairLedId.Lightbar9);
ledGroup.AddLed(CorsairLedId.Lightbar10);
ledGroup.AddLed(CorsairLedId.Lightbar11);
ledGroup.AddLed(CorsairLedId.Lightbar12);
ledGroup.AddLed(CorsairLedId.Lightbar13);
ledGroup.AddLed(CorsairLedId.Lightbar14);
ledGroup.AddLed(CorsairLedId.Lightbar15);
ledGroup.AddLed(CorsairLedId.Lightbar16);
ledGroup.AddLed(CorsairLedId.Lightbar17);
ledGroup.AddLed(CorsairLedId.Lightbar18);
ledGroup.AddLed(CorsairLedId.Lightbar19);
Console.WriteLine($"{ledGroup.GetLeds().Count()} LEDs in group");
ledGroup.Brush = new SolidColorBrush((Color)Resources["SystemAccentColor"]);
ledGroup.Device.Update();
}
catch (CUEException ex)
{
Console.WriteLine("CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error));
}
catch (WrapperException ex)
{
Console.WriteLine("Wrapper Exception! Message:" + ex.Message);
}
}
not so fun ...
Hey,
I was wondering if it's at all possible to get the position of a key, preferably in X/Y coordinates?
For Logitech I just made a KeyMap (like so: https://github.com/SpoinkyNL/Artemis/blob/master/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyMap.cs)
I dunno if CUE offers an easier way to do this, if not I don't expect you to go through the boring process of making a map, just wondering :)
For example,
if(someValue)
{
SetProfile(myCustomCUEProfile);
}
Updating individual colors is broken because of
c4ac6f0#diff-caac9f90950af58ae566e770d533738aR209
ApplyColorData(_colorDataSave) overwriting the LedMapping's state no matter what.
Tested using Corsair k70 RGB.
Workaround: apply a brush before updating individual key colors.
Do you think this can be done? I currently use
foreach (var item in _keyboard.Keys)
{
item.Led.Color = bitmapImage.GetPixel((int) item.KeyRectangle.X, (int) item.KeyRectangle.Y);
}
but it can take up to 200MB of memory.
First of all create a concept for this :p
This seems to be caused by the new Keypress-Callback.
An exception while drawing a brush should not crash the application.
Check for more possible problems and add solid exception handling to everything.
I have a K70 LUX RGB, and am trying to build a WinForms app using the CUE.NET SDK. I currently have CUE 2 installed.
The following code is how i am setting the keyboard
private CorsairKeyboard keyboardDevice;
if(!CueSDK.IsInitialized)
{
CueSDK.Initialize(false); // initialize with non exclusive access
}
keyboardDevice = CueSDK.KeyboardSDK;
this.keyboardDevice[CorsairKeyboardLedId.F1].Color = Color.Red;
this.keyboardDevice.Update(); // update but do not flush
Whenever i set the key to red, the entire keyboard goes to white except for the key i set to red. I only have the keyboard, so not sure what else i can test.
Edit: just calling update without setting any of the other colors also makes the keys go white.
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.