コード例 #1
0
        void MoveKeyPress(Movements btn, bool press)
        {
            // Handling each if separately allows sending All for key up when connection lost
            // For each key, check if it's requested and that the state isn't already set
            if (btn.Has(Movements.Backward) && _moveFlag.Has(Movements.Backward) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.S, System.Windows.Input.ModifierKeys.None, press);
            }
            if (btn.Has(Movements.Left) && _moveFlag.Has(Movements.Left) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.A, System.Windows.Input.ModifierKeys.None, press);
            }
            if (btn.Has(Movements.Right) && _moveFlag.Has(Movements.Right) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.D, System.Windows.Input.ModifierKeys.None, press);
            }
            if (btn.Has(Movements.LeftStrafe) && _moveFlag.Has(Movements.LeftStrafe) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.Q, System.Windows.Input.ModifierKeys.None, press);
            }
            if (btn.Has(Movements.RightStrafe) && _moveFlag.Has(Movements.RightStrafe) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.E, System.Windows.Input.ModifierKeys.None, press);
            }
            if (btn.Has(Movements.Forward) && _moveFlag.Has(Movements.Forward) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.W, System.Windows.Input.ModifierKeys.None, press);
            }
            if (btn.Has(Movements.Up) && _moveFlag.Has(Movements.Up) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.Space, System.Windows.Input.ModifierKeys.None, press);
            }
            if (btn.Has(Movements.Down) && _moveFlag.Has(Movements.Down) != press)
            {
                UnsafeWin32Calls.SendKeyClick(System.Windows.Input.Key.X, System.Windows.Input.ModifierKeys.None, press);
            }

            // Update the flags
            if (press)
            {
                _moveFlag.Add(btn);
            }
            else
            {
                _moveFlag.Remove(btn);
            }
        }