public static ListKeyGroup ToSimpleKeyGroup(this BaseKeyGroup keyGroup) { ListKeyGroup simpleKeyGroup = keyGroup as ListKeyGroup; if (simpleKeyGroup == null) { bool wasAttached = keyGroup.Detach(); simpleKeyGroup = new ListKeyGroup(keyGroup.Keyboard, wasAttached, keyGroup.Keys.ToArray()) { Brush = keyGroup.Brush }; } return simpleKeyGroup; }
public static void Main(string[] args) { Console.WriteLine("Press any key to exit ..."); Console.WriteLine(); Task.Factory.StartNew( () => { Console.ReadKey(); Environment.Exit(0); }); try { // Initialize CUE-SDK CueSDK.Initialize(); Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK"); // Get connected keyboard or throw exception if there is no light controllable keyboard connected CorsairKeyboard keyboard = CueSDK.KeyboardSDK; if (keyboard == null) throw new WrapperException("No keyboard found"); // --------------------------------------------------------------------------- // First we'll look at some basic coloring Console.WriteLine("Basic color-test ..."); // Ink all numbers on the keypad except the '5' purple, we want that to be gray ListKeyGroup purpleGroup = new RectangleKeyGroup(keyboard, CorsairKeyboardKeyId.Keypad7, CorsairKeyboardKeyId.Keypad3) { Brush = new SolidColorBrush(Color.Purple) } .Exclude(CorsairKeyboardKeyId.Keypad5); keyboard[CorsairKeyboardKeyId.Keypad5].Led.Color = Color.Gray; // Ink the Keys 'r', 'g', 'b' in their respective color // The char access fails for everything except letters (SDK doesn't return a valid keyId) keyboard['R'].Led.Color = Color.Red; keyboard[CorsairKeyboardKeyId.G].Led.Color = Color.Green; keyboard['B'].Led.Color = Color.Blue; // Lock the 'r', 'g', 'b' keys. We want them to stay like this forever (commented since it looks quite stupid later, but feel free tu uncomment this) //keyboard['R'].Led.IsLocked = true; //keyboard['G'].Led.IsLocked = true; //keyboard['B'].Led.IsLocked = true; // Ink the letters of 'white' white ListKeyGroup whiteGroup = new ListKeyGroup(keyboard, CorsairKeyboardKeyId.W, CorsairKeyboardKeyId.H, CorsairKeyboardKeyId.I, CorsairKeyboardKeyId.T, CorsairKeyboardKeyId.E) { Brush = new SolidColorBrush(Color.White) }; // Ink the keys '1' to '0' yellow RectangleKeyGroup yellowGroup = new RectangleKeyGroup(keyboard, CorsairKeyboardKeyId.D1, CorsairKeyboardKeyId.D0) { Brush = new SolidColorBrush(Color.Yellow) }; // Update the keyboard to show the configured colors, (your CUE settings defines the rest) keyboard.Update(); Wait(3); // Remove all the groups we created above to clear the keyboard purpleGroup.Detach(); whiteGroup.Detach(); yellowGroup.Detach(); // --------------------------------------------------------------------------- // Next we add a nice linear gradient brush over the keyboard and play around with the offset of one stop Console.WriteLine("gradient-brush-test"); // Create our gradient stop to play with GradientStop moveableStop = new GradientStop(0, Color.FromArgb(0, 255, 0)); // Create a basic (by default horizontal) brush ... LinearGradientBrush linearBrush = new LinearGradientBrush(new LinearGradient(new GradientStop(0, Color.Blue), moveableStop, new GradientStop(1f, Color.White))); // ... and add it as the keyboard background keyboard.Brush = linearBrush; // Move the brush from left to right for (float offset = 0; offset <= 1f; offset += 0.02f) { moveableStop.Offset = offset; keyboard.Update(); Thread.Sleep(100); } // And back to center for (float offset = 1f; offset >= 0.5f; offset -= 0.02f) { moveableStop.Offset = offset; keyboard.Update(); Thread.Sleep(100); } // "Rotate" the brush (this is of course not the best implementation for this but you see the point) for (float rotateX = 0, rotateY = 0; rotateX <= 1f; rotateX += 0.02f, rotateY = 0.04f) { if (rotateY > 1f) rotateY = 1f - (rotateY - 1f); linearBrush.StartPoint = new PointF(rotateX, rotateY); linearBrush.EndPoint = new PointF(1f - rotateX, 1f - rotateY); keyboard.Update(); Thread.Sleep(100); } Wait(2); // --------------------------------------------------------------------------- // Time for an even better brush: rainbow Console.WriteLine("rainbow-test"); // Create an simple horizontal rainbow containing two times the full spectrum RainbowGradient rainbowGradient = new RainbowGradient(0, 720); // Add the rainbow to the keyboard and perform an initial update keyboard.Brush = new LinearGradientBrush(rainbowGradient); keyboard.Update(); // Let the rainbow move around for 10 secs for (int i = 0; i < 100; i++) { rainbowGradient.StartHue += 10f; rainbowGradient.EndHue += 10f; keyboard.Update(); Thread.Sleep(100); } Wait(2); // --------------------------------------------------------------------------- // Now let us move some points random over the keyboard // Something like this could become some sort of effect // Initialize needed stuff const float SPEED = 6f; // mm/tick Random random = new Random(); // Flash whole keyboard three times to ... well ... just to make it happen for (int i = 0; i < 3; i++) { keyboard.Brush = new SolidColorBrush(Color.Aquamarine); keyboard.Update(); Thread.Sleep(160); keyboard.Brush = new SolidColorBrush(Color.Black); keyboard.Update(); Thread.Sleep(200); } // Set keyboard 'background' to black with low alpha (this will add a nice "fade" effect instead of just clearing the keyboard every frame) keyboard.Brush = new SolidColorBrush(Color.FromArgb(25, 0, 0, 0)); // Define how many points we have const int NUM_POINTS = 6; // The points we want to draw (rectangle since circles are too hard to calculate :p) RectangleF[] points = new RectangleF[NUM_POINTS]; // KeyGroups which represents our point on the keyboard RectangleKeyGroup[] pointGroups = new RectangleKeyGroup[NUM_POINTS]; // Target of our movement PointF[] targets = new PointF[NUM_POINTS]; // Initialize all the stuff for (int i = 0; i < NUM_POINTS; i++) { // Spawn our point in the top-left corner (right over G1 or on ESC depending on your keyboard) points[i] = new RectangleF(keyboard.KeyboardRectangle.X, keyboard.KeyboardRectangle.Y, 60, 60); pointGroups[i] = new RectangleKeyGroup(keyboard, points[i], 0.1f) { Brush = new SolidColorBrush(Color.White) }; targets[i] = new PointF(points[i].X, points[i].Y); } // We set colors manually since white points are kinda boring (notice, that we use alpha values) pointGroups[0].Brush = new SolidColorBrush(Color.FromArgb(127, 255, 0, 0)); pointGroups[1].Brush = new SolidColorBrush(Color.FromArgb(127, 0, 255, 0)); pointGroups[2].Brush = new SolidColorBrush(Color.FromArgb(127, 0, 0, 255)); pointGroups[3].Brush = new SolidColorBrush(Color.FromArgb(127, 255, 0, 255)); pointGroups[4].Brush = new SolidColorBrush(Color.FromArgb(127, 255, 255, 0)); pointGroups[5].Brush = new SolidColorBrush(Color.FromArgb(127, 0, 255, 255)); while (true) { // Calculate all the points for (int i = 0; i < NUM_POINTS; i++) { // Choose new target if we arrived if (points[i].Contains(targets[i])) targets[i] = new PointF((float)(keyboard.KeyboardRectangle.X + (random.NextDouble() * keyboard.KeyboardRectangle.Width)), (float)(keyboard.KeyboardRectangle.Y + (random.NextDouble() * keyboard.KeyboardRectangle.Height))); else // Calculate movement points[i].Location = Interpolate(points[i].Location, targets[i], SPEED); // It would be better to calculate from the center of our rectangle but the easy way is enough here // Move our rectangle to the new position pointGroups[i].Rectangle = points[i]; } // Update changed leds keyboard.Update(); // 20 updates per sec should be enought for this Thread.Sleep(50); } } catch (CUEException ex) { Console.WriteLine("CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error)); } catch (WrapperException ex) { Console.WriteLine("Wrapper Exception! Message:" + ex.Message); } catch (Exception ex) { Console.WriteLine("Exception! Message:" + ex.Message); } while (true) Thread.Sleep(1000); // Don't exit after exception }
/// <summary> /// Intial setup of keygroups using the keyboard provided. /// </summary> /// <param name="keyboard"></param> /// <param name="useNumpad"></param> public static void setupKeyGroups(CorsairKeyboard keyboard, bool useNumpad) { try { WASD = new ListKeyGroup(keyboard, keyboard['W'], keyboard['A'], keyboard['S'], keyboard['D']); healthFunction = new ListKeyGroup(keyboard, CorsairKeyboardKeyId.F1, CorsairKeyboardKeyId.F2, CorsairKeyboardKeyId.F3, CorsairKeyboardKeyId.F4, CorsairKeyboardKeyId.F5, CorsairKeyboardKeyId.F6); armorFunction = new ListKeyGroup(keyboard, CorsairKeyboardKeyId.F7, CorsairKeyboardKeyId.F8, CorsairKeyboardKeyId.F9, CorsairKeyboardKeyId.F10, CorsairKeyboardKeyId.F11, CorsairKeyboardKeyId.F12); //don't initilize the numpad groups if the keyboard doesn't have a numpad(K65). if (useNumpad) { numpad = new RectangleKeyGroup(keyboard, CorsairKeyboardKeyId.NumLock, CorsairKeyboardKeyId.KeypadEnter, 1.0f, true); numpadDigital = new List<ListKeyGroup>(); for (int i = 0; i < 10; ++i) { numpadDigital.Add(null); } numpadDigital[1] = new ListKeyGroup(keyboard, CorsairKeyboardKeyId.NumLock, CorsairKeyboardKeyId.KeypadSlash, CorsairKeyboardKeyId.Keypad8, CorsairKeyboardKeyId.Keypad5, CorsairKeyboardKeyId.Keypad2, CorsairKeyboardKeyId.Keypad0, CorsairKeyboardKeyId.KeypadPeriodAndDelete); var numpad2Keys = new CorsairKeyboardKeyId[] { CorsairKeyboardKeyId.NumLock, CorsairKeyboardKeyId.KeypadSlash, CorsairKeyboardKeyId.KeypadAsterisk, CorsairKeyboardKeyId.Keypad9, CorsairKeyboardKeyId.Keypad6, CorsairKeyboardKeyId.Keypad5, CorsairKeyboardKeyId.Keypad4, CorsairKeyboardKeyId.Keypad1, CorsairKeyboardKeyId.Keypad0, CorsairKeyboardKeyId.KeypadPeriodAndDelete}; numpadDigital[2] = new ListKeyGroup(keyboard, numpad2Keys); numpadDigital[3] = new ListKeyGroup(keyboard, numpad2Keys); numpadDigital[3].AddKey(CorsairKeyboardKeyId.Keypad3); numpadDigital[3].RemoveKey(CorsairKeyboardKeyId.Keypad1); var numpad4Keys = new CorsairKeyboardKeyId[] { CorsairKeyboardKeyId.NumLock, CorsairKeyboardKeyId.Keypad7, CorsairKeyboardKeyId.Keypad4, CorsairKeyboardKeyId.Keypad5, CorsairKeyboardKeyId.Keypad6, CorsairKeyboardKeyId.Keypad9, CorsairKeyboardKeyId.KeypadAsterisk, CorsairKeyboardKeyId.Keypad3, CorsairKeyboardKeyId.KeypadPeriodAndDelete}; numpadDigital[4] = new ListKeyGroup(keyboard, numpad4Keys); numpadDigital[5] = new ListKeyGroup(keyboard, numpad2Keys); numpadDigital[5].AddKey(CorsairKeyboardKeyId.Keypad7, CorsairKeyboardKeyId.Keypad3); numpadDigital[5].RemoveKey(CorsairKeyboardKeyId.Keypad9, CorsairKeyboardKeyId.Keypad1); numpadDigital[6] = new ListKeyGroup(keyboard, numpad2Keys); numpadDigital[6].AddKey(CorsairKeyboardKeyId.Keypad3, CorsairKeyboardKeyId.Keypad7); numpadDigital[6].RemoveKey(CorsairKeyboardKeyId.Keypad9); var numpad7Keys = new CorsairKeyboardKeyId[] { CorsairKeyboardKeyId.Keypad7, CorsairKeyboardKeyId.NumLock, CorsairKeyboardKeyId.KeypadSlash, CorsairKeyboardKeyId.KeypadAsterisk, CorsairKeyboardKeyId.Keypad9, CorsairKeyboardKeyId.Keypad6, CorsairKeyboardKeyId.Keypad3, CorsairKeyboardKeyId.KeypadPeriodAndDelete }; numpadDigital[7] = new ListKeyGroup(keyboard, numpad7Keys); numpadDigital[8] = new ListKeyGroup(keyboard, numpad2Keys); numpadDigital[8].AddKey(CorsairKeyboardKeyId.Keypad7, CorsairKeyboardKeyId.Keypad3); numpadDigital[9] = new ListKeyGroup(keyboard, numpad4Keys); numpadDigital[9].AddKey(CorsairKeyboardKeyId.KeypadSlash); numpadDigital[0] = new ListKeyGroup(keyboard, numpad7Keys); numpadDigital[0].AddKey(CorsairKeyboardKeyId.Keypad0, CorsairKeyboardKeyId.Keypad1, CorsairKeyboardKeyId.Keypad4); } } catch (Exception ex) { Console.WriteLine("Exception in creating key groups!"); Console.WriteLine("Message: " + ex.Message); } }
public void updateState(string type, System.Drawing.Color col, [Optional]System.Drawing.Color col2, [Optional]bool direction, [Optional]int speed) { if (type == "reset") { if (RazerSDK != false) { if (DeviceHeadset == true) { Headset.Instance.Clear(); } if (DeviceKeyboard == true) { Keyboard.Instance.Clear(); } if (DeviceKeypad == true) { Keypad.Instance.Clear(); } if (DeviceMouse == true) { Mouse.Instance.Clear(); } if (DeviceMousepad == true) { Mousepad.Instance.Clear(); } } if (CorsairSDK != false) { if (CorsairKeyboardDetect == true) { CorsairKeyboard corKeyboard = CueSDK.KeyboardSDK; ListKeyGroup allGroup = new ListKeyGroup(corKeyboard) { Brush = new SolidColorBrush(System.Drawing.Color.Black) }; corKeyboard.Update(); } if (CorsairMouseDetect == true) { CorsairMouse corMouse = CueSDK.MouseSDK; //Unsupported } if (CorsairHeadsetDetect == true) { CorsairHeadset corHeadset = CueSDK.HeadsetSDK; //Unsupported } } if (LogitechSDK != false) { if (DeviceLogitech == true) { if (LogiEffectRunning == true) { LogitechGSDK.LogiLedStopEffects(); Thread.Sleep(100); } LogitechGSDK.LogiLedSetLighting(0, 0, 0); } } } else if (type == "static") { if (RazerSDK != false) { new Task(() => { if (DeviceHeadset == true) { Headset.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceKeyboard == true) { Keyboard.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceKeypad == true) { Keypad.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceMouse == true) { Mouse.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceMousepad == true) { Mousepad.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } }).Start(); } if (CorsairSDK != false) { new Task(() => { if (CorsairKeyboardDetect == true) { UpdateKeyboard(col); } if (CorsairMouseDetect == true) { CorsairMouse corMouse = CueSDK.MouseSDK; //Unsupported } if (CorsairHeadsetDetect == true) { CorsairHeadset corHeadset = CueSDK.HeadsetSDK; //Unsupported } }).Start(); } if (LogitechSDK != false) { new Task(() => { if (DeviceLogitech == true) { if (LogiEffectRunning == true) { LogitechGSDK.LogiLedStopEffects(); Thread.Sleep(100); } LogitechGSDK.LogiLedSetLighting((int)Math.Ceiling((double)(col.R * 100) / 255), (int)Math.Ceiling((double)(col.G * 100) / 255), (int)Math.Ceiling((double)(col.B * 100) / 255)); LogiEffectRunning = false; } }).Start(); } } else if (type == "transition") { if (RazerSDK != false) { new Task(() => { if (DeviceHeadset == true) { Headset.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceKeyboard == true) { transition(Corale.Colore.Core.Color.FromSystemColor(col), direction); } if (DeviceKeypad == true) { Keypad.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceMouse == true) { Mouse.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceMousepad == true) { Mousepad.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } }).Start(); } if (CorsairSDK != false) { new Task(() => { if (CorsairKeyboardDetect == true) { UpdateKeyboard(col); } if (CorsairMouseDetect == true) { CorsairMouse corMouse = CueSDK.MouseSDK; //Unsupported } if (CorsairHeadsetDetect == true) { CorsairHeadset corHeadset = CueSDK.HeadsetSDK; //Unsupported } }).Start(); } if (LogitechSDK != false) { new Task(() => { if (DeviceLogitech == true) { if (LogiEffectRunning == true) { LogitechGSDK.LogiLedStopEffects(); Thread.Sleep(100); } LogitechGSDK.LogiLedSetLighting((int)Math.Ceiling((double)(col.R * 100) / 255), (int)Math.Ceiling((double)(col.G * 100) / 255), (int)Math.Ceiling((double)(col.B * 100) / 255)); LogiEffectRunning = false; } }).Start(); } } else if (type == "wave") { if (RazerSDK != false) { new Task(() => { if (DeviceHeadset == true) { Headset.Instance.SetEffect(Corale.Colore.Razer.Headset.Effects.Effect.SpectrumCycling); } if (DeviceKeyboard == true) { Keyboard.Instance.SetWave(Corale.Colore.Razer.Keyboard.Effects.Direction.LeftToRight); } if (DeviceKeypad == true) { Keypad.Instance.SetWave(Corale.Colore.Razer.Keypad.Effects.Direction.LeftToRight); } if (DeviceMouse == true) { Mouse.Instance.SetWave(Corale.Colore.Razer.Mouse.Effects.Direction.FrontToBack); } if (DeviceMousepad == true) { Mousepad.Instance.SetWave(Corale.Colore.Razer.Mousepad.Effects.Direction.LeftToRight); } }).Start(); } if (CorsairSDK != false) { new Task(() => { if (CorsairKeyboardDetect == true) { UpdateKeyboard(col); } if (CorsairMouseDetect == true) { CorsairMouse corMouse = CueSDK.MouseSDK; //Unsupported } if (CorsairHeadsetDetect == true) { CorsairHeadset corHeadset = CueSDK.HeadsetSDK; //Unsupported } }).Start(); } if (LogitechSDK != false) { new Task(() => { if (DeviceLogitech == true) { if (LogiEffectRunning == true) { LogitechGSDK.LogiLedStopEffects(); Thread.Sleep(100); } LogiColourCycle(col); LogiEffectRunning = false; } }).Start(); } } else if (type == "breath") { if (RazerSDK != false) { new Task(() => { if (DeviceHeadset == true) { Headset.Instance.SetBreathing(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceKeyboard == true) { Keyboard.Instance.SetBreathing(Corale.Colore.Core.Color.FromSystemColor(col), Corale.Colore.Core.Color.FromSystemColor(col2)); } if (DeviceKeypad == true) { Keypad.Instance.SetBreathing(Corale.Colore.Core.Color.FromSystemColor(col), Corale.Colore.Core.Color.FromSystemColor(col2)); } if (DeviceMouse == true) { Mouse.Instance.SetBreathing(Corale.Colore.Core.Color.FromSystemColor(col), Corale.Colore.Core.Color.FromSystemColor(col2), Led.All); } if (DeviceMousepad == true) { Mousepad.Instance.SetBreathing(Corale.Colore.Core.Color.FromSystemColor(col), Corale.Colore.Core.Color.FromSystemColor(col2)); } }).Start(); } if (CorsairSDK != false) { new Task(() => { if (CorsairKeyboardDetect == true) { UpdateKeyboard(col); } if (CorsairMouseDetect == true) { CorsairMouse corMouse = CueSDK.MouseSDK; //Unsupported } if (CorsairHeadsetDetect == true) { CorsairHeadset corHeadset = CueSDK.HeadsetSDK; //Unsupported } }).Start(); } if (LogitechSDK != false) { new Task(() => { if (DeviceLogitech == true) { LogitechGSDK.LogiLedPulseLighting((int)Math.Ceiling((double)(col.R * 100) / 255), (int)Math.Ceiling((double)(col.G * 100) / 255), (int)Math.Ceiling((double)(col.B * 100) / 255), LogitechGSDK.LOGI_LED_DURATION_INFINITE, 60); LogiEffectRunning = true; } }).Start(); } } else if (type == "pulse") { if (RazerSDK != false) { new Task(() => { if (DeviceHeadset == true) { Headset.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceKeyboard == true) { transitionConst(Corale.Colore.Core.Color.FromSystemColor(col), Corale.Colore.Core.Color.FromSystemColor(col2), true, speed); } if (DeviceKeypad == true) { Keypad.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceMouse == true) { Mouse.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } if (DeviceMousepad == true) { Mousepad.Instance.SetAll(Corale.Colore.Core.Color.FromSystemColor(col)); } }, CTS.Token).Start(); RzPulse = true; } if (CorsairSDK != false) { new Task(() => { if (CorsairKeyboardDetect == true) { UpdateKeyboard(col); } if (CorsairMouseDetect == true) { CorsairMouse corMouse = CueSDK.MouseSDK; //Unsupported } if (CorsairHeadsetDetect == true) { CorsairHeadset corHeadset = CueSDK.HeadsetSDK; //Unsupported } }).Start(); } if (LogitechSDK != false) { new Task(() => { if (DeviceLogitech == true) { if (LogiEffectRunning == true) { LogitechGSDK.LogiLedStopEffects(); Thread.Sleep(100); } LogitechGSDK.LogiLedSetLighting((int)Math.Ceiling((double)(col.R * 100) / 255), (int)Math.Ceiling((double)(col.G * 100) / 255), (int)Math.Ceiling((double)(col.B * 100) / 255)); LogiEffectRunning = false; } }).Start(); } } }