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


C# Keys.Contains方法代码示例

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


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

示例1: Convert

        public string Convert(Keys[] keys)
        {
            string output = "";
            bool usesShift = (keys.Contains(Keys.LeftShift) || keys.Contains(Keys.RightShift));

            foreach (Keys key in keys)
            {
                if (key >= Keys.A && key <= Keys.Z)
                    output += key.ToString();
                else if (key >= Keys.NumPad0 && key <= Keys.NumPad9)
                    output += ((int)(key - Keys.NumPad0)).ToString();
                else if (key >= Keys.D0 && key <= Keys.D9)
                {
                    string num = ((int)(key - Keys.D0)).ToString();
                    output += num;
                }
                else if(key == Keys.Space)
                {
                    output += " ";
                }
                else if(key == Keys.OemPeriod)
                {
                    output += ".";
                }

                if (!usesShift) output = output.ToLower();
            }
            return output;
        }
开发者ID:LuckiiGoggy,项目名称:COMP7051Assignment3,代码行数:29,代码来源:Console.cs

示例2: OnlyDigits

        /// <summary>
        /// Permite apenas numeros
        /// </summary>
        /// <param name="e"></param>
        public static void OnlyDigits(KeyEventArgs e)
        {
            Keys[] digits = new Keys[] { Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.NumPad0,
            Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9 };

            if (!digits.Contains(e.KeyData))
            {
                e.SuppressKeyPress = true;
            }
        }
开发者ID:rcarubbi,项目名称:Carubbi.Components,代码行数:14,代码来源:MaskHelper.cs

示例3: Move

 public void Move(Keys[] keys)
 {
     if (keys.Contains(Keys.Up) && keys.Contains(Keys.Right))
     {
         this.position.Y -= this.velocity / 2;
         this.position.X += this.velocity / 2;
     }
     else if (keys.Contains(Keys.Right) && keys.Contains(Keys.Down))
     {
         this.position.Y += this.velocity / 2;
         this.position.X += this.velocity / 2;
     }
     else if (keys.Contains(Keys.Down) && keys.Contains(Keys.Left))
     {
         this.position.Y += this.velocity / 2;
         this.position.X -= this.velocity / 2;
     }
     else if (keys.Contains(Keys.Left) && keys.Contains(Keys.Up))
     {
         this.position.Y -= this.velocity / 2;
         this.position.X -= this.velocity / 2;
     }
     else if (keys.Contains(Keys.Left))
     {
         this.position.X -= this.velocity;
     }
     else if (keys.Contains(Keys.Up))
     {
         this.position.Y -= this.velocity;
     }
     else if (keys.Contains(Keys.Down))
     {
         this.position.Y += this.velocity;
     }
     else if (keys.Contains(Keys.Right))
     {
         this.position.X += this.velocity;
     }
 }
开发者ID:srsebastian1s,项目名称:game-dev,代码行数:39,代码来源:GameObject.cs

示例4: KeyPressed

        public void KeyPressed(Keys[] pressedKeys)
        {
            if (pressedKeys.Length == 0) {
                nonePressed = true;
                upPressed = false;
                leftPressed = false;
                downPressed = false;
                rightPressed = false;
            } else {
                nonePressed = false;

                if (pressedKeys.Contains(Keys.W)) {
                    upPressed = true;
                } else {
                    upPressed = false;
                }

                if (pressedKeys.Contains(Keys.A)) {
                    leftPressed = true;
                } else {
                    leftPressed = false;
                }

                if (pressedKeys.Contains(Keys.S)) {
                    downPressed = true;
                } else {
                    downPressed = false;
                }

                if (pressedKeys.Contains(Keys.D)) {
                    rightPressed = true;
                } else {
                    rightPressed = false;
                }
            }
        }
开发者ID:GeordieP,项目名称:TopdownTileGame,代码行数:36,代码来源:Player.cs

示例5: TypeInto

        public void TypeInto(Keys[] keys)
        {
            m_text += Convert(keys);

            if(keys.Contains(Keys.Enter))
            {
                if (m_text.Length > 13 && m_text.Substring(0, 13) == "set bg color ")
                    CheckIfColor();
                if(m_text.Length > 13 && m_text.Substring(0, 13) == "set ball spd ")
                    CheckIfSpeed();
                if(m_text.Length >= 9 && m_text.Substring(0, 9) == "stop ball")
                    Game1.SetBallSpeed(0f);
            }
        }
开发者ID:LuckiiGoggy,项目名称:COMP7051Assignment3,代码行数:14,代码来源:Console.cs

