当前位置: 首页>>代码示例>>C#>>正文


C# KeyboardState.GetPressedKeys方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Input.KeyboardState.GetPressedKeys方法的典型用法代码示例。如果您正苦于以下问题:C# KeyboardState.GetPressedKeys方法的具体用法?C# KeyboardState.GetPressedKeys怎么用?C# KeyboardState.GetPressedKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Input.KeyboardState的用法示例。


在下文中一共展示了KeyboardState.GetPressedKeys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

 public void Update()
 {
     if (doInitDelay)
     {
         initialDelay--;
     }
     if (initialDelay <= 0)
     {
         doInitDelay = false;
         currentCommand = new NullCommand();
         keyboardState = Keyboard.GetState();
         foreach (Keys key in keyboardState.GetPressedKeys())
         {
             if (commandLibrary.ContainsKey(key))
             {
                 currentCommand = commandLibrary[key];
                 currentCommand.Execute();
                 break;
             }
         }
         if (keyboardState.GetPressedKeys().Length == 0)
         {
             player.Idle();
         }
     }
 }
开发者ID:buttsj,项目名称:CSharpMon,代码行数:26,代码来源:KeyboardController.cs

示例2: SetKeyboardState

 public void SetKeyboardState(KeyboardState ob)
 {
     if(ob.GetPressedKeys().Length>0)
         switch (ob.GetPressedKeys()[0])
         {
                 case Keys.W:
                     direction = GameObjects.Sprites.Direction.Up;
                     action = GameObjects.Sprites.Action.Walking;
                     break;
                 case Keys.A:
                     direction = GameObjects.Sprites.Direction.Left;
                     action = GameObjects.Sprites.Action.Walking;
                     break;
                 case Keys.S:
                     direction = GameObjects.Sprites.Direction.Down;
                     action = GameObjects.Sprites.Action.Walking;
                     break;
                 case Keys.D:
                     direction = GameObjects.Sprites.Direction.Right;
                     action = GameObjects.Sprites.Action.Walking;
                     break;
                 default:
                     action = GameObjects.Sprites.Action.Standing;
                     break;
         }
     if (!ob.GetPressedKeys().Contains(Keys.W) &&
         !ob.GetPressedKeys().Contains(Keys.A) &&
         !ob.GetPressedKeys().Contains(Keys.S) &&
         !ob.GetPressedKeys().Contains(Keys.D))
     {
         action = GameObjects.Sprites.Action.Standing;
     }
 }
开发者ID:Dzm2012,项目名称:_AnimalArmy,代码行数:33,代码来源:Sprites.cs

示例3: Update

        public void Update(KeyboardState Tastenstatus, ref string Text)
        {
            if (SchreibModus == true)
            {
                Lastposition = Text.Length;

                if (Tastenstatus.IsKeyDown(Keys.LeftShift))
                {
                    Großschreiben = true;
                    if (Tastendruck == true && Tastenstatus.GetPressedKeys().Length == 1)
                    {
                        Tastendruck = false;
                    }
                }
                else
                {
                    Großschreiben = false;
                    if (Tastendruck == true && Tastenstatus.GetPressedKeys().Length == 0)
                    {
                        Tastendruck = false;
                    }
                }
                if (Tastenstatus.IsKeyDown(Keys.Back) && Lastposition > 0 && Tastendruck == false)
                {
                    Text = Text.Remove(Lastposition - 1, 1);
                    Tastendruck = true;
                }
                if (Lastposition <= MaxAnzahlZeichen)
                {
                    Keys[] currentlyPressed = Tastenstatus.GetPressedKeys();
                    List<string> allowedChars = new List<string>(AllowedChars);
                    foreach (Keys key in currentlyPressed)
                    {

                        Buchstabe = key.ToString();
                        if (Buchstabe.Length == 2)
                        {
                            Buchstabe = Buchstabe.Remove(0, 1);
                        }
                        if (allowedChars.Contains(Buchstabe.ToLower()) && Tastendruck == false)
                        {
                            Tastendruck = true;
                            if (Großschreiben == true)
                            {
                                Text += Buchstabe.ToUpper();
                            }
                            else
                            {
                                Text += Buchstabe.ToLower();
                            }
                        }
                    }
                }
            }
        }
开发者ID:Rosthouse,项目名称:Multi-Pac,代码行数:55,代码来源:Texteingabe.cs

示例4: HandleInput

        public override void HandleInput(GameTime time)
        {
            //throw new NotImplementedException();
            newState = Keyboard.GetState();

            Keys[] newDown = newState.GetPressedKeys();
            Keys[] oldDown = oldState.GetPressedKeys();

            foreach(Keys k in oldDown)
            {
                if(!newDown.Contains(k))
                {
                    if(k == Keys.Back)
                    {
                        if (text.Length > 0) text = text.Substring(0, text.Length - 1);
                    }
                    else if(k == Keys.Space)
                    {
                        text += " ";
                    }
                    else
                    {
                        text += k.ToString();
                    }
                }
            }

            oldState = newState;
        }
