示例#1
0
        private void RaisePressedEvents(GameTime gameTime, KeyboardState currentState)
        {
            if (!currentState.IsKeyDown(Key.AltLeft) && !currentState.IsKeyDown(Key.AltRight))
            {
                var pressedKeys = Enum.GetValues(typeof(Key))
                                  .Cast <Key>()
                                  .Where(key => currentState.IsKeyDown(key) && _previousState.IsKeyUp(key));

                foreach (var key in pressedKeys)
                {
                    var args = new KeyboardEventArgs(key, currentState);

                    KeyPressed?.Invoke(this, args);

                    if (args.Character.HasValue)
                    {
                        KeyTyped?.Invoke(this, args);
                    }

                    _previousKey   = key;
                    _lastPressTime = gameTime.TotalGameTime;
                    _isInitial     = true;
                }
            }
        }
示例#2
0
        private void RaiseRepeatEvents(GameTime gameTime, KeyboardState currentState)
        {
            var elapsedTime = (gameTime.TotalGameTime - _lastPressTime).TotalMilliseconds;

            if (currentState.IsKeyDown(_previousKey) && ((_isInitial && elapsedTime > InitialDelay) || (!_isInitial && elapsedTime > RepeatDelay)))
            {
                var args = new KeyboardEventArgs(_previousKey, currentState);

                if (args.Character.HasValue)
                {
                    KeyTyped.Raise(this, args);
                }

                _lastPressTime = gameTime.TotalGameTime;
                _isInitial     = false;
            }
        }
示例#3
0
 protected virtual void OnKeyTyped(char c) => KeyTyped?.Invoke(c);
示例#4
0
 private void WindowOnKeyPress(object sender, KeyPressEventArgs e)
 {
     KeyTyped?.Invoke(e.KeyChar);
 }
示例#5
0
文件: Input.cs 项目: Perksey/Mana
 internal static void OnKeyTyped(char c)
 {
     KeyTyped?.Invoke(c);
 }