示例6: KeyPressed

 internal void KeyPressed(Keys[] keys)
 {
     #region Player control keys
     if (keys.Contains(Keys.W)) player.PlayerPressedKey(Keys.W);
     if (keys.Contains(Keys.A)) player.PlayerPressedKey(Keys.A);
     if (keys.Contains(Keys.D)) player.PlayerPressedKey(Keys.D);
     if (keys.Contains(Keys.Q)) player.PlayerPressedKey(Keys.Q);
     if (keys.Contains(Keys.Escape)) game.states.setCurrentState(StateManager.State.Menu);
     if (keys.Contains(Keys.LeftShift)) player.SetSprinting(true);  // SHIFT - Sprint.
     else if (!keys.Contains(Keys.LeftShift)) player.SetSprinting(false); //Stop Sprint
     #endregion
 }
开发者ID:TheCodeOff,项目名称:TheGame,代码行数:12,代码来源:StateSingle.cs

示例7: Move

        private void Move(Keys[] keys)
        {
            if (IsOnGround() && (keys.Contains(Keys.Space) || keys.Contains(Keys.Up) || keys.Contains(Keys.W)))
            {
                Jump();
            }

            Directions lateralDirection = Directions.None;

            if (keys.Contains(Keys.Right) || keys.Contains(Keys.D))
            {
                lateralDirection |= Directions.Right;
            }

            if (keys.Contains(Keys.Left) || keys.Contains(Keys.A))
            {
                lateralDirection |= Directions.Left;
            }

            Move(lateralDirection);
        }
开发者ID:josiah1888,项目名称:game-dev,代码行数:21,代码来源:Player.cs

