Ejemplo 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;
                }
                }
            }
        }
Ejemplo n.º 2
0
        public void TestAddPressedKey()
        {
            var state = new KeyboardState();

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

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