Ejemplo n.º 1
0
        /// <summary>
        ///     Determines whether a specified key is pressed.
        /// </summary>
        /// <param name="key"> The key. </param>
        /// <returns>
        ///     true if the key is pressed, false otherwise.
        /// </returns>
        public static bool IsKeyPressed(SystemKeyboardKey key)
        {
            short result = SystemKeyboard.GetKeyState((int)key);

            bool keyPressed;

            switch ((result & 0x8000) >> 15)
            {
            default:
            {
                keyPressed = true;
                break;
            }

            case 0:
            {
                keyPressed = false;
                break;
            }

            case 1:
            {
                keyPressed = true;
                break;
            }
            }

            return(keyPressed);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Determines whether a specified key is toggled on.
        /// </summary>
        /// <param name="key"> The key. </param>
        /// <returns>
        ///     true if the key is toggled on, false otherwise.
        /// </returns>
        public static bool IsKeyToggledOn(SystemKeyboardKey key)
        {
            short result = SystemKeyboard.GetKeyState((int)key);

            bool keyToggledOn;

            switch (result & 0x0001)
            {
            default:
            {
                keyToggledOn = true;
                break;
            }

            case 0:
            {
                keyToggledOn = false;
                break;
            }

            case 1:
            {
                keyToggledOn = true;
                break;
            }
            }

            return(keyToggledOn);
        }