开发者ID:Olink,项目名称:XNAGui,代码行数:29,代码来源:TextField.cs

示例5: UpdateInput

        public static void UpdateInput()
        {
            oldKeyboardState = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            Keys[] pressedKeys;
            pressedKeys = currentKeyboardState.GetPressedKeys();

            foreach (Keys key in pressedKeys)
            {
                if( oldKeyboardState.IsKeyUp(key) )
                {
                    if (key == Keys.Back) // overflows
                    {
                        if (textString.Length > 0)
                        textString = textString.Remove(textString.Length - 1, 1);
                    }
                    else if (key == Keys.Space)
                        textString = textString.Insert(textString.Length, " ");
                    else if (key == Keys.Enter)
                    {
                        Command = textString;
                        InputParser.Update();
                        textString = String.Empty;
                    }
                    else
                        textString += key.ToString();
                }
            }
        }
开发者ID:Crysco,项目名称:Invasion,代码行数:30,代码来源:InputDisplay.cs

示例6: Update

        public void Update(GameTime time)
        {
            oldState = currentState;
            currentState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            shiftDown = currentState.IsKeyDown(Keys.LeftShift) || currentState.IsKeyDown(Keys.RightShift);

            currentlyPressed = currentState.GetPressedKeys();
            previouslyPressed = oldState.GetPressedKeys();

            if (currentlyPressed.Length != previouslyPressed.Length)
            {
                keyHoldTimer = 0.0f;
                keyHeld = false;
                lastKeyHeld = FindLastKeyPressed();
            }

            if (!keyHeld && currentlyPressed.Length > 0)
            {
                keyHoldTimer += (float)time.ElapsedGameTime.TotalMilliseconds;
                if (keyHoldTimer > keyHoldWait)
                {
                    keyHeld = true;
                }
            }
        }
开发者ID:idaohang,项目名称:Helicopter-Autopilot-Simulator,代码行数:25,代码来源:UIKeyboard.cs

示例7: ReturnDigitORNumberKeyAsChar

        public List<char> ReturnDigitORNumberKeyAsChar(KeyboardState keyboardstate, KeyboardState oldKeyboardstate)
        {
            List<char> chars = new List<char>();
            char c;
            bool shift = false;
            if (keyboardstate.IsKeyDown(Keys.LeftShift) || keyboardstate.IsKeyDown(Keys.RightShift))
                shift = true;

            foreach (Keys a in keyboardstate.GetPressedKeys())
            {
                if (oldKeyboardstate.IsKeyUp(a) && a != Keys.RightShift && a != Keys.LeftShift)
                {
                    int i = a.GetHashCode();
                    c = (char)i;
                    if (Char.IsLetterOrDigit(c))
                        if (shift)
                            chars.Add(c);
                        else
                            chars.Add(Convert.ToChar(c.ToString().ToLower()));

                }
            }

            return chars;
        }
开发者ID:steffan88,项目名称:Bevelle,代码行数:25,代码来源:KeyboardHelper.cs

示例8: Initialize

        public static void Initialize()
        {
            previousState = currentState = Keyboard.GetState();

            previousKeySet = new HashSet<Keys>(currentState.GetPressedKeys());
            keyListeners = new HashSet<KeyListener>();
        }
开发者ID:johnfn,项目名称:Illumination,代码行数:7,代码来源:KeyController.cs

示例9: Update

        public void Update(KeyboardState state)
        {
            Keys[] pressed = state.GetPressedKeys();
              List<Keys> toRemove = new List<Keys>();
              List<Keys> toRelease = new List<Keys>();
              foreach (KeyValuePair<Keys, AdvancedKeyState> key in States) {
            if (!pressed.Contains(key.Key)) {
              if (key.Value == AdvancedKeyState.Pressed ||
              key.Value == AdvancedKeyState.Down) {
            toRelease.Add(key.Key);
              } else if (key.Value == AdvancedKeyState.Released) {
            toRemove.Add(key.Key);
              }
            }
              }
              foreach (var release in toRelease) {
            States[release] = AdvancedKeyState.Released;
            FireEvent(release);
              }
              foreach (var remove in toRemove)
            States.Remove(remove);

              foreach (var key in pressed) {
            if (!States.ContainsKey(key) ||
            States[key] == AdvancedKeyState.Released) {
              States[key] = AdvancedKeyState.Pressed;
              FireEvent(key);
            } else if (States[key] == AdvancedKeyState.Pressed) {
              States[key] = AdvancedKeyState.Down;
            }
              }
        }
开发者ID:SenojLuap,项目名称:GameUtility,代码行数:32,代码来源:AdvancedKeyboard.cs

