Description

Colore is an elegant solution for C# developers to work with Razer's Chroma SDK in a way that feels intuitive and similar to other .NET libraries.

Snippets

Key Converter

Class to convert between Winforms Keys and Colore Keyboard Keys

   1 // Not all possible keys are included. This would not be possible using a dictionary, because winforms has, for instance, just one 'Enter' key, in contrast to Colore's normal- and numpad Enter key.
   2 
   3 
   4 using System.Collections.Generic;
   5 using System.Linq;
   6 using FormsKey = System.Windows.Forms.Keys;
   7 using ColoreKey = Colore.Effects.Keyboard.Key;
   8 
   9 namespace MyNameSpace
  10 {
  11     internal class KeyConverter
  12     {
  13         private readonly Dictionary<ColoreKey, FormsKey> formsKeys = new Dictionary<ColoreKey, FormsKey>
  14         {
  15             {ColoreKey.A, FormsKey.A },
  16             {ColoreKey.B, FormsKey.B },
  17             {ColoreKey.C, FormsKey.C },
  18             {ColoreKey.D, FormsKey.D },
  19             {ColoreKey.E, FormsKey.E },
  20             {ColoreKey.F, FormsKey.F },
  21             {ColoreKey.G, FormsKey.G },
  22             {ColoreKey.H, FormsKey.H },
  23             {ColoreKey.I, FormsKey.I },
  24             {ColoreKey.J, FormsKey.J },
  25             {ColoreKey.K, FormsKey.K },
  26             {ColoreKey.L, FormsKey.L },
  27             {ColoreKey.M, FormsKey.M },
  28             {ColoreKey.N, FormsKey.N },
  29             {ColoreKey.O, FormsKey.O },
  30             {ColoreKey.P, FormsKey.P },
  31             {ColoreKey.Q, FormsKey.Q },
  32             {ColoreKey.R, FormsKey.R },
  33             {ColoreKey.S, FormsKey.S },
  34             {ColoreKey.T, FormsKey.T },
  35             {ColoreKey.U, FormsKey.U },
  36             {ColoreKey.V, FormsKey.V },
  37             {ColoreKey.W, FormsKey.W },
  38             {ColoreKey.X, FormsKey.X },
  39             {ColoreKey.Y, FormsKey.Y },
  40             {ColoreKey.Z, FormsKey.Z },
  41             {ColoreKey.D0, FormsKey.D0 },
  42             {ColoreKey.D1, FormsKey.D1 },
  43             {ColoreKey.D2, FormsKey.D2 },
  44             {ColoreKey.D3, FormsKey.D3 },
  45             {ColoreKey.D4, FormsKey.D4 },
  46             {ColoreKey.D5, FormsKey.D5 },
  47             {ColoreKey.D6, FormsKey.D6 },
  48             {ColoreKey.D7, FormsKey.D7 },
  49             {ColoreKey.D8, FormsKey.D8 },
  50             {ColoreKey.D9, FormsKey.D9 },
  51             {ColoreKey.Num0, FormsKey.NumPad0 },
  52             {ColoreKey.Num1, FormsKey.NumPad1 },
  53             {ColoreKey.Num2, FormsKey.NumPad2 },
  54             {ColoreKey.Num3, FormsKey.NumPad3 },
  55             {ColoreKey.Num4, FormsKey.NumPad4 },
  56             {ColoreKey.Num5, FormsKey.NumPad5 },
  57             {ColoreKey.Num6, FormsKey.NumPad6 },
  58             {ColoreKey.Num7, FormsKey.NumPad7 },
  59             {ColoreKey.Num8, FormsKey.NumPad8 },
  60             {ColoreKey.Num9, FormsKey.NumPad9 },
  61             {ColoreKey.F1, FormsKey.F1 },
  62             {ColoreKey.F2, FormsKey.F2 },
  63             {ColoreKey.F3, FormsKey.F3 },
  64             {ColoreKey.F4, FormsKey.F4 },
  65             {ColoreKey.F5, FormsKey.F5 },
  66             {ColoreKey.F6, FormsKey.F6 },
  67             {ColoreKey.F7, FormsKey.F7 },
  68             {ColoreKey.F8, FormsKey.F8 },
  69             {ColoreKey.F9, FormsKey.F9 },
  70             {ColoreKey.F10, FormsKey.F10 },
  71             {ColoreKey.F11, FormsKey.F11 },
  72             {ColoreKey.F12, FormsKey.F12 },
  73             {ColoreKey.NumDivide, FormsKey.Divide },
  74             {ColoreKey.NumMultiply, FormsKey.Multiply },
  75             {ColoreKey.NumSubtract, FormsKey.Subtract },
  76             {ColoreKey.NumAdd, FormsKey.Add },
  77             {ColoreKey.NumDecimal, FormsKey.Decimal },
  78             {ColoreKey.NumEnter, FormsKey.Enter },
  79             {ColoreKey.NumLock, FormsKey.NumLock },
  80             {ColoreKey.Escape, FormsKey.Escape },
  81             {ColoreKey.PrintScreen, FormsKey.PrintScreen },
  82             {ColoreKey.Scroll, FormsKey.Scroll },
  83             {ColoreKey.Pause, FormsKey.Pause },
  84             {ColoreKey.Insert, FormsKey.Insert },
  85             {ColoreKey.Home, FormsKey.Home },
  86             {ColoreKey.PageUp, FormsKey.PageUp },
  87             {ColoreKey.PageDown, FormsKey.PageDown },
  88             {ColoreKey.Delete, FormsKey.Delete },
  89             {ColoreKey.End, FormsKey.End },
  90             {ColoreKey.OemTilde, FormsKey.Oemtilde },
  91             {ColoreKey.Tab, FormsKey.Tab },
  92             {ColoreKey.CapsLock, FormsKey.CapsLock },
  93             {ColoreKey.LeftShift, FormsKey.LShiftKey },
  94             {ColoreKey.RightShift, FormsKey.RShiftKey },
  95             {ColoreKey.LeftControl, FormsKey.LControlKey },
  96             {ColoreKey.RightControl, FormsKey.RControlKey },
  97             {ColoreKey.LeftWindows, FormsKey.LWin },
  98             {ColoreKey.LeftAlt, FormsKey.Alt },
  99             {ColoreKey.Space, FormsKey.Space },
 100             {ColoreKey.Backspace, FormsKey.Back },
 101             {ColoreKey.Up, FormsKey.Up },
 102             {ColoreKey.Down, FormsKey.Down },
 103             {ColoreKey.Left, FormsKey.Left },
 104             {ColoreKey.Right, FormsKey.Right },
 105             {ColoreKey.OemLeftBracket, FormsKey.OemOpenBrackets },
 106             {ColoreKey.OemRightBracket, FormsKey.OemCloseBrackets },
 107             {ColoreKey.OemComma, FormsKey.Oemcomma },
 108             {ColoreKey.OemPeriod, FormsKey.OemPeriod },
 109             {ColoreKey.KorPipe, FormsKey.OemPipe },
 110             {ColoreKey.OemSemicolon, FormsKey.OemSemicolon},
 111             {ColoreKey.OemApostrophe, FormsKey.OemQuotes },
 112             {ColoreKey.OemSlash, FormsKey.OemQuestion },
 113         };
 114 
 115         private readonly Dictionary<FormsKey, ColoreKey> coloreKeys = new Dictionary<FormsKey, ColoreKey>();
 116 
 117         public KeyConverter()
 118         {
 119             coloreKeys = formsKeys.ToDictionary(x => x.Value, x => x.Key);  // Create Reverse-lookup dictionary
 120         }
 121 
 122         public ColoreKey ToColoreKey(FormsKey key)
 123         {
 124             return coloreKeys[key];
 125         }
 126 
 127         public FormsKey ToFormsKey(ColoreKey key)
 128         {
 129             return formsKeys[key];
 130         }
 131     }
 132 }

Howto/CSharp/Colore (last edited 2020-04-17 11:14:17 by Burathar)