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


C# KeyboardState类代码示例

本文整理汇总了C#中KeyboardState的典型用法代码示例。如果您正苦于以下问题:C# KeyboardState类的具体用法?C# KeyboardState怎么用?C# KeyboardState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Update

        protected override void Update(TimeSpan gameTime)
        {
            input = WaveServices.Input;

            if (input.KeyboardState.IsConnected)
            {
                keyboardState = input.KeyboardState;

                if (keyboardState.W == ButtonState.Pressed)
                {
                    MoveCamera(ref forward);
                }
                if (keyboardState.S == ButtonState.Pressed)
                {
                    MoveCamera(ref back);
                }
                if (keyboardState.A == ButtonState.Pressed)
                {
                    MoveCamera(ref left);
                }
                if (keyboardState.D == ButtonState.Pressed)
                {
                    MoveCamera(ref right);
                }
            }
            var rotationMatrix = (Matrix.CreateRotationX(MathHelper.ToRadians(45.0f)) * Matrix.CreateRotationY(MathHelper.ToRadians(30.0f)));
            Vector3 transformedReference = Vector3.Transform(Vector3.Down, rotationMatrix);
            Vector3 cameraLookat = Camera.Position + transformedReference;
            var width = WaveServices.Platform.ScreenWidth / 24;
            var height = WaveServices.Platform.ScreenHeight / 24;

            //camera.Projection = Matrix.CreateOrthographic(width, height, camera.NearPlane, camera.FarPlane);
            Camera.LookAt = cameraLookat;
        }
开发者ID:123asd123A,项目名称:Samples,代码行数:34,代码来源:IsometricCameraBehavior.cs

示例2: Keyboard

 public Keyboard()
 {
     var directInput = new DirectInput();
     mKeyboard = new SlimDX.DirectInput.Keyboard(directInput);
     mKeyboard.Acquire();
     mState = new KeyboardState();
 }
开发者ID:Christof,项目名称:ionfish,代码行数:7,代码来源:Keyboard.cs

示例3: Move

        //Methods from IMovable
        public void Move(KeyboardState keyBoardState)
        {
            keyBoardState = Keyboard.GetState();

            this.Velocity = Vector2.Zero;

            if (keyBoardState.IsKeyDown(Keys.Up))
            {
                this.velocity.Y = -movementSpeed.Y;
            }
            if (keyBoardState.IsKeyDown(Keys.Left))
            {
                this.velocity.X = -movementSpeed.X;
            }
            if (keyBoardState.IsKeyDown(Keys.Down))
            {
                this.velocity.Y = movementSpeed.Y;
            }
            if (keyBoardState.IsKeyDown(Keys.Right))
            {
                this.velocity.X = movementSpeed.X;
            }

            this.Position += this.velocity;
        }
开发者ID:juliameleshko,项目名称:Franz-Kafka,代码行数:26,代码来源:Hero.cs

示例4: Update

        /// <summary>
        /// Update Method
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;

            // if (this.input.KeyboardState.IsConnected)
            {
                this.keyboardState = this.input.KeyboardState;

                if (revoluteJoint != null)
                {
                    // A, D, S Keyboard Control (left, right, stop motor)
                    if (this.keyboardState.A == ButtonState.Pressed)
                    {
                        if (revoluteJoint.MotorSpeed + motorSpeed <= maxSpeed)
                        {
                            revoluteJoint.MotorSpeed += motorSpeed;
                        }
                    }
                    else if (this.keyboardState.D == ButtonState.Pressed)
                    {
                        if (revoluteJoint.MotorSpeed - motorSpeed >= -maxSpeed)
                        {
                            revoluteJoint.MotorSpeed -= motorSpeed;
                        }
                    }
                    else if (this.keyboardState.S == ButtonState.Pressed)
                    {
                        revoluteJoint.MotorSpeed = 0.0f;
                    }
                }
            }
        }
开发者ID:nagyistoce,项目名称:WaveEngine-Samples,代码行数:36,代码来源:MotorBehavior.cs

