Added key-position, initialized keyboard with available keys

This commit is contained in:
DarthAffe committed 2015-09-19 18:49:41 +02:00
1 parent 0167828a19
commit 64e0902046
4 files changed
+25 -8

No files matched your search

+14 -2
View File
@@ -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
+5 -2
View File
@@ -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
+2 -1
View File
@@ -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)]
+4 -3
View File
@@ -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
}
}