Example #1
0
    private void handleFocusChanged(object sender, EventArgs e)
    {
        GameWindow wnd = sender as GameWindow;

        //reset arrow keys in case the user was scrolling
        //then defocus. This otherwise would scroll indefinately
        //even if the user is not pressing the key.
        p_ArrowKeyDown = 0;
    }
Example #2
0
        /// <summary>
        /// Taps the specified arrow key. Send both UP and DOWN events
        /// with delay of 5 msec
        /// </summary>
        /// <param name="key">The arrow key to be send</param>
        /// <param name="release">True if send WM_KEYUP message as well</param>
        /// <returns>Returns true if successful, false if not</returns>
        public bool SendArrowKey(ArrowKey key)
        {
            if (!ArrowKeyDown(key))
            {
                return(false);
            }

            //Sleep to let the window process the message
            Thread.Sleep(5);

            return(ArrowKeyUp(key));
        }
Example #3
0
        /// <summary>
        /// Send WM_KEYDOWN event for arrow key
        /// </summary>
        /// <param name="key">Arrow key</param>
        /// <returns>True if WM_KEYDOWN message successfully sent and
        /// False if not</returns>
        public bool ArrowKeyDown(ArrowKey key)
        {
            uint lparam;
            int  wparam;

            if (!CheckArrowKey(key, out wparam, out lparam))
            {
                return(false);
            }

            //Post the WM_KEYDOWN message, return false if unsuccessful
            return(_PostMessage(WowHWND, 0x100, wparam, lparam) == 0);
        }
Example #4
0
        /// <summary>
        /// Send WM_KEYUP event for arrow key
        /// </summary>
        /// <param name="key">Arrow key</param>
        /// <returns>True if WM_KEYUP message successfully sent and
        /// False if not</returns>
        public bool ArrowKeyUp(ArrowKey key)
        {
            uint lparam;
            int  wparam;

            if (!CheckArrowKey(key, out wparam, out lparam))
            {
                return(false);
            }

            //Post the WM_KEYUP message, return false if unsuccessful
            return(_PostMessage(WowHWND, 0x101,
                                wparam, (lparam + 0xC0000000)) == 0);
        }
Example #5
0
        /// <summary>
        /// Retrieve lparam value for arrow key
        /// </summary>
        /// <param name="key">Arrow key</param>
        /// <returns>lparam value or 0 if key is unknown</returns>
        private uint GetArrowKeyCode(ArrowKey key)
        {
            //Set up lParam based upon which button needs pressing
            switch (key)
            {
            case ArrowKey.Left: return(0x14B0001);

            case ArrowKey.Up: return(0x1480001);

            case ArrowKey.Right: return(0x14D0001);

            case ArrowKey.Down: return(0x1500001);

            default: return(0);
            }
        }
Example #6
0
    private void handleKeyUp(object sender, KeyEventArgs e)
    {
        p_CurrentKeys = Keys.None;
        if (p_LogicDisabled)
        {
            return;
        }

        if (p_EventHijacker != null)
        {
            p_EventHijacker.OnKeyUp(this, e);
            return;
        }

        /*adjust arrow key flags if we have an arrow key released*/
        switch (e.KeyCode)
        {
        case Keys.Left:
        case Keys.A:
            p_ArrowKeyDown -= ArrowKey.LEFT;
            break;

        case Keys.Right:
        case Keys.D:
            p_ArrowKeyDown -= ArrowKey.RIGHT;
            break;

        case Keys.Up:
        case Keys.W:
            p_ArrowKeyDown -= ArrowKey.UP;
            break;

        case Keys.Down:
        case Keys.S:
            p_ArrowKeyDown -= ArrowKey.DOWN;
            break;
        }

        /*send to all UI elements*/
        int l = p_UIElements.Length;

        for (int c = 0; c < l; c++)
        {
            p_UIElements[c].OnKeyUp(this, e);
        }
    }
Example #7
0
        /// <summary>
        /// Retrieve wparam and lparam for arrow key
        /// </summary>
        /// <param name="key">Arrow key</param>
        /// <param name="wparam">wParam value</param>
        /// <param name="lparam">lParam value</param>
        /// <returns>True if key valid and False if key invalid (unknown)</returns>
        private bool CheckArrowKey(ArrowKey key, out int wparam, out uint lparam)
        {
            wparam = (int)key;
            lparam = GetArrowKeyCode(key);
            if (lparam == 0)
            {
                return(false);
            }

            //If hWnd is 0 return false
            if (WowHWND <= 0)
            {
                return(false);
            }

            return(true);
        }