示例8: Convert

        public string Convert(Keys[] keys)
        {
            string output = "";
            bool usesShift = (keys.Contains(Keys.LeftShift) || keys.Contains(Keys.RightShift));

            foreach (Keys key in keys)
            {
                //thanks SixOfEleven @ DIC
                if (prevState.IsKeyUp(key))
                    continue;

                if (key >= Keys.A && key <= Keys.Z)
                    output += key.ToString();
                else if (key >= Keys.NumPad0 && key <= Keys.NumPad9)
                    output += ((int)(key - Keys.NumPad0)).ToString();
                else if (key >= Keys.D0 && key <= Keys.D9)
                {
                    string num = ((int)(key - Keys.D0)).ToString();
                    #region special num chars
                    if (usesShift)
                    {
                        switch (num)
                        {
                            case "1":
                                {
                                    num = "!";
                                }
                                break;
                            case "2":
                                {
                                    num = "@";
                                }
                                break;
                            case "3":
                                {
                                    num = "#";
                                }
                                break;
                            case "4":
                                {
                                    num = "$";
                                }
                                break;
                            case "5":
                                {
                                    num = "%";
                                }
                                break;
                            case "6":
                                {
                                    num = "^";
                                }
                                break;
                            case "7":
                                {
                                    num = "&";
                                }
                                break;
                            case "8":
                                {
                                    num = "*";
                                }
                                break;
                            case "9":
                                {
                                    num = "(";
                                }
                                break;
                            case "0":
                                {
                                    num = ")";
                                }
                                break;
                            default:
                                //wtf?
                                break;
                        }
                    }
                    #endregion
                    output += num;
                }
                else if (key == Keys.OemPeriod)
                    output += ".";
                else if (key == Keys.OemTilde)
                    output += "'";
                else if (key == Keys.Space)
                    output += " ";
                else if (key == Keys.OemMinus)
                    output += "-";
                else if (key == Keys.OemPlus)
                    output += "+";
                else if (key == Keys.OemQuestion && usesShift)
                    output += "?";
                else if (key == Keys.Back) //backspace
                    output += "\b";

                if (!usesShift) //shouldn't need to upper because it's automagically in upper case
                    output = output.ToLower();
            }
            return output;
//.........这里部分代码省略.........
开发者ID:Johanw123,项目名称:MonoPlatformerGame,代码行数:101,代码来源:KeyboardManager.cs

示例9: Fly

 public void Fly(Keys[] keys)
 {
     if (keys.Contains(Keys.Tab))
     {
         if (keys.Contains(Keys.Up) && keys.Contains(Keys.Right))
         {
             this.Position.Y -= this.FlightSpeeds.Y / 2;
             this.Position.X += this.FlightSpeeds.X / 2;
         }
         else if (keys.Contains(Keys.Right) && keys.Contains(Keys.Down))
         {
             this.Position.Y += this.FlightSpeeds.Y / 2;
             this.Position.X += this.FlightSpeeds.X / 2;
         }
         else if (keys.Contains(Keys.Down) && keys.Contains(Keys.Left))
         {
             this.Position.Y += this.FlightSpeeds.Y / 2;
             this.Position.X -= this.FlightSpeeds.X / 2;
         }
         else if (keys.Contains(Keys.Left) && keys.Contains(Keys.Up))
         {
             this.Position.Y -= this.FlightSpeeds.Y / 2;
             this.Position.X -= this.FlightSpeeds.X / 2;
         }
         else if (keys.Contains(Keys.Left))
         {
             this.Position.X -= this.FlightSpeeds.X;
         }
         else if (keys.Contains(Keys.Up))
         {
             this.Position.Y -= this.FlightSpeeds.Y;
         }
         else if (keys.Contains(Keys.Down))
         {
             this.Position.Y += this.FlightSpeeds.Y;
         }
         else if (keys.Contains(Keys.Right))
         {
             this.Position.X += this.FlightSpeeds.X;
         }
     }
 }
开发者ID:josiah1888,项目名称:game-dev,代码行数:42,代码来源:GameObject.cs

示例10: onKeys

 public static void onKeys(Keys[] pressedKeys)
 {
     if (pressedKeys.Contains(Keys.N) && !previousKeys.Contains(Keys.N))
     {
         //Do something if N was just pressed;
     }
     if (pressedKeys.Contains(Keys.G) && !previousKeys.Contains(Keys.G))
     {
         //Main.godMode = !Main.godMode; // not working atm
         //Main.player[Main.myPlayer].immune = true;
         if (Main.player[Main.myPlayer].immuneTime < 0) { Main.player[Main.myPlayer].immuneTime = 1000000; }
         // works, but dangerous, since immunetime <> 0 when taking hit
         else Main.player[Main.myPlayer].immuneTime = 0;
     }
     previousKeys = pressedKeys;
 }
开发者ID:Heloo88,项目名称:ModTerraria_Heloo,代码行数:16,代码来源:ModHooks.cs

示例11: SetKeys

                public HResult SetKeys(INiCommandBarButton button, Keys[] keys)
                {
                    try
                    {
                        if (button == null)
                            throw new ArgumentNullException("button");
                        if (keys == null)
                            throw new ArgumentNullException("keys");

                        foreach (var key in keys)
                        {
                            if (!ShortcutKeysUtil.IsValid(key))
                                throw new ArgumentException(String.Format("{0} is not a valid shortcut", key));
                        }

                        var id = button.Id;

                        List<Keys> currentKeys;
                        if (!_mappingsByButton.TryGetValue(id, out currentKeys))
                        {
                            currentKeys = new List<Keys>();
                            _mappingsByButton.Add(id, currentKeys);
                        }

                        // Remove the button from keys that are not set anymore.

                        foreach (var key in currentKeys)
                        {
                            if (!keys.Contains(key))
                            {
                                List<Guid> buttons;
                                if (_mappingsByKeys.TryGetValue(key, out buttons))
                                {
                                    bool removed = buttons.Remove(id);
                                    Debug.Assert(removed);
                                }
                                else
                                {
                                    Debug.Fail("Expected key to appear in mapping");
                                }
                            }
                        }

                        // Add the button to new keys.

                        foreach (var key in keys)
                        {
                            if (!currentKeys.Contains(key))
                            {
                                List<Guid> buttons;
                                if (!_mappingsByKeys.TryGetValue(key, out buttons))
                                {
                                    buttons = new List<Guid>();
                                    _mappingsByKeys.Add(key, buttons);
                                }

                                buttons.Add(id);
                            }
                        }

                        // Save the new key bindings.

                        currentKeys.Clear();
                        currentKeys.AddRange(keys);

                        // Update the new mappings with the new keys.

                        if (AreSameKeys(_keyboardMappingManager._initialKeys[id], keys))
                            Mappings.Remove(id);
                        else
                            Mappings[id] = keys.ToArray();

                        return HResult.OK;
                    }
                    catch (Exception ex)
                    {
                        return ErrorUtil.GetHResult(ex);
                    }
                }
开发者ID:netide,项目名称:netide,代码行数:79,代码来源:NiCommandManager.KeyboardMappings.cs

示例12: getMove

        private void getMove(KeyboardState keyState)
        {
            // If there is a selected tile.
            if (0 <= selectedTile.X && 0 <= selectedTile.Y) {
                // Keyboard
                Keys[] pressedKeys = keyState.GetPressedKeys();
                Keys[] numPadKeys = new Keys[] {Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4,
                                                Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8,
                                                Keys.NumPad9, Keys.NumPad0, Keys.D1, Keys.D2, Keys.D3, Keys.D4,
                                                Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.D0};

                for (int keyIndex = 0; keyIndex < pressedKeys.Length; ++keyIndex) {
                    if (keyState.IsKeyDown(pressedKeys[keyIndex]) && oldKeyState.IsKeyUp(pressedKeys[keyIndex])
                        && numPadKeys.Contains(pressedKeys[keyIndex])) {
                        int value = (Array.IndexOf(numPadKeys, pressedKeys[keyIndex]) % 10) + 1;

                        // Remove value from crossout.
                        if (pressedKeys.Contains(Keys.Space) && value != 10) {
                            // Remove value from crossout.
                            if (crossout[selectedTile].Contains(value)) {
                                crossout[selectedTile].Remove(value);
                            // Add value to crossout.
                            } else {
                                crossout[selectedTile].Add(value);
                            }
                            hasMoved = true;
                        // Change selected tile to value pressed.
                        } else if ((value == 10 || crossout[selectedTile].Contains(value) == false)
                            && curBoard.Original[selectedTile.X, selectedTile.Y] == 0) {
                            curBoard[selectedTile.X, selectedTile.Y] = value % 10;
                            hasMoved = true;
                        }
                    }
                }

                // Mouse
                for (int i = 0; i < moveBoardDest.GetLength(0); ++i) {
                    for (int j = 0; j < moveBoardDest.GetLength(1); ++j) {
                        // If right mouse clicked or left mouse + spacebar, then crossout value from possible values.
                        int value = moveBoard[i, j];

                        // Crossout value from possible values.
                        if ((moveBoardDest[i, j].Contains(lastClickedLeft) && pressedKeys.Contains(Keys.Space))
                            || moveBoardDest[i, j].Contains(lastClickedRight)) {
                            // If have value, remove value.
                            if (crossout[selectedTile].Contains(value)) {
                                crossout[selectedTile].Remove(value);
                            // Else, add value.
                            } else {
                                crossout[selectedTile].Add(value);
                            }
                        // Change selected tile to value pressed.
                        } else if (moveBoardDest[i, j].Contains(lastClickedLeft)
                            && crossout[selectedTile].Contains(value) == false
                            && curBoard.Original[selectedTile.X, selectedTile.Y] == 0) {
                            curBoard[selectedTile.X, selectedTile.Y] = value;
                        }
                    }
                }
            }
        }
开发者ID:Eternyte,项目名称:Sudoku,代码行数:61,代码来源:Sudoku.cs

示例13: ManagePlayerStates

        public void ManagePlayerStates(Character player, Keys[] pressedkeys, int stagelimit)
        {
            if (player.HasState(State.DYING))
                return;

            if (player.CurrentHealth <= 0 || player.Position.Y > stagelimit)
            {
                player.CurrentHealth = 0;
                player.AddState(State.ALIVE);
                player.AddState(State.DYING);
                return;
            }

            int dx = 0, dy = 0;
            //Here we manage Horizontal movement
            if (pressedkeys.Contains<Keys>(Keys.Left))
            {
                dx -= 5;
                player.RemoveState(State.FACERIGHT);
                player.AddState(State.FACELEFT);
                player.AddState(State.MOVING);
            }
            else if (pressedkeys.Contains<Keys>(Keys.Right))
            {
                dx += 5;
                player.RemoveState(State.FACELEFT);
                player.AddState(State.FACERIGHT);
                player.AddState(State.MOVING);
            }
            else
                player.RemoveState(State.MOVING);

            //Here we manage vertical movement based on jumping actions
            if (pressedkeys.Contains<Keys>(Keys.Up))
            {
                if (player.HasState(State.JUMPING))
                {
                    if (player.Position.Y < player.MaxHeight)
                    {
                        dy = (int)player.Position.Y - player.MaxHeight;
                        player.RemoveState(State.JUMPING);
                        player.AddState(State.FALLING);
                    }
                    else
                        dy -= 15;
                }
                if (player.HasState(State.STANDING))
                {
                    player.MaxHeight = ((int)player.Position.Y - 200);
                    if (player.MaxHeight < 0)
                        player.MaxHeight = 0;
                    player.RemoveState(State.STANDING);
                    player.AddState(State.JUMPING);
                    dy -= 3;
                }
            }
            else
            {
                if (player.HasState(State.JUMPING))
                {
                    player.AddState(State.FALLING);
                    player.RemoveState(State.JUMPING);
                }
            }

            dy += 5;
            player.Move(dx, dy);
        }
开发者ID:ruxeom,项目名称:Kirby,代码行数:68,代码来源:StateManager.cs

示例14: IsValidChar

        bool IsValidChar(Keys key)
        {
            Keys[] invalid = new Keys[] {
                Keys.Left, Keys.Right, Keys.Up, Keys.Down,
                Keys.Back, Keys.Delete, Keys.BrowserBack, Keys.LeftShift,
                Keys.LeftAlt, Keys.LeftControl, Keys.LeftWindows, Keys.Enter,
                Keys.Escape, Keys.RightAlt
            };

            if (invalid.Contains(key)) return false;

            char c = KeyCodeToChar(key);
            return !Char.IsControl(c);
        }
开发者ID:Bunkerbewohner,项目名称:Mathcraft,代码行数:14,代码来源:TextInputComponent.cs

示例15: Update

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

            if (show)
            {
                if (kbd.IsKeyDown(Keys.C) && prevKbd.IsKeyUp(Keys.C) && kbd.IsKeyDown(Keys.LeftControl))
                {
                    Close();
                    return;
                }

                if (cursor_blink < CURSOR_BLINK_DELAY_MS)
                    cursor_blink += gameTime.ElapsedGameTime.Milliseconds;

                if (cursor_blink > CURSOR_BLINK_DELAY_MS)
                {
                    drawCursor = !drawCursor;
                    cursor_blink = 0;
                }

                if (kbd.IsKeyDown(Keys.Left) && prevKbd.IsKeyUp(Keys.Left))
                    cursorOffset = Math.Max(0, cursorOffset - 1);
                else if (kbd.IsKeyDown(Keys.Right) && prevKbd.IsKeyUp(Keys.Right))
                    cursorOffset = Math.Min(inputBuffer.Length, cursorOffset + 1);
                else if (IsPressed(Keys.Up))
                {
                    int started = cursorOffset;
                    while (cursorOffset > inputBuffer.Length - 1) cursorOffset--;
                    while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n')
                        cursorOffset--;

                    int lineOffset = started - cursorOffset;
                    if (cursorOffset > 0) cursorOffset--;
                    while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n')
                        cursorOffset--;

                    cursorOffset += lineOffset;
                }
                else if (IsPressed(Keys.Down))
                {
                    int started = cursorOffset;
                    while (cursorOffset > inputBuffer.Length - 1) cursorOffset--;
                    while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n')
                        cursorOffset--;

                    int lineOffset = started - cursorOffset;

                    cursorOffset = Math.Min(inputBuffer.Length - 1, cursorOffset + lineOffset + 1);
                    while (cursorOffset < inputBuffer.Length - 1 && inputBuffer[cursorOffset] != '\n')
                        cursorOffset++;

                    cursorOffset = Math.Min(cursorOffset + lineOffset, inputBuffer.Length - 1);
                }
                else if (IsPressed(Keys.End))
                {
                    while (cursorOffset < inputBuffer.Length - 1 && inputBuffer[cursorOffset] != '\n')
                        cursorOffset++;
                }
                else if (IsPressed(Keys.Home))
                {
                    while (cursorOffset > inputBuffer.Length - 1) cursorOffset--;
                    while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n')
                        cursorOffset--;
                }
                else if (IsPressed(Keys.F5))
                {
                    var result = eval.Evaluate(inputBuffer.ToString());
                    if (result.Success) Close();

                    lastResult = result;
                }
                else
                {
                    Keys[] keys = kbd.GetPressedKeys();

                    if (keys.Length > 0 && (int)keys[0] > 0 || keys.Length > 1)
                    {
                        Keys[] skip = new Keys[] { Keys.LeftShift, Keys.LeftControl, Keys.LeftAlt, Keys.None };
                        Keys key = (from k in keys where !skip.Contains(k) && prevKbd.IsKeyUp(k) select k).FirstOrDefault();

                        bool shift = kbd.IsKeyDown(Keys.LeftShift);
                        bool alt = kbd.IsKeyDown(Keys.RightAlt);

                        if (IsPressed(Keys.Delete))
                        {
                            if (kbd.IsKeyDown(Keys.LeftControl))
                            {
                                cursorOffset = 0;
                                inputBuffer.Clear();
                            }
                            else if (cursorOffset >= 0 && cursorOffset < inputBuffer.Length)
                            {
                                inputBuffer.Remove(cursorOffset, 1);
                            }
                        }
                        else if (IsPressed(Keys.Back))
                        {
                            if (inputBuffer.Length >= 0 && cursorOffset > 0)
                            {
//.........这里部分代码省略.........
开发者ID:Bunkerbewohner,项目名称:Mathcraft,代码行数:101,代码来源:TextInputComponent.cs


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