示例5: Update

        /// <summary>
        /// Allows this instance to execute custom logic during its <c>Update</c>.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
            inputService = WaveServices.Input;

            if (inputService.KeyboardState.IsConnected)
            {
                // Key F1
                if (inputService.KeyboardState.F1 == ButtonState.Pressed &&
                    beforeKeyboardState.F1 != ButtonState.Pressed)
                {
                    this.diagnostics = !this.diagnostics;
                    WaveServices.ScreenContextManager.SetDiagnosticsActive(this.diagnostics);
                }

                // Key F3
                if (inputService.KeyboardState.F3 == ButtonState.Pressed &&
                    beforeKeyboardState.F3 != ButtonState.Pressed)
                {
                    this.debugLines = !this.debugLines;
                    this.Scene.RenderManager.DebugLines = this.debugLines;
                }
            }

            beforeKeyboardState = inputService.KeyboardState;
        }
开发者ID:sgrizan,项目名称:Samples,代码行数:32,代码来源:DebugSceneBehavior.cs

示例6: HandleInput

        public void HandleInput(MouseState mouseState, KeyboardState keyboardState)
        {
            KeyboardState = keyboardState;

            if (MouseOverRenderArea && mouseState.LeftButton == ButtonState.Pressed)
            {
                if (!MouseDragging)
                {
                    MouseDragging = true;
                    MousePreviousPosition = new Vector2(mouseState.X, mouseState.Y);
                }

                var mouseNewCoords = new Vector2(mouseState.X, mouseState.Y);

                MouseDelta.X = mouseNewCoords.X - MousePreviousPosition.X;
                MouseDelta.Y = mouseNewCoords.Y - MousePreviousPosition.Y;

                MousePreviousPosition = mouseNewCoords;
            }

            if (!MouseOverRenderArea || mouseState.LeftButton == ButtonState.Released)
            {
                MouseDragging = false;
            }
        }
开发者ID:SteamDatabase,项目名称:ValveResourceFormat,代码行数:25,代码来源:Camera.cs

示例7: KeyboardInputProcessor

        public KeyboardInputProcessor()
        {
            _previousKeyboardState = new KeyboardState();
            _currentKeyboardState = new KeyboardState();

            KeyDictionary = new KeyDictionary();
        }
开发者ID:HaKDMoDz,项目名称:ProceduralGeneration,代码行数:7,代码来源:KeyboardInputProcessor.cs

示例8: Update

        public void Update(KeyboardState keyboardState)
        {
            _previousKeyboardState = _currentKeyboardState;
            _currentKeyboardState = keyboardState;

            KeyDictionary.Update(keyboardState);
        }
开发者ID:HaKDMoDz,项目名称:ProceduralGeneration,代码行数:7,代码来源:KeyboardInputProcessor.cs

示例9: Poll

        /// <summary>
        /// Check input device without check Floor Height 
        /// </summary>
        public void Poll()
        {
            KeyState = KeyBoardDevice.GetCurrentKeyboardState();
            KeyBoardJOBs();

            MState = MouseDevice.CurrentMouseState;
            MouseJOBs();
        }
开发者ID:Behzadkhosravifar,项目名称:Museum-3D,代码行数:11,代码来源:InputToolBox.cs

示例10: KeyboardMapBuilder

 internal KeyboardMapBuilder(IVirtualKeyboard virtualKeyboard)
 {
     _virtualKeyboard = virtualKeyboard;
     _keyboard = _virtualKeyboard.KeyboardState;
     _lookedForOem1ModifierVirtualKey = _keyboard.Oem1ModifierVirtualKey.HasValue;
     _lookedForOem2ModifierVirtualKey = _keyboard.Oem2ModifierVirtualKey.HasValue;
     _possibleModifierVirtualKey = new Lazy<List<uint>>(GetPossibleVirtualKeyModifiers);
 }
开发者ID:nligerakis,项目名称:VsVim,代码行数:8,代码来源:KeyboardMapBuilder.cs

示例11: Poll

        /// <summary>
        /// Check input device with check Floor Height 
        /// </summary>
        /// <param name="vFloor"></param>
        public void Poll(ref Microsoft.DirectX.Direct3D.CustomVertex.PositionTextured[] vFloor)
        {
            _vFloor = vFloor;
            KeyState = KeyBoardDevice.GetCurrentKeyboardState();
            KeyBoardJOBs();

            MState = MouseDevice.CurrentMouseState;
            MouseJOBs();
        }
