Пример #1
0
        /// <summary>
        /// Takes keyboard input and returns certain characters as a string
        /// </summary>
        /// <param name="elapsedTime"></param>
        /// <returns></returns>
        private string GetStringFromKeyState(double elapsedTime)
        {
            bool shiftPressed = CurrentKeyState.IsKeyDown(Keys.LeftShift) || CurrentKeyState.IsKeyDown(Keys.RightShift);
            bool altPressed   = CurrentKeyState.IsKeyDown(Keys.LeftAlt) || CurrentKeyState.IsKeyDown(Keys.RightAlt);

            foreach (KeyBinding binding in KeyboardHelper.AmericanBindings)
            {
                if (KeyPressWithRepeat(binding.Key, elapsedTime))
                {
                    if (!shiftPressed && !altPressed)
                    {
                        return(binding.UnmodifiedString);
                    }
                    else if (shiftPressed && !altPressed)
                    {
                        return(binding.ShiftString);
                    }
                    else if (!shiftPressed && altPressed)
                    {
                        return(binding.AltString);
                    }
                    else if (shiftPressed && altPressed)
                    {
                        return(binding.ShiftAltString);
                    }
                }
            }

            return("");
        }
Пример #2
0
        public void HandleInput()
        {
            CurrentKeyState = Keyboard.GetState();

            if (!(CurrentKeyState.IsKeyDown(Keys.Right)) && !(CurrentKeyState.IsKeyDown(Keys.Left)))
            {
                //dir = 0;
                IsLeftPressed  = false;
                IsRightPressed = false;
                if (PlayerState != PLAYER_STATE.IDLE && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING)
                {
                    PlayerState = PLAYER_STATE.IDLE;
                }
            }

            if (CurrentKeyState.IsKeyDown(Keys.Right))
            {
                dir            = 1;
                IsLeftPressed  = false;
                IsRightPressed = true;
                if (Skeleton.FlipX == true)
                {
                    Skeleton.FlipX = false;
                }
                if (PlayerState != PLAYER_STATE.R_RUN && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING)
                {
                    PlayerState = PLAYER_STATE.R_RUN;
                }
            }
            else if (CurrentKeyState.IsKeyDown(Keys.Left))
            {
                dir            = -1;
                IsLeftPressed  = true;
                IsRightPressed = false;
                if (Skeleton.FlipX == false)
                {
                    Skeleton.FlipX = true;
                }
                if (PlayerState != PLAYER_STATE.L_RUN && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING)
                {
                    PlayerState = PLAYER_STATE.L_RUN;
                }
            }

            if (PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING &&
                CurrentKeyState.IsKeyDown(Keys.Z) && PrevKeyState.IsKeyUp(Keys.Z))
            {
                IsGrounded    = false;
                PlayerState   = PLAYER_STATE.JUMP;
                IsJumpPressed = true;
            }

            if (/*PlayerState == PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING
                 * && */CurrentKeyState.IsKeyUp(Keys.Z) && PrevKeyState.IsKeyDown(Keys.Z))
            {
                IsJumpPressed = false;
            }

            PrevKeyState = CurrentKeyState;
        }
Пример #3
0
 //check if a key is pressed, and repeat it at the default repeat rate
 private bool KeyPressWithRepeat(Keys key, double elapsedTime)
 {
     if (CurrentKeyState.IsKeyDown(key))
     {
         if (IsKeyPressed(key))
         {
             return(true);                   //if the key has just been pressed, it automatically counts
         }
         keyTimes[key] -= elapsedTime;       //count down to next repeat
         double keyTime = keyTimes[key];     //get the time left
         if (keyTimes[key] <= 0)             //if the time has run out, repeat the letter
         {
             keyTimes[key] = repeatInterval; //reset the timer to the repeat interval
             return(true);
         }
         else
         {
             return(false);
         }
     }
     //if the key is not pressed, reset it's time to the first interval, which is usually longer
     else
     {
         keyTimes[key] = firstInterval;
         return(false);
     }
 }
Пример #4
0
        public static bool IsButtonDown(Keys key)
        {
            bool down = false;

            if (CurrentKeyState.IsKeyDown(key))
            {
                down = true;
            }
            return(down);
        }
Пример #5
0
        public static bool GetKeyDown(Keys Key, KeyboardFlags keyboardFlags = KeyboardFlags.ANY)
        {
            bool BaseCond = CurrentKeyState.IsKeyDown(Key) && LastKeyState.IsKeyUp(Key);

            switch (keyboardFlags)
            {
            case KeyboardFlags.ANY:
                return(BaseCond);

            case KeyboardFlags.SOLO:
                return(BaseCond && Keyboard.GetState().IsKeyUp(Keys.LeftAlt) && Keyboard.GetState().IsKeyUp(Keys.LeftShift) && Keyboard.GetState().IsKeyUp(Keys.LeftControl));

            case KeyboardFlags.SHIFT:
                return(BaseCond && Keyboard.GetState().IsKeyDown(Keys.LeftShift));

            case KeyboardFlags.ALT:
                return(BaseCond && Keyboard.GetState().IsKeyDown(Keys.LeftAlt));

            default:
                return(BaseCond && Keyboard.GetState().IsKeyDown(Keys.LeftControl));
            }
        }
Пример #6
0
 //check if the key has just been pressed
 private bool IsKeyPressed(Keys key)
 {
     return(CurrentKeyState.IsKeyDown(key) && !LastKeyState.IsKeyDown(key));
 }
Пример #7
0
 public static bool KeyPressed(Keys key)
 {
     return(CurrentKeyState.IsKeyDown(key));
 }
Пример #8
0
 public static bool KeyDown(Keys key)
 {
     return(LastKeyState.IsKeyUp(key) && CurrentKeyState.IsKeyDown(key));
 }
Пример #9
0
 static bool IsKeyPressed(QKeyStates keyState)
 {
     return(CurrentKeyState.IsKeyDown((Keys)keyState) && PreviousKeyState.IsKeyUp((Keys)keyState));
 }
Пример #10
0
 static bool IsKeyHeld(QKeyStates keyState)
 {
     return(CurrentKeyState.IsKeyDown((Keys)keyState));
 }
Пример #11
0
 public static bool IsKeyPressed(Keys key)
 {
     return(PreviousKeyState.IsKeyUp(key) && CurrentKeyState.IsKeyDown(key));
 }