/// <summary> /// Initializes a new instance of the <see cref="DynamicKeyImageRenderer" /> class. /// </summary> /// <param name="keyType">The type of DK to render to.</param> /// <param name="up">The image to render (UP state).</param> /// <param name="down">The image to render (DOWN state).</param> /// <param name="interval">The interval (in milliseconds) at which to refresh the image.</param> internal DynamicKeyImageRenderer(DynamicKeyType keyType, string up, string down, int interval = 42) : base(up, interval) { _up = up; _down = down; KeyType = keyType; }
/// <summary> /// Enables a specific dynamic key. /// </summary> /// <param name="keyType">The key type to enable.</param> /// <param name="image">Image to display on this key when in the UP state.</param> /// <param name="pressedImage">Image to display on this key when in the DOWN state.</param> /// <param name="replace">True to override this key's previous configuration /// if it has already been enabled, otherwise returns current key if already enabled.</param> /// <returns>The dynamic key that was enabled.</returns> public IDynamicKey Enable( DynamicKeyType keyType, string image, string pressedImage = null, bool replace = false) { return(Enable(keyType, null, image, pressedImage, replace)); }
/// <summary> /// Enables a specific dynamic key. /// </summary> /// <param name="keyType">The key type to enable.</param> /// <param name="callback">Callback called when this key is released.</param> /// <param name="image">Image to display on this key when in the UP state.</param> /// <param name="replace">True to override this key's previous configuration /// if it has already been enabled, otherwise returns current key if already enabled.</param> /// <returns>The dynamic key that was enabled.</returns> public IDynamicKey Enable( DynamicKeyType keyType, EventHandler <DynamicKeyEventArgs> callback, string image, bool replace) { return(Enable(keyType, callback, image, null, replace)); }
/// <summary> /// Sets the images for the specified state on the specified dynamic key. /// </summary> /// <param name="keyType">The dynamic key to modify.</param> /// <param name="state">The state to update.</param> /// <param name="image">Image file for the specified state.</param> /// <exception cref="NativeCallException"> /// Thrown if there is an error calling the native functions to update the images. /// </exception> public static void Draw(DynamicKeyType keyType, DynamicKeyState state, string image) { var result = NativeMethods.RzSBSetImageDynamicKey(keyType, state, image); if (HRESULT.RZSB_FAILED(result)) { throw new NativeCallException("RzSBSetImageDynamicKey", result); } }
/// <summary> /// Raises dynamic key event to subscribers. /// </summary> /// <param name="keyType">The dynamic key affected.</param> /// <param name="state">New key state.</param> private void OnDynamicKeyEvent(DynamicKeyType keyType, DynamicKeyState state) { var func = DynamicKeyEvent; if (func != null) { func(this, new DynamicKeyEventArgs(keyType, state)); } }
/// <summary> /// Gets a specific dynamic key. /// </summary> /// <param name="keyType">The type of key to get.</param> /// <returns> /// An instance of <see cref="IDynamicKey" />. /// </returns> public IDynamicKey this[DynamicKeyType keyType] { get { var index = (int)keyType - 1; if (index >= _keys.Length) { throw new ArgumentOutOfRangeException("keyType"); } return(_keys[index] ?? Enable(keyType)); } }
/// <summary> /// Disables a specific dynamic key. /// </summary> /// <param name="keyType">The key type to disable.</param> public void Disable(DynamicKeyType keyType) { var index = (int)keyType - 1; var dk = _keys[index]; if (dk != null && !dk.Disposed) { dk.Enabled = false; dk.Dispose(); } _keys[index] = null; }
/// <summary> /// Handles dynamic key events sent from Razer SDK. /// </summary> /// <param name="keyType">Dynamic key type.</param> /// <param name="state">New state of the dynamic key.</param> /// <returns><see cref="HRESULT" /> object indicating success or failure.</returns> private HRESULT HandleDynamicKeyEvent(DynamicKeyType keyType, DynamicKeyState state) { const int Result = HRESULT.RZSB_OK; _log.Debug("Raising DynamicKeyEvent event"); OnDynamicKeyEvent(keyType, state); var index = (int)keyType - 1; var dk = _keys[index]; if (dk == null) { _log.Debug("Key has not been registered by app"); return(Result); } _log.Debug("Updating key state"); // UpdateState will check if it's a valid press and call any event subscribers dk.UpdateState(state); return(Result); }
/// <summary> /// Initializes a new instance of the <see cref="DynamicKey" /> class. /// </summary> /// <param name="keyType">The type of dynamic key being initialized.</param> /// <param name="image">Image to set for this key's depressed state.</param> /// <param name="pressedImage">Image to set for this key's pressed state.</param> /// <param name="callback">The function to call when this key is released.</param> internal DynamicKey( DynamicKeyType keyType, string image = null, string pressedImage = null, EventHandler <DynamicKeyEventArgs> callback = null) : base(TargetDisplayMapping[keyType], Constants.DynamicKeyHeight, Constants.DynamicKeyWidth) { _log = LogManager.GetLogger(this); if (string.IsNullOrEmpty(pressedImage)) { _log.Debug("pressedImage is null, setting to value of image"); pressedImage = image; } _log.Debug("Setting default states"); State = DynamicKeyState.None; PreviousState = DynamicKeyState.None; KeyType = keyType; _log.Debug("Creating blank bitmap"); _blankBitmap = GenericMethods.GetBlankBitmap(DisplayWidth, DisplayHeight); _log.Debug("Setting images"); if (image != null) { Draw(image, pressedImage); } if (callback != null) { _log.Debug("Setting callback"); Released += callback; } _enabled = true; }
/// <summary> /// Enables a specific dynamic key. /// </summary> /// <param name="keyType">The key type to enable.</param> /// <param name="callback">Callback called when this key is released.</param> /// <param name="image">Image to display on this key when in the UP state.</param> /// <param name="pressedImage">Image to display on this key when in the DOWN state.</param> /// <param name="replace">True to override this key's previous configuration /// if it has already been enabled, otherwise returns current key if already enabled.</param> /// <returns>The dynamic key that was enabled.</returns> public IDynamicKey Enable( DynamicKeyType keyType, EventHandler <DynamicKeyEventArgs> callback = null, string image = null, string pressedImage = null, bool replace = false) { var index = (int)keyType - 1; if (_keys[index] != null && !replace) { _log.Info("Dynamic key already enabled and replace is false."); return(_keys[index]); } _log.Debug("Resetting dynamic key (Disable)"); Disable(keyType); try { _log.Debug("Creating new DynamicKey object"); var dk = new DynamicKey(keyType, image, pressedImage, callback); _keys[index] = dk; } catch (NativeCallException ex) { _log.ErrorFormat("Failed to enable dynamic key {0}: {1}", keyType, ex.HResult); throw new DynamicKeyException( string.Format( CultureInfo.InvariantCulture, "Failed to enable dynamic key {0} due to a native call exception.", keyType), ex); } return(_keys[index]); }
/// <summary> /// Sets the images for the specified dynamic key's up and down states. /// </summary> /// <param name="keyType">The dynamic key to modify.</param> /// <param name="upImage">Image file for the UP state.</param> /// <param name="downImage">Image file for the DOWN state.</param> public static void Draw(DynamicKeyType keyType, string upImage, string downImage) { Draw(keyType, DynamicKeyState.Up, upImage); Draw(keyType, DynamicKeyState.Down, downImage); }
public static void Draw(DynamicKeyType keyType, string image) { Draw(keyType, image, image); }
private IDynamicKey GetDk(DynamicKeyType type = DynamicKeyType.DK1) { return(_sb.DynamicKeys[type] ?? _sb.DynamicKeys.Enable(type, "dk_image.bmp", "dk_image_down.bmp", true)); }
internal static extern HRESULT RzSBSetImageDynamicKey( [In] DynamicKeyType dk, [In] DynamicKeyState state, [In][MarshalAs(UnmanagedType.LPWStr)] string filename);
/// <summary> /// Enables a specific dynamic key. /// </summary> /// <param name="keyType">The key type to enable.</param> /// <param name="image">Image to display on this key when in the UP state.</param> /// <param name="replace">True to override this key's previous configuration /// if it has already been enabled, otherwise returns current key if already enabled.</param> /// <returns>The dynamic key that was enabled.</returns> public IDynamicKey Enable(DynamicKeyType keyType, string image, bool replace) { return(Enable(keyType, image, null, replace)); }
/// <summary> /// Initializes a new instance of the <see cref="DynamicKeyEventArgs" /> class. /// </summary> /// <param name="keyType">The dynamic key type.</param> /// <param name="state">The state of the key.</param> internal DynamicKeyEventArgs(DynamicKeyType keyType, DynamicKeyState state) { _keyType = keyType; _state = state; }
private IDynamicKey GetDk(DynamicKeyType type = DynamicKeyType.DK1) { return _sb.DynamicKeys[type] ?? _sb.DynamicKeys.Enable(type, "dk_image.bmp", "dk_image_down.bmp", true); }