开发者ID:Behzadkhosravifar,项目名称:Room-3D,代码行数:13,代码来源:InputToolBox.cs

示例12: Keyboard

 internal Keyboard(DKeyboard keyboard)
 {
     System.Diagnostics.Debug.Assert(keyboard != null);
     _dKeyboard = keyboard;
     _inputState = KeyboardInput.CreateEmpty();
     _lastPressedKeys = new List<Key>();
     (_timer = new GameTimer()).Start();
     _currentDirectInputState = new KeyboardState();
 }
开发者ID:sleepless1,项目名称:GameSharp,代码行数:9,代码来源:Keyboard.cs

示例13: InputKeyBoard_KeyEvent

        void InputKeyBoard_KeyEvent(KeyboardState keyNewState, KeyboardState keyOldState)
        {
            if (keyNewState.IsKeyDown(Keys.Escape) && keyOldState.IsKeyUp(Keys.Escape)) game.Exit();

            if (keyNewState.IsKeyDown(Keys.Up) && keyOldState.IsKeyUp(Keys.Up)) game.Window.Title = "Up";
            if (keyNewState.IsKeyDown(Keys.Down) && keyOldState.IsKeyUp(Keys.Down)) game.Window.Title = "Down";
            if (keyNewState.IsKeyDown(Keys.Left) && keyOldState.IsKeyUp(Keys.Left)) game.Window.Title = "Left";
            if (keyNewState.IsKeyDown(Keys.Right) && keyOldState.IsKeyUp(Keys.Right)) game.Window.Title = "Right";
        }
开发者ID:bharathi355,项目名称:davethegame,代码行数:9,代码来源:InputTest.cs

示例14: Update

        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;
            if (this.input.KeyboardState.IsConnected)
            {
                this.keyboardState = this.input.KeyboardState;

                RigidBody2D rigidBody = Owner.FindComponent<RigidBody2D>();
                if (rigidBody != null)
                {
                    // W, A, S, D applies Directional Linear Impulses
                    Vector2 result = Vector2.Zero;
                    if (keyboardState.A == ButtonState.Pressed)
                    {
                        result += leftDirection;
                    }
                    if (keyboardState.D == ButtonState.Pressed)
                    {
                        result -= leftDirection;
                    }
                    if (keyboardState.W == ButtonState.Pressed)
                    {
                        result += topDirection;
                    }
                    if (keyboardState.S == ButtonState.Pressed)
                    {
                        result -= topDirection;
                    }
                 
                    // Apply Linear Impulse
                    if (result != Vector2.Zero)
                    {
                        rigidBody.ApplyLinearImpulse(result);
                    }

                    // Left and Right arrow applies angular impulse
                    if (keyboardState.Left == ButtonState.Pressed)
                    {
                        rigidBody.ApplyAngularImpulse(-angularImpulse);
                    }
                    else if (keyboardState.Right == ButtonState.Pressed)
                    {
                        rigidBody.ApplyAngularImpulse(angularImpulse);
                    }

                    // J and K applies Torque
                    if (keyboardState.J == ButtonState.Pressed)
                    {
                        rigidBody.ApplyTorque(torque);
                    }
                    else if (keyboardState.K == ButtonState.Pressed)
                    {
                        rigidBody.ApplyTorque(-torque);
                    }
                }
            }
        }
开发者ID:123asd123A,项目名称:Samples,代码行数:57,代码来源:ForceBehavior.cs

示例15: InputSystem

 public InputSystem()
 {
     CurrentKeyboardState = new KeyboardState();
     PreviousKeyboardState = new KeyboardState();
     CurrentGamepadState = new GamePadState();
     PreviousGamepadState = new GamePadState();
     CurrentMouseState = new MouseState();
     PreviousMouseState = new MouseState();
 }
开发者ID:jasongdove,项目名称:MonoGameEngine,代码行数:9,代码来源:InputSystem.cs


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