Example #8
0
        /// <summary>
        /// Holds down an arrow key for the specified time
        /// </summary>
        /// <param name="key">The arrow key to be send</param>
        /// <param name="holdDelay">Number of milliseconds to hold down key</param>
        /// <returns>Returns true if successful, false if not</returns>
        public bool SendArrowKey(ArrowKey key, int holdDelay)
        {
            int  wParam;
            uint lParam;

            if (!CheckArrowKey(key, out wParam, out lParam))
            {
                return(false);
            }

            //Post the WM_KEYDOWN message, return false if unsuccessful
            if (_PostMessage(WowHWND, 0x100, wParam, lParam) == 0)
            {
                return(false);
            }

            //Sleep to emulate the delay you get when you hold a key down on your keyboard
            Thread.Sleep(50);

            //Loop until i >= delay specified in parameter 2
            for (int i = 1; i < holdDelay; i += 50)
            {
                //Post the WM_KEYDOWN message with the repeat flag turned on, return false if unsuccessful
                if (_PostMessage(WowHWND, 0x100, wParam, (lParam + 0x40000000)) == 0)
                {
                    return(false);
                }

                //Sleep for 1/20th of a second between posting the message
                Thread.Sleep(50);
            }

            //Post the WM_KEYUP message, return false if unsuccessful
            if (_PostMessage(WowHWND, 0x101, wParam, (lParam + 0xC0000000)) == 0)
            {
                return(false);
            }

            return(true);
        }
Example #9
0
    private Direction translateArrowDirection(ArrowKey key)
    {
        Direction buffer = Direction.NONE;

        if ((key & ArrowKey.LEFT) == ArrowKey.LEFT)
        {
            buffer |= Direction.WEST;
        }
        if ((key & ArrowKey.RIGHT) == ArrowKey.RIGHT)
        {
            buffer |= Direction.EAST;
        }
        if ((key & ArrowKey.UP) == ArrowKey.UP)
        {
            buffer |= Direction.NORTH;
        }
        if ((key & ArrowKey.DOWN) == ArrowKey.DOWN)
        {
            buffer |= Direction.SOUTH;
        }
        return(buffer);
    }
Example #10
0
 /// <summary>
 /// Retrieve lparam value for arrow key
 /// </summary>
 /// <param name="key">Arrow key</param>
 /// <returns>lparam value or 0 if key is unknown</returns>
 private uint GetArrowKeyCode(ArrowKey key)
 {
     //Set up lParam based upon which button needs pressing
     switch (key)
     {
         case ArrowKey.Left: return 0x14B0001;
         case ArrowKey.Up: return 0x1480001;
         case ArrowKey.Right: return 0x14D0001;
         case ArrowKey.Down: return 0x1500001;
         default: return 0;
     }
 }
Example #11
0
        /// <summary>
        /// Retrieve wparam and lparam for arrow key
        /// </summary>
        /// <param name="key">Arrow key</param>
        /// <param name="wparam">wParam value</param>
        /// <param name="lparam">lParam value</param>
        /// <returns>True if key valid and False if key invalid (unknown)</returns>
        private bool CheckArrowKey(ArrowKey key, out int wparam, out uint lparam)
        {
            wparam = (int)key;
            lparam = GetArrowKeyCode(key);
            if (lparam == 0)
                    return false;

            //If hWnd is 0 return false
            if (WowHWND <= 0)
                return false;

            return true;
        }
