示例#1
0
 public static bool Dismiss(bool doMouse = true, bool doKeyBoard = true, bool doGamePad = true)
 {
     if (Core.GameInstance.IsActive)
     {
         if (doKeyBoard)
         {
             if (KeyBoardHandler.KeyPressed(Core.KeyBindings.Back1) || KeyBoardHandler.KeyPressed(Core.KeyBindings.Back2))
             {
                 return(true);
             }
         }
         if (doMouse)
         {
             if (MouseHandler.ButtonPressed(MouseHandler.MouseButtons.RightButton))
             {
                 return(true);
             }
         }
         if (doGamePad)
         {
             if (ControllerHandler.ButtonPressed(Buttons.B))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#2
0
 public static bool Accept(bool doMouse = true, bool doKeyBoard = true, bool doGamePad = true)
 {
     if (Core.GameInstance.IsActive)
     {
         if (doKeyBoard)
         {
             if (KeyBoardHandler.KeyPressed(Core.KeyBindings.Enter1) || KeyBoardHandler.KeyPressed(Core.KeyBindings.Enter2))
             {
                 return(true);
             }
         }
         if (doMouse)
         {
             if (MouseHandler.ButtonPressed(MouseHandler.MouseButtons.LeftButton))
             {
                 return(true);
             }
         }
         if (doGamePad)
         {
             if (ControllerHandler.ButtonPressed(Buttons.A))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#3
0
        public static bool CtrlPressed(string pressedFlag = "LR", bool triggerButtons = true)
        {
            // TODO
            //if (System.Windows.Forms.Control.ModifierKeys == (System.Windows.Forms.Keys.Control || System.Windows.Forms.Keys.Alt))
            //{
            //    return false;
            //}
            if (pressedFlag.Contains("L") && KeyBoardHandler.KeyDown(Keys.LeftControl))
            {
                return(true);
            }
            if (pressedFlag.Contains("L") && ControllerHandler.ButtonDown(Buttons.LeftTrigger) && triggerButtons)
            {
                return(true);
            }
            if (pressedFlag.Contains("R") && KeyBoardHandler.KeyDown(Keys.RightControl))
            {
                return(true);
            }
            if (pressedFlag.Contains("R") && ControllerHandler.ButtonDown(Buttons.RightTrigger) && triggerButtons)
            {
                return(true);
            }

            return(false);
        }
示例#4
0
 public static bool Down(bool pressed, bool arrowKeys = true, bool scroll = true, bool wasd = true, bool thumbStick = true, bool dPad = true)
 {
     if (Core.GameInstance.IsActive)
     {
         if (MouseHandler.WindowContainsMouse && scroll)
         {
             if (MouseHandler.GetScrollWheelChange() < 0)
             {
                 return(true);
             }
         }
         if (pressed)
         {
             return(CheckDirectionalPress(PressDirections.Down, Core.KeyBindings.BackwardMove, Core.KeyBindings.Down, Buttons.LeftThumbstickDown, Buttons.DPadDown, arrowKeys, wasd, thumbStick, dPad));
         }
         if (wasd)
         {
             if (KeyBoardHandler.KeyDown(Core.KeyBindings.BackwardMove))
             {
                 return(true);
             }
         }
         if (arrowKeys)
         {
             if (KeyBoardHandler.KeyDown(Core.KeyBindings.Down))
             {
                 return(true);
             }
         }
         if (thumbStick)
         {
             if (ControllerHandler.ButtonDown(Buttons.LeftThumbstickDown))
             {
                 return(true);
             }
         }
         if (dPad)
         {
             if (ControllerHandler.ButtonDown(Buttons.DPadDown))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#5
0
 public static bool ShiftPressed(string pressedFlag = "LR", bool triggerButtons = true)
 {
     if (pressedFlag.Contains("L") && KeyBoardHandler.KeyPressed(Keys.LeftShift))
     {
         return(true);
     }
     if (pressedFlag.Contains("L") && ControllerHandler.ButtonPressed(Buttons.LeftTrigger) && triggerButtons)
     {
         return(true);
     }
     if (pressedFlag.Contains("R") && KeyBoardHandler.KeyPressed(Keys.RightShift))
     {
         return(true);
     }
     if (pressedFlag.Contains("R") && ControllerHandler.ButtonPressed(Buttons.RightTrigger) && triggerButtons)
     {
         return(true);
     }
     return(false);
 }
示例#6
0
        public static bool HasKeyboardInput()
        {
            Keys[] keyArr =
            {
                Core.KeyBindings.ForwardMove,
                Core.KeyBindings.LeftMove,
                Core.KeyBindings.BackwardMove,
                Core.KeyBindings.RightMove,
                Core.KeyBindings.Up,
                Core.KeyBindings.Left,
                Core.KeyBindings.Down,
                Core.KeyBindings.Right
            };
            foreach (Keys key in keyArr)
            {
                if (KeyBoardHandler.KeyPressed(key))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#7
0
        /// <summary>
        /// Gets keyboard inputs.
        /// </summary>
        /// <param name="whiteKeys">All keys that allow a valid return. If the list is empty, all keys are allowed by default.</param>
        /// <param name="blackKeys">All keys that are not allowed for a valid return. If this list is empty, all keys are allowed by default.</param>
        /// <param name="text">The current text that this function adds text to.</param>
        /// <param name="maxLength">The maximum length of the text. -1 means infinite length.</param>
        /// <param name="triggerShift">Checks if the Shift variant of a key gets considered.</param>
        /// <param name="triggerAlt">Checks if the Alt variant of a key gets considered.</param>
        public static string GetInput(Keys[] whiteKeys, Keys[] blackKeys, ref string text, int maxLength = -1, bool triggerShift = true, bool triggerAlt = true)
        {
            var keys = KeyBoardHandler.GetPressedKeys;

            foreach (var key in keys)
            {
                if (key == Keys.V && KeyBoardHandler.KeyPressed(Keys.V) && (KeyBoardHandler.KeyDown(Keys.LeftControl) || KeyBoardHandler.KeyDown(Keys.RightControl)))
                {
                    // TODO
                    // OSX clipboard http://stackoverflow.com/questions/28611112/mono-clipboard-fix
                    if (Clipboard.ContainsText())
                    {
                        text += Clipboard.GetText();
                    }
                }
                else
                {
                    if (key != Keys.Back)
                    {
                        if (!KeyBlocked(whiteKeys, blackKeys, key))
                        {
                            char c;
                            if (TryConvertKeyboardInput(key, KeyBoardHandler.KeyDown(Keys.LeftShift) || KeyBoardHandler.KeyDown(Keys.RightShift), out c))
                            {
                                if (_holdDelay <= 0f && _holdKey == key)
                                {
                                    text += c.ToString(NumberFormatInfo.InvariantInfo);
                                }
                                else
                                {
                                    if (KeyBoardHandler.KeyPressed(key))
                                    {
                                        text += c.ToString(NumberFormatInfo.InvariantInfo);

                                        _holdKey   = key;
                                        _holdDelay = 3f;
                                    }
                                }
                            }
                        }
                    }
                    if (key == Keys.Back && !KeyBlocked(whiteKeys, blackKeys, Keys.Back))
                    {
                        if (_holdDelay <= 0f && _holdKey == key)
                        {
                            if (text.Length > 0)
                            {
                                text = text.Remove(text.Length - 1, 1);
                            }
                        }
                        else
                        {
                            if (KeyBoardHandler.KeyPressed(key))
                            {
                                if (text.Length > 0)
                                {
                                    text = text.Remove(text.Length - 1, 1);
                                }

                                _holdKey   = key;
                                _holdDelay = 3f;
                            }
                        }
                    }
                }
            }

            if (KeyBoardHandler.KeyUp(_holdKey))
            {
                _holdDelay = 3f;
            }
            else
            {
                _holdDelay -= 0.1f;
                if (_holdDelay <= 0f)
                {
                    _holdDelay = 0f;
                }
            }

            if (maxLength > -1)
            {
                while (text.Length > maxLength)
                {
                    text = text.Remove(text.Length - 1, 1);
                }
            }

            return(text);
        }
示例#8
0
        private static bool CheckDirectionalPress(PressDirections direction, Keys wasdKey, Keys directionalKey, Buttons thumbStickDirection, Buttons dPadDirecion, bool arrowKeys, bool wasd, bool thumbStick, bool dPad)
        {
            bool command = false;

            if (wasd)
            {
                if (KeyBoardHandler.KeyDown(wasdKey))
                {
                    command = true;
                    if (HoldDownPress(direction))
                    {
                        return(true);
                    }
                    if (KeyBoardHandler.KeyPressed(wasdKey))
                    {
                        ChangeDirectionPressed(direction);
                        return(true);
                    }
                }
            }
            if (arrowKeys)
            {
                if (KeyBoardHandler.KeyDown(directionalKey))
                {
                    command = true;
                    if (HoldDownPress(direction))
                    {
                        return(true);
                    }
                    if (KeyBoardHandler.KeyPressed(directionalKey))
                    {
                        ChangeDirectionPressed(direction);
                        return(true);
                    }
                }
            }
            if (thumbStick)
            {
                if (ControllerHandler.ButtonDown(thumbStickDirection))
                {
                    command = true;
                    if (HoldDownPress(direction))
                    {
                        return(true);
                    }
                    if (ControllerHandler.ButtonPressed(thumbStickDirection))
                    {
                        ChangeDirectionPressed(direction);
                        return(true);
                    }
                }
            }
            if (dPad)
            {
                if (ControllerHandler.ButtonDown(dPadDirecion))
                {
                    command = true;
                    if (HoldDownPress(direction))
                    {
                        return(true);
                    }
                    if (ControllerHandler.ButtonPressed(dPadDirecion))
                    {
                        ChangeDirectionPressed(direction);
                        return(true);
                    }
                }
            }

            if (command == false)
            {
                ResetDirectionPressed(direction);
            }

            return(false);
        }