Exemplo n.º 1
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);

                    KeyPressed.Raise(this, args);

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

                    _previousKey   = key;
                    _lastPressTime = gameTime.TotalGameTime;
                    _isInitial     = true;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Handles the KeyPressed event of the <see cref="GameBase.RenderWindow"/>.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="SFML.Window.KeyEventArgs"/> instance containing the event data.</param>
 void rw_KeyPressed(object sender, KeyEventArgs e)
 {
     if (KeyPressed != null)
     {
         KeyPressed.Raise(this, e);
     }
 }
Exemplo n.º 3
0
Arquivo: Input.cs Projeto: ndech/Alpha
        public void Update(double delta)
        {
            // Truncate mouse position to screen dimensions
            Point position = _form.PointToClient(Cursor.Position);

            _mousePosition = new Vector2I(position.X, position.Y);
            MouseMoved.Raise(_mousePosition);

            MouseButtons buttons = Control.MouseButtons;
            bool         leftMouseButtonPressed = (buttons == MouseButtons.Left);

            if (leftMouseButtonPressed && !_previousMouseButtons[0])
            {
                MouseClicked.Raise(_mousePosition, 0);
            }
            else if (_previousMouseButtons[0] && !leftMouseButtonPressed)
            {
                MouseReleased.Raise(_mousePosition, 0);
            }
            _previousMouseButtons[0] = leftMouseButtonPressed;

            bool rightMouseButtonPressed = (buttons == MouseButtons.Right);

            if (rightMouseButtonPressed && !_previousMouseButtons[1])
            {
                MouseClicked.Raise(_mousePosition, 1);
            }
            else if (_previousMouseButtons[1] && !rightMouseButtonPressed)
            {
                MouseReleased.Raise(_mousePosition, 1);
            }
            _previousMouseButtons[1] = rightMouseButtonPressed;


            foreach (Key key in _keys.Cast <Key>().Where(key => key != Key.None))
            {
                if (Keyboard.IsKeyDown(key))
                {
                    if (_pressedKeys.ContainsKey(key))
                    {
                        _pressedKeys[key] += delta;
                        if (_pressedKeys[key] > 0.1)
                        {
                            _pressedKeys[key] = 0.0;
                            KeyPressed.Raise(key, InputInterop.GetCharFromKey(key), true);
                        }
                    }
                    else
                    {
                        _pressedKeys.Add(key, -0.9);
                        KeyPressed.Raise(key, InputInterop.GetCharFromKey(key), false);
                    }
                }
                else
                {
                    if (_pressedKeys.ContainsKey(key))
                    {
                        _pressedKeys.Remove(key);
                        KeyReleased.Raise(key);
                    }
                }
            }
        }
Exemplo n.º 4
0
 void MainInput_KeyPressed(object sender, EventArgs <ConsoleKeyInfo> e)
 {
     KeyPressed.Raise(this, e);
 }