Exemplo n.º 1
0
        /// <summary>Updates the state of the input device</summary>
        /// <remarks>
        ///   <para>
        ///     If this method is called with no snapshots in the queue, it will take
        ///     an immediate snapshot and make it the current state. This way, you
        ///     can use the input devices without caring for the snapshot system if
        ///     you wish.
        ///   </para>
        ///   <para>
        ///     If this method is called while one or more snapshots are waiting in
        ///     the queue, this method takes the next snapshot from the queue and makes
        ///     it the current state.
        ///   </para>
        /// </remarks>
        public void Update()
        {
            while (this.queuedEvents.Count > 0)
            {
                KeyboardEvent nextEvent = this.queuedEvents.Dequeue();
                switch (nextEvent.EventType)
                {
                case EventType.KeyRelease: {
                    KeyboardStateHelper.RemovePressedKey(ref this.current, (int)nextEvent.Key);
                    OnKeyReleased(nextEvent.Key);
                    break;
                }

                case EventType.KeyPress: {
                    KeyboardStateHelper.AddPressedKey(ref this.current, (int)nextEvent.Key);
                    OnKeyPressed(nextEvent.Key);
                    break;
                }

                case EventType.Character: {
                    OnCharacterEntered(nextEvent.Character);
                    break;
                }

                case EventType.Snapshot: {
                    return;
                }
                }
            }
        }
Exemplo n.º 2
0
        public void TestRemovedPressedKey()
        {
            var state = new KeyboardState(Keys.A, Keys.B, Keys.C, Keys.D);

            KeyboardStateHelper.RemovePressedKey(ref state, (int)Keys.A);
            KeyboardStateHelper.RemovePressedKey(ref state, (int)Keys.C);

            Assert.IsFalse(state.IsKeyDown(Keys.A));
            Assert.IsTrue(state.IsKeyDown(Keys.B));
            Assert.IsFalse(state.IsKeyDown(Keys.C));
            Assert.IsTrue(state.IsKeyDown(Keys.D));
        }