示例10: TypeText

        public static string TypeText(KeyboardState oldState, KeyboardState newState, string text, int maxchars, string def)
        {
            Keys[] oldKeys = oldState.GetPressedKeys();
            Keys[] newKeys = newState.GetPressedKeys();

            foreach (Keys key in oldKeys)
            {
                if (!newKeys.Contains(key))
                {
                    if (key == Keys.Back)
                    {
                        if (text.Length > 0)
                            text = text.Remove(text.Length - 1);
                    }
                    else if (text.Length <= maxchars)
                    {
                        if (key == Keys.Space)
                        {
                            text += "_";
                        }
                        else if (key.ToString().Length == 1)
                        {
                            if (text == def)
                                text = "";

                            text += key.ToString();
                        }
                    }
                }
            }
            return text;
        }
开发者ID:Tzbob,项目名称:TakGu,代码行数:32,代码来源:InputUtility.cs

示例11: getState

        public static void getState()
        {
            oldTeclado = teclado;
            oldMouse = mouse;
            teclado = Keyboard.GetState();
            mouse = Mouse.GetState();

            Keys[] keys = teclado.GetPressedKeys();

            foreach (Keys keyPressed in keys)
            {
                if (!keysPressed.Contains(keyPressed))
                {
                    keysPressed.Add(keyPressed);
                }
            }

            foreach (Keys keyPressed in keysPressed)
            {
                if (teclado.IsKeyUp(keyPressed))
                {
                    keysPressed.Remove(keyPressed);
                    break;
                }
            }
        }
开发者ID:BGCX262,项目名称:zumbi-game-svn-to-git,代码行数:26,代码来源:InputController.cs

示例12: Update

        public void Update(GameTime gameTime, KeyboardState keyState)
        {
            if (IsAtive)
            {
                #region Change of direction
                if (keyState.GetPressedKeys().Contains(KeyLeft))
                {
                    this.Direction += DirectionSpeed * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                }
                if (keyState.GetPressedKeys().Contains(KeyRight))
                {

                    this.Direction -= DirectionSpeed * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                } 
                #endregion

                Vector2 newPosition = ActualPosition + new Vector2((float)Math.Sin(Direction) * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds, (float)Math.Cos(Direction) * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds);
                float Distance = Vector2.Distance(newPosition, Positions[Positions.Count - 1]);
                if (SpaceParts <= 0)
                {
                    for (int i = (int)(Distance / PartsDistance); i > 0; i--)
                    {
                        Vector2 newPart = Positions[Positions.Count - 1] + new Vector2((float)Math.Sin(Direction) * PartsDistance, (float)Math.Cos(Direction) * PartsDistance);
                        Positions.Add(newPart);
                    }
                }
                else
                {
                    SpaceParts--;
                    if (SpaceParts == 0)
                    {
                        Positions.Add(ActualPosition);
                    }
                }

                ActualPosition = newPosition;

                #region Spaces
                SpaceTime -= gameTime.ElapsedGameTime.TotalMilliseconds;
                if (SpaceTime <= 0)
                {
                    SpaceParts = SpacePartsMax;
                    SpaceTime = 2000 + Nahoda.Next(0, 3000);
                }  
                #endregion
            }
        }
开发者ID:M4ch,项目名称:TestProj,代码行数:47,代码来源:Player.cs

示例13: DevInput

 private static void DevInput(MouseState mouse, KeyboardState keyboard)
 {
     if (keyboard.GetPressedKeys().Contains(Keys.Space))
     {
         Camera.Position.X = 0;
         Camera.Position.Z = 0;
     }
 }
开发者ID:Ascendzor,项目名称:Viper,代码行数:8,代码来源:Input.cs

示例14: CalculateKeyDownMessages

 private void CalculateKeyDownMessages(KeyboardState newKeyState)
 {
     var keys = newKeyState.GetPressedKeys().Where(key => !_oldKeyState.IsKeyDown(key));
     foreach (var key in keys)
     {
         _messageManager.QueueMessage(new KeyDownMessage(key));
     }
 }
开发者ID:jolson88,项目名称:Hiromi,代码行数:8,代码来源:KeyboardInputHandler.cs

示例15: Update

        public override void Update(GameTime gameTime)
        {
            keyOldState = keyNewState;
            keyNewState = Keyboard.GetState();

            if ((Game.IsActive && (keyNewState.GetPressedKeys().Length > 0 || keyOldState.GetPressedKeys().Length > 0) && KeyEvent != null))
                KeyEvent(keyNewState, keyOldState);
        }
开发者ID:bharathi355,项目名称:davethegame,代码行数:8,代码来源:InputKeyBoard.cs


注:本文中的Microsoft.Xna.Framework.Input.KeyboardState.GetPressedKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。