예제 #1
0
파일: InputManager.cs 프로젝트: mrvux/xenko
        private void UpdateKeyboard()
        {
            pressedKeysSet.Clear();
            releasedKeysSet.Clear();
            KeyEvents.Clear();

            lock (KeyboardInputEvents)
            {
                foreach (KeyboardInputEvent keyboardInputEvent in KeyboardInputEvents)
                {
                    var key = keyboardInputEvent.Key;

                    if (key == Keys.None)
                    {
                        continue;
                    }

                    switch (keyboardInputEvent.Type)
                    {
                    case InputEventType.Down:
                        if (!IsKeyDown(key))     // prevent from several inconsistent pressed key due to OS repeat key
                        {
                            activeKeys[key] = true;
                            if (!keyboardInputEvent.OutOfFocus)
                            {
                                pressedKeysSet.Add(key);
                                KeyEvents.Add(new KeyEvent(key, KeyEventType.Pressed));
                            }
                            downKeysList.Add(key);
                        }
                        break;

                    case InputEventType.Up:
                        activeKeys[key] = false;
                        releasedKeysSet.Add(key);
                        KeyEvents.Add(new KeyEvent(key, KeyEventType.Released));
                        downKeysList.Remove(key);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                KeyboardInputEvents.Clear();
            }

            if (LostFocus)
            {
                // Release keys/buttons when control focus is lost (this prevents some keys getting stuck when a focus loss happens)
                foreach (var key in downKeysList)
                {
                    releasedKeysSet.Add(key);
                    KeyEvents.Add(new KeyEvent(key, KeyEventType.Released));
                }
                activeKeys.Clear();
                downKeysList.Clear();
            }
        }
예제 #2
0
        /// <summary>
        /// Clears all relative states
        /// </summary>
        public void Clear()
        {
            KeyEvents.Clear();
            MouseEvents.Clear();
            KeyCharPresses.Clear();

            WheelDelta = 0.0f;

            Events.Clear();

            KeysDownThisFrame.Clear();
            MouseButtonsDownThisFrame.Clear();
        }
예제 #3
0
        private void UpdateKeyboard()
        {
            pressedKeysSet.Clear();
            releasedKeysSet.Clear();
            KeyEvents.Clear();

            lock (KeyboardInputEvents)
            {
                foreach (KeyboardInputEvent keyboardInputEvent in KeyboardInputEvents)
                {
                    var key = keyboardInputEvent.Key;

                    if (key == Keys.None)
                    {
                        continue;
                    }

                    switch (keyboardInputEvent.Type)
                    {
                    case InputEventType.Down:
                        if (!IsKeyDown(key))     // prevent from several inconsistent pressed key due to OS repeat key
                        {
                            activeKeys[key] = true;
                            pressedKeysSet.Add(key);

                            KeyEvents.Add(new KeyEvent(key, KeyEventType.Pressed));
                            downKeysList.Add(key);
                        }
                        break;

                    case InputEventType.Up:
                        activeKeys[key] = false;
                        releasedKeysSet.Add(key);
                        KeyEvents.Add(new KeyEvent(key, KeyEventType.Released));
                        downKeysList.Remove(key);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                KeyboardInputEvents.Clear();
            }

            if (LostFocus)
            {
                activeKeys.Clear();
                downKeysList.Clear();
            }
        }