@@ -104,7 +104,7 @@ public static partial class CueSDK
104
104
105
105
[ UnmanagedFunctionPointer ( CallingConvention . Cdecl ) ]
106
106
private delegate void OnKeyPressedDelegate ( IntPtr context , CorsairKeyId keyId , [ MarshalAs ( UnmanagedType . I1 ) ] bool pressed ) ;
107
- private static readonly OnKeyPressedDelegate _onKeyPressedDelegate = OnKeyPressed ;
107
+ private static OnKeyPressedDelegate _onKeyPressedDelegate ;
108
108
109
109
#endregion
110
110
@@ -113,6 +113,8 @@ public static partial class CueSDK
113
113
/// <summary>
114
114
/// Occurs when the SDK reports that a key is pressed.
115
115
/// Notice that right now only G- (keyboard) and M- (mouse) keys are supported.
116
+ ///
117
+ /// To enable this event <see cref="EnableKeypressCallback"/> needs to be called.
116
118
/// </summary>
117
119
public static event EventHandler < KeyPressedEventArgs > KeyPressed ;
118
120
@@ -247,7 +249,6 @@ public static void Initialize(bool exclusiveAccess = false)
247
249
Throw ( error , true ) ;
248
250
}
249
251
250
- _CUESDK . CorsairRegisterKeypressCallback ( Marshal . GetFunctionPointerForDelegate ( _onKeyPressedDelegate ) , IntPtr . Zero ) ;
251
252
error = LastError ;
252
253
if ( error != CorsairError . Success )
253
254
Throw ( error , false ) ;
@@ -257,6 +258,21 @@ public static void Initialize(bool exclusiveAccess = false)
257
258
IsInitialized = true ;
258
259
}
259
260
261
+ /// <summary>
262
+ /// Enables the keypress-callback.
263
+ /// This method needs to be called to enable the <see cref="KeyPressed"/>-event.
264
+ ///
265
+ /// WARNING: AFTER THIS METHOD IS CALLED IT'S NO LONGER POSSIBLE TO REINITIALIZE THE SDK!
266
+ /// </summary>
267
+ public static void EnableKeypressCallback ( )
268
+ {
269
+ if ( ! IsInitialized )
270
+ throw new WrapperException ( "CueSDK isn't initialized." ) ;
271
+
272
+ _onKeyPressedDelegate = OnKeyPressed ;
273
+ _CUESDK . CorsairRegisterKeypressCallback ( Marshal . GetFunctionPointerForDelegate ( _onKeyPressedDelegate ) , IntPtr . Zero ) ;
274
+ }
275
+
260
276
/// <summary>
261
277
/// Resets the colors of all devices back to the last saved color-data. (If there wasn't a manual save, that's the data from the time the SDK was initialized.)
262
278
/// </summary>
@@ -283,6 +299,9 @@ public static void Reinitialize(bool exclusiveAccess)
283
299
if ( ! IsInitialized )
284
300
throw new WrapperException ( "CueSDK isn't initialized." ) ;
285
301
302
+ if ( _onKeyPressedDelegate != null )
303
+ throw new WrapperException ( "Keypress-Callback is enabled." ) ;
304
+
286
305
KeyboardSDK ? . ResetLeds ( ) ;
287
306
MouseSDK ? . ResetLeds ( ) ;
288
307
HeadsetSDK ? . ResetLeds ( ) ;
@@ -343,7 +362,6 @@ public static void Reinitialize(bool exclusiveAccess)
343
362
|| HeadsetStandSDK . HeadsetStandDeviceInfo . Model != reloadedDevices [ CorsairDeviceType . HeadsetStand ] . Model )
344
363
throw new WrapperException ( "The previously loaded Headset Stand got disconnected." ) ;
345
364
346
- _CUESDK . CorsairRegisterKeypressCallback ( Marshal . GetFunctionPointerForDelegate ( _onKeyPressedDelegate ) , IntPtr . Zero ) ;
347
365
error = LastError ;
348
366
if ( error != CorsairError . Success )
349
367
Throw ( error , false ) ;
0 commit comments