diff --git a/Devices/Keyboard/CorsairKeyboard.cs b/Devices/Keyboard/CorsairKeyboard.cs index 656971e..816042b 100644 --- a/Devices/Keyboard/CorsairKeyboard.cs +++ b/Devices/Keyboard/CorsairKeyboard.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; +using System.Drawing; +using System.Runtime.InteropServices; using CUE.NET.Devices.Generic; using CUE.NET.Devices.Keyboard.Enums; using CUE.NET.Devices.Keyboard.Keys; +using CUE.NET.Native; namespace CUE.NET.Devices.Keyboard { @@ -41,8 +44,17 @@ namespace CUE.NET.Devices.Keyboard private void InitializeKeys() { - foreach (CorsairKeyboardKeyId keyId in Enum.GetValues(typeof(CorsairKeyboardKeyId))) - _keys.Add(keyId, new CorsairKey(keyId, GetLed((int)keyId))); + _CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions)); + int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); + IntPtr ptr = nativeLedPositions.pLedPosition; + for (int i = 0; i < nativeLedPositions.numberOfLed; i++) + { + _CorsairLedPosition ledPosition = Marshal.PtrToStructure<_CorsairLedPosition>(ptr); + _keys.Add(ledPosition.ledId, new CorsairKey(ledPosition.ledId, GetLed((int)ledPosition.ledId), + //TODO DarthAffe 19.09.2015: Is something like RectangleD needed? I don't think so ... + new RectangleF((float)ledPosition.top, (float)ledPosition.left, (float)ledPosition.width, (float)ledPosition.height))); + ptr = new IntPtr(ptr.ToInt64() + structSize); + } } #endregion diff --git a/Devices/Keyboard/Keys/CorsairKey.cs b/Devices/Keyboard/Keys/CorsairKey.cs index f63e85d..7a05530 100644 --- a/Devices/Keyboard/Keys/CorsairKey.cs +++ b/Devices/Keyboard/Keys/CorsairKey.cs @@ -1,4 +1,5 @@ -using CUE.NET.Devices.Generic; +using System.Drawing; +using CUE.NET.Devices.Generic; using CUE.NET.Devices.Keyboard.Enums; namespace CUE.NET.Devices.Keyboard.Keys @@ -9,15 +10,17 @@ namespace CUE.NET.Devices.Keyboard.Keys public CorsairKeyboardKeyId KeyId { get; } public CorsairLed Led { get; } + public RectangleF KeyRectangle { get; } #endregion #region Constructors - internal CorsairKey(CorsairKeyboardKeyId keyId, CorsairLed led) + internal CorsairKey(CorsairKeyboardKeyId keyId, CorsairLed led, RectangleF keyRectangle) { this.KeyId = keyId; this.Led = led; + this.KeyRectangle = keyRectangle; } #endregion diff --git a/Native/_CUESDK.cs b/Native/_CUESDK.cs index c5df2d5..8f8305c 100644 --- a/Native/_CUESDK.cs +++ b/Native/_CUESDK.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using CUE.NET.Devices.Generic.Enums; +using CUE.NET.Devices.Keyboard.Enums; namespace CUE.NET.Native { @@ -52,7 +53,7 @@ namespace CUE.NET.Native [DllImport("CUESDK_2013.dll", CallingConvention = CallingConvention.Cdecl)] #endif // retrieves led id for key name taking logical layout into account. - internal static extern int CorsairGetLedIdForKeyName(char keyName); + internal static extern CorsairKeyboardKeyId CorsairGetLedIdForKeyName(char keyName); #if WIN64 [DllImport("CUESDK.x64_2013.dll", CallingConvention = CallingConvention.Cdecl)] diff --git a/Native/_CorsairLedPosition.cs b/Native/_CorsairLedPosition.cs index 2d5d472..ebd29e2 100644 --- a/Native/_CorsairLedPosition.cs +++ b/Native/_CorsairLedPosition.cs @@ -3,17 +3,18 @@ #pragma warning disable 649 // Field 'x' is never assigned using System.Runtime.InteropServices; +using CUE.NET.Devices.Keyboard.Enums; namespace CUE.NET.Native { // ReSharper disable once InconsistentNaming [StructLayout(LayoutKind.Sequential)] - internal class _CorsairLedPosition // contains led id and position of led rectangle.Most of the keys are rectangular. In case if key is not rectangular(like Enter in ISO / UK layout) it returns the smallest rectangle that fully contains the key + internal class _CorsairLedPosition // contains led id and position of led rectangle.Most of the keys are rectangular. In case if key is not rectangular(like Enter in ISO / UK layout) it returns the smallest rectangle that fully contains the key { - internal int ledId; // identifier of led + internal CorsairKeyboardKeyId ledId; // identifier of led internal double top; internal double left; internal double height; - internal double width; // values in mm + internal double width; // values in mm } }