mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 08:48:30 +00:00
Added an event to get the key-change of special keys (G and M)
This commit is contained in:
parent
c4ac6f0e40
commit
5091b33864
@ -59,6 +59,7 @@
|
|||||||
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairAccessMode.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairDeviceCaps.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
|
||||||
|
<Compile Include="Devices\Generic\Enums\CorsairKeyId.cs" />
|
||||||
<Compile Include="Devices\Generic\Enums\CorsairLedId.cs" />
|
<Compile Include="Devices\Generic\Enums\CorsairLedId.cs" />
|
||||||
<Compile Include="Devices\Generic\EventArgs\ExceptionEventArgs.cs" />
|
<Compile Include="Devices\Generic\EventArgs\ExceptionEventArgs.cs" />
|
||||||
<Compile Include="Brushes\AbstractBrush.cs" />
|
<Compile Include="Brushes\AbstractBrush.cs" />
|
||||||
@ -71,6 +72,8 @@
|
|||||||
<Compile Include="Devices\HeadsetStand\CorsairHeadsetStandDeviceInfo.cs" />
|
<Compile Include="Devices\HeadsetStand\CorsairHeadsetStandDeviceInfo.cs" />
|
||||||
<Compile Include="Devices\HeadsetStand\Enums\CorsairHeadsetStandLedId.cs" />
|
<Compile Include="Devices\HeadsetStand\Enums\CorsairHeadsetStandLedId.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
|
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
|
||||||
|
<Compile Include="Devices\Keyboard\Enums\CorsairKeyboardKeyId.cs" />
|
||||||
|
<Compile Include="Devices\Mouse\Enums\CorsairMouseKeyId.cs" />
|
||||||
<Compile Include="Effects\AbstractLedGroupEffect.cs" />
|
<Compile Include="Effects\AbstractLedGroupEffect.cs" />
|
||||||
<Compile Include="Effects\AbstractBrushEffect.cs" />
|
<Compile Include="Effects\AbstractBrushEffect.cs" />
|
||||||
<Compile Include="Effects\AbstractEffectTarget.cs" />
|
<Compile Include="Effects\AbstractEffectTarget.cs" />
|
||||||
@ -79,6 +82,7 @@
|
|||||||
<Compile Include="Devices\Mousemat\CorsairMousematDeviceInfo.cs" />
|
<Compile Include="Devices\Mousemat\CorsairMousematDeviceInfo.cs" />
|
||||||
<Compile Include="Devices\Mousemat\Enums\CorsairMousematLedId.cs" />
|
<Compile Include="Devices\Mousemat\Enums\CorsairMousematLedId.cs" />
|
||||||
<Compile Include="Effects\MoveGradientEffect.cs" />
|
<Compile Include="Effects\MoveGradientEffect.cs" />
|
||||||
|
<Compile Include="EventArgs\KeyPressedEventArgs.cs" />
|
||||||
<Compile Include="Gradients\AbstractGradient.cs" />
|
<Compile Include="Gradients\AbstractGradient.cs" />
|
||||||
<Compile Include="Gradients\GradientStop.cs" />
|
<Compile Include="Gradients\GradientStop.cs" />
|
||||||
<Compile Include="Gradients\IGradient.cs" />
|
<Compile Include="Gradients\IGradient.cs" />
|
||||||
|
|||||||
29
CueSDK.cs
29
CueSDK.cs
@ -1,6 +1,7 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@ -12,6 +13,7 @@ using CUE.NET.Devices.HeadsetStand;
|
|||||||
using CUE.NET.Devices.Keyboard;
|
using CUE.NET.Devices.Keyboard;
|
||||||
using CUE.NET.Devices.Mouse;
|
using CUE.NET.Devices.Mouse;
|
||||||
using CUE.NET.Devices.Mousemat;
|
using CUE.NET.Devices.Mousemat;
|
||||||
|
using CUE.NET.EventArgs;
|
||||||
using CUE.NET.Exceptions;
|
using CUE.NET.Exceptions;
|
||||||
using CUE.NET.Native;
|
using CUE.NET.Native;
|
||||||
|
|
||||||
@ -100,6 +102,20 @@ namespace CUE.NET
|
|||||||
|
|
||||||
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
private delegate void OnKeyPressedDelegate(IntPtr context, CorsairKeyId keyId, [MarshalAs(UnmanagedType.I1)] bool pressed);
|
||||||
|
private static readonly OnKeyPressedDelegate _onKeyPressedDelegate = OnKeyPressed;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the SDK reports that a key is pressed.
|
||||||
|
/// Notice that right now only G- (keyboard) and M- (mouse) keys are supported.
|
||||||
|
/// </summary>
|
||||||
|
public static event EventHandler<KeyPressedEventArgs> KeyPressed;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
@ -231,6 +247,11 @@ namespace CUE.NET
|
|||||||
Throw(error, true);
|
Throw(error, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_CUESDK.CorsairRegisterKeypressCallback(Marshal.GetFunctionPointerForDelegate(_onKeyPressedDelegate), IntPtr.Zero);
|
||||||
|
error = LastError;
|
||||||
|
if (error != CorsairError.Success)
|
||||||
|
Throw(error, false);
|
||||||
|
|
||||||
InitializedDevices = new ReadOnlyCollection<ICueDevice>(devices);
|
InitializedDevices = new ReadOnlyCollection<ICueDevice>(devices);
|
||||||
|
|
||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
@ -322,6 +343,11 @@ namespace CUE.NET
|
|||||||
|| HeadsetStandSDK.HeadsetStandDeviceInfo.Model != reloadedDevices[CorsairDeviceType.HeadsetStand].Model)
|
|| HeadsetStandSDK.HeadsetStandDeviceInfo.Model != reloadedDevices[CorsairDeviceType.HeadsetStand].Model)
|
||||||
throw new WrapperException("The previously loaded Headset Stand got disconnected.");
|
throw new WrapperException("The previously loaded Headset Stand got disconnected.");
|
||||||
|
|
||||||
|
_CUESDK.CorsairRegisterKeypressCallback(Marshal.GetFunctionPointerForDelegate(_onKeyPressedDelegate), IntPtr.Zero);
|
||||||
|
error = LastError;
|
||||||
|
if (error != CorsairError.Success)
|
||||||
|
Throw(error, false);
|
||||||
|
|
||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,6 +368,9 @@ namespace CUE.NET
|
|||||||
throw new CUEException(error);
|
throw new CUEException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void OnKeyPressed(IntPtr context, CorsairKeyId keyId, bool pressed)
|
||||||
|
=> KeyPressed?.Invoke(null, new KeyPressedEventArgs(keyId, pressed));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
Devices/Generic/Enums/CorsairKeyId.cs
Normal file
46
Devices/Generic/Enums/CorsairKeyId.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Generic.Enums
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains list of all KeyIds available for all corsair devices.
|
||||||
|
/// </summary>
|
||||||
|
public enum CorsairKeyId
|
||||||
|
{
|
||||||
|
Invalid = 0,
|
||||||
|
|
||||||
|
G1 = 1,
|
||||||
|
G2 = 2,
|
||||||
|
G3 = 3,
|
||||||
|
G4 = 4,
|
||||||
|
G5 = 5,
|
||||||
|
G6 = 6,
|
||||||
|
G7 = 7,
|
||||||
|
G8 = 8,
|
||||||
|
G9 = 9,
|
||||||
|
G10 = 10,
|
||||||
|
G11 = 11,
|
||||||
|
G12 = 12,
|
||||||
|
G13 = 13,
|
||||||
|
G14 = 14,
|
||||||
|
G15 = 15,
|
||||||
|
G16 = 16,
|
||||||
|
G17 = 17,
|
||||||
|
G18 = 18,
|
||||||
|
|
||||||
|
M1 = 19,
|
||||||
|
M2 = 20,
|
||||||
|
M3 = 21,
|
||||||
|
M4 = 22,
|
||||||
|
M5 = 23,
|
||||||
|
M6 = 24,
|
||||||
|
M7 = 25,
|
||||||
|
M8 = 26,
|
||||||
|
M9 = 27,
|
||||||
|
M10 = 28,
|
||||||
|
M11 = 29,
|
||||||
|
M12 = 30,
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Devices/Keyboard/Enums/CorsairKeyboardKeyId.cs
Normal file
36
Devices/Keyboard/Enums/CorsairKeyboardKeyId.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||||
|
|
||||||
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Keyboard.Enums
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains list of all LEDs available for corsair keyboards.
|
||||||
|
/// </summary>
|
||||||
|
public static class CorsairKeyboardKeyId
|
||||||
|
{
|
||||||
|
public const CorsairKeyId Invalid = CorsairKeyId.Invalid;
|
||||||
|
|
||||||
|
public const CorsairKeyId G1 = CorsairKeyId.G1;
|
||||||
|
public const CorsairKeyId G2 = CorsairKeyId.G2;
|
||||||
|
public const CorsairKeyId G3 = CorsairKeyId.G3;
|
||||||
|
public const CorsairKeyId G4 = CorsairKeyId.G4;
|
||||||
|
public const CorsairKeyId G5 = CorsairKeyId.G5;
|
||||||
|
public const CorsairKeyId G6 = CorsairKeyId.G6;
|
||||||
|
public const CorsairKeyId G7 = CorsairKeyId.G7;
|
||||||
|
public const CorsairKeyId G8 = CorsairKeyId.G8;
|
||||||
|
public const CorsairKeyId G9 = CorsairKeyId.G9;
|
||||||
|
public const CorsairKeyId G10 = CorsairKeyId.G10;
|
||||||
|
public const CorsairKeyId G11 = CorsairKeyId.G11;
|
||||||
|
public const CorsairKeyId G12 = CorsairKeyId.G12;
|
||||||
|
public const CorsairKeyId G13 = CorsairKeyId.G13;
|
||||||
|
public const CorsairKeyId G14 = CorsairKeyId.G14;
|
||||||
|
public const CorsairKeyId G15 = CorsairKeyId.G15;
|
||||||
|
public const CorsairKeyId G16 = CorsairKeyId.G16;
|
||||||
|
public const CorsairKeyId G17 = CorsairKeyId.G17;
|
||||||
|
public const CorsairKeyId G18 = CorsairKeyId.G18;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
Devices/Mouse/Enums/CorsairMouseKeyId.cs
Normal file
30
Devices/Mouse/Enums/CorsairMouseKeyId.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
|
||||||
|
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||||
|
|
||||||
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Mouse.Enums
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains list of all LEDs available for corsair mice.
|
||||||
|
/// </summary>
|
||||||
|
public static class CorsairMouseKeyId
|
||||||
|
{
|
||||||
|
public const CorsairKeyId Invalid = CorsairKeyId.Invalid;
|
||||||
|
|
||||||
|
public const CorsairKeyId M1 = CorsairKeyId.M1;
|
||||||
|
public const CorsairKeyId M2 = CorsairKeyId.M2;
|
||||||
|
public const CorsairKeyId M3 = CorsairKeyId.M3;
|
||||||
|
public const CorsairKeyId M4 = CorsairKeyId.M4;
|
||||||
|
public const CorsairKeyId M5 = CorsairKeyId.M5;
|
||||||
|
public const CorsairKeyId M6 = CorsairKeyId.M6;
|
||||||
|
public const CorsairKeyId M7 = CorsairKeyId.M7;
|
||||||
|
public const CorsairKeyId M8 = CorsairKeyId.M8;
|
||||||
|
public const CorsairKeyId M9 = CorsairKeyId.M9;
|
||||||
|
public const CorsairKeyId M10 = CorsairKeyId.M10;
|
||||||
|
public const CorsairKeyId M11 = CorsairKeyId.M11;
|
||||||
|
public const CorsairKeyId M12 = CorsairKeyId.M12;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
EventArgs/KeyPressedEventArgs.cs
Normal file
41
EventArgs/KeyPressedEventArgs.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
|
||||||
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
|
|
||||||
|
namespace CUE.NET.EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the data provided by the <see cref="CueSDK.KeyPressed"/>-event.
|
||||||
|
/// </summary>
|
||||||
|
public class KeyPressedEventArgs : System.EventArgs
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the id of the key.
|
||||||
|
/// </summary>
|
||||||
|
public CorsairKeyId KeyId { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current status of the key (true = pressed, flase = released).
|
||||||
|
/// </summary>
|
||||||
|
public bool IsPressed { get; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="KeyPressedEventArgs"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="keyId">The id of the key.</param>
|
||||||
|
/// <param name="isPressed">The current status of the key (true = pressed, flase = released).</param>
|
||||||
|
public KeyPressedEventArgs(CorsairKeyId keyId, bool isPressed)
|
||||||
|
{
|
||||||
|
this.KeyId = keyId;
|
||||||
|
this.IsPressed = isPressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -39,6 +39,8 @@ namespace SimpleDevTest
|
|||||||
CueSDK.Initialize();
|
CueSDK.Initialize();
|
||||||
Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK");
|
Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK");
|
||||||
|
|
||||||
|
CueSDK.KeyPressed += (sender, eventArgs) => Console.WriteLine($"Key {eventArgs.KeyId} {(eventArgs.IsPressed ? "pressed" : "released")}");
|
||||||
|
|
||||||
//CueSDK.KeyboardSDK.Brush = (SolidColorBrush)Color.Black;
|
//CueSDK.KeyboardSDK.Brush = (SolidColorBrush)Color.Black;
|
||||||
//CueSDK.KeyboardSDK[CorsairLedId.Z].Color = Color.Red;
|
//CueSDK.KeyboardSDK[CorsairLedId.Z].Color = Color.Red;
|
||||||
//CueSDK.KeyboardSDK[CorsairLedId.Z].IsLocked = true;
|
//CueSDK.KeyboardSDK[CorsairLedId.Z].IsLocked = true;
|
||||||
|
|||||||
@ -63,6 +63,7 @@ namespace CUE.NET.Native
|
|||||||
_corsairReleaseControlPointer = (CorsairReleaseControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairReleaseControl"), typeof(CorsairReleaseControlPointer));
|
_corsairReleaseControlPointer = (CorsairReleaseControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairReleaseControl"), typeof(CorsairReleaseControlPointer));
|
||||||
_corsairPerformProtocolHandshakePointer = (CorsairPerformProtocolHandshakePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairPerformProtocolHandshake"), typeof(CorsairPerformProtocolHandshakePointer));
|
_corsairPerformProtocolHandshakePointer = (CorsairPerformProtocolHandshakePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairPerformProtocolHandshake"), typeof(CorsairPerformProtocolHandshakePointer));
|
||||||
_corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer));
|
_corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer));
|
||||||
|
_corsairRegisterKeypressCallbackPointer = (CorsairRegisterKeypressCallbackPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairRegisterKeypressCallback"), typeof(CorsairRegisterKeypressCallbackPointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UnloadCUESDK()
|
private static void UnloadCUESDK()
|
||||||
@ -100,6 +101,7 @@ namespace CUE.NET.Native
|
|||||||
private static CorsairReleaseControlPointer _corsairReleaseControlPointer;
|
private static CorsairReleaseControlPointer _corsairReleaseControlPointer;
|
||||||
private static CorsairPerformProtocolHandshakePointer _corsairPerformProtocolHandshakePointer;
|
private static CorsairPerformProtocolHandshakePointer _corsairPerformProtocolHandshakePointer;
|
||||||
private static CorsairGetLastErrorPointer _corsairGetLastErrorPointer;
|
private static CorsairGetLastErrorPointer _corsairGetLastErrorPointer;
|
||||||
|
private static CorsairRegisterKeypressCallbackPointer _corsairRegisterKeypressCallbackPointer;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -138,6 +140,9 @@ namespace CUE.NET.Native
|
|||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
private delegate CorsairError CorsairGetLastErrorPointer();
|
private delegate CorsairError CorsairGetLastErrorPointer();
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
private delegate bool CorsairRegisterKeypressCallbackPointer(IntPtr callback, IntPtr context);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// ReSharper disable EventExceptionNotDocumented
|
// ReSharper disable EventExceptionNotDocumented
|
||||||
@ -231,6 +236,11 @@ namespace CUE.NET.Native
|
|||||||
return _corsairGetLastErrorPointer();
|
return _corsairGetLastErrorPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool CorsairRegisterKeypressCallback(IntPtr callback, IntPtr context)
|
||||||
|
{
|
||||||
|
return _corsairRegisterKeypressCallbackPointer(callback, context);
|
||||||
|
}
|
||||||
|
|
||||||
// ReSharper restore EventExceptionNotDocumented
|
// ReSharper restore EventExceptionNotDocumented
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user