Example #12
0
        /// <summary>
        /// Holds down an arrow key for the specified time
        /// </summary>
        /// <param name="key">The arrow key to be send</param>
        /// <param name="holdDelay">Number of milliseconds to hold down key</param>
        /// <returns>Returns true if successful, false if not</returns>
        public bool SendArrowKey(ArrowKey key, int holdDelay)
        {
            int wParam;
            uint lParam;

            if (!CheckArrowKey(key, out wParam, out lParam))
                return false;

            //Post the WM_KEYDOWN message, return false if unsuccessful
            if (_PostMessage(WowHWND, 0x100, wParam, lParam) == 0)
                return false;

            //Sleep to emulate the delay you get when you hold a key down on your keyboard
            Thread.Sleep(50);

            //Loop until i >= delay specified in parameter 2
            for (int i = 1; i < holdDelay; i += 50)
            {
                //Post the WM_KEYDOWN message with the repeat flag turned on, return false if unsuccessful
                if (_PostMessage(WowHWND, 0x100, wParam, (lParam + 0x40000000)) == 0)
                    return false;

                //Sleep for 1/20th of a second between posting the message
                Thread.Sleep(50);
            }

            //Post the WM_KEYUP message, return false if unsuccessful
            if (_PostMessage(WowHWND, 0x101, wParam, (lParam + 0xC0000000)) == 0)
                return false;

            return true;
        }
Example #13
0
        /// <summary>
        /// Taps the specified arrow key. Send both UP and DOWN events
        /// with delay of 5 msec
        /// </summary>
        /// <param name="key">The arrow key to be send</param>
        /// <param name="release">True if send WM_KEYUP message as well</param>
        /// <returns>Returns true if successful, false if not</returns>
        public bool SendArrowKey(ArrowKey key)
        {
            if (!ArrowKeyDown(key))
                return false;

            //Sleep to let the window process the message
            Thread.Sleep(5);

            return ArrowKeyUp(key);
        }
Example #14
0
        /// <summary>
        /// Send WM_KEYUP event for arrow key
        /// </summary>
        /// <param name="key">Arrow key</param>
        /// <returns>True if WM_KEYUP message successfully sent and
        /// False if not</returns>
        public bool ArrowKeyUp(ArrowKey key)
        {
            uint lparam;
            int wparam;

            if (!CheckArrowKey(key, out wparam, out lparam))
                return false;

            //Post the WM_KEYUP message, return false if unsuccessful
            return (_PostMessage(WowHWND, 0x101,
                wparam, (lparam + 0xC0000000)) == 0);
        }
Example #15
0
        /// <summary>
        /// Send WM_KEYDOWN event for arrow key
        /// </summary>
        /// <param name="key">Arrow key</param>
        /// <returns>True if WM_KEYDOWN message successfully sent and
        /// False if not</returns>
        public bool ArrowKeyDown(ArrowKey key)
        {
            uint lparam;
            int wparam;

            if (!CheckArrowKey(key, out wparam, out lparam))
                return false;

            //Post the WM_KEYDOWN message, return false if unsuccessful
            return (_PostMessage(WowHWND, 0x100, wparam, lparam) == 0);
        }
Example #16
0
    private void handleKeyDown(object sender, KeyEventArgs e)
    {
        /*update key modifier*/
        p_CurrentKeys = e.KeyData;

        if (p_EventHijacker != null)
        {
            p_EventHijacker.OnKeyDown(this, e);
            return;
        }

        if (e.Modifiers != Keys.None)
        {
            return;
        }

        fogFuck(e.KeyCode);

        switch (e.KeyCode)
        {
        /*debug*/
        case Keys.Enter:
            debugPrompt();
            return;

        case Keys.F3:
            p_DebugLabel.Visible = true;
            p_DebugLabel.Enable();
            break;

        /* arrow key pressed?
         * note: by doing it this way, a player can press 2 keys to make the
         * player go diagonal.
         */
        case Keys.Left:
        case Keys.A:
            p_ArrowKeyDown |= ArrowKey.LEFT;
            break;

        case Keys.Right:
        case Keys.D:
            p_ArrowKeyDown |= ArrowKey.RIGHT;
            break;

        case Keys.Up:
        case Keys.W:
            p_ArrowKeyDown |= ArrowKey.UP;
            break;

        case Keys.Down:
        case Keys.S:
            p_ArrowKeyDown |= ArrowKey.DOWN;
            break;
        }

        //if logic is disabled, do not allow arrow keys but
        //the user might have entered debug mode
        if (p_LogicDisabled)
        {
            p_ArrowKeyDown = 0;
            return;
        }

        /*send to all UI elements*/
        int l = p_UIElements.Length;

        for (int c = 0; c < l; c++)
        {
            p_UIElements[c].OnKeyDown(this, e);
        }
    }