Exemple #1
0
        /// <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);
            }
        }
Exemple #2
0
        /// <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));
            }
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        /// <summary>
        /// Updates this key's state and handles events.
        /// </summary>
        /// <param name="state">The new state to assign to this key.</param>
        internal void UpdateState(DynamicKeyState state)
        {
            PreviousState = State;
            State         = state;

            // Don't notify subscribers unless key is enabled
            if (!Enabled)
            {
                return;
            }

            OnChanged();
            if (State == DynamicKeyState.Up &&
                (PreviousState == DynamicKeyState.Down || PreviousState == DynamicKeyState.None))
            {
                OnReleased();
            }
            else if (State == DynamicKeyState.Down &&
                     (PreviousState == DynamicKeyState.Up || PreviousState == DynamicKeyState.None))
            {
                OnPressed();
            }
        }
Exemple #5
0
 /// <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;
 }
Exemple #6
0
 /// <summary>
 /// Sets the image for a specific state on this dynamic key.
 /// </summary>
 /// <param name="state">The state to set an image for.</param>
 /// <param name="image">The image file to set.</param>
 public void Draw(DynamicKeyState state, string image)
 {
     DynamicKeyImageRenderer.Draw(KeyType, state, image);
 }
Exemple #7
0
 internal static extern HRESULT RzSBSetImageDynamicKey(
     [In] DynamicKeyType dk,
     [In] DynamicKeyState state,
     [In][MarshalAs(UnmanagedType.LPWStr)] string filename);