Exemplo n.º 1
0
        private void Events_KeyPressed(object sender, KeyboardEventArgs e)
        {
            if (e.Key != Keys.Enter || Controller.State == PlayState.Playing)
                return;

            Controller.Restart();
        }
Exemplo n.º 2
0
        private void RaisePressedEvents(GameTime gameTime, KeyboardState currentState)
        {
            if (!currentState.IsKeyDown(Keys.LeftAlt) && !currentState.IsKeyDown(Keys.RightAlt))
            {
                var pressedKeys = Enum.GetValues(typeof (Keys))
                    .Cast<Keys>()
                    .Where(key => currentState.IsKeyDown(key) && _previousState.IsKeyUp(key));

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

                    RaiseEvent(KeyPressed, args);

                    if (args.Character.HasValue)
                        RaiseEvent(KeyTyped, args);

                    _previousKey = key;
                    _lastPressTime = gameTime.TotalGameTime;
                    _isInitial = true;
                }
            }
        }
Exemplo n.º 3
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)
                    RaiseEvent(KeyTyped, args);

                _lastPressTime = gameTime.TotalGameTime;
                _isInitial = false;
            }
        }