Exemplo n.º 1
0
        public static bool WasBindDown(KeyBinding bind)
        {
            if (oldButtonState == null || oldKeyState == null)
                return false;

            if (oldKeyState.IsKeyDown(bind.key) || oldButtonState.IsButtonDown(bind.button))
                return true;

            return false;
        }
Exemplo n.º 2
0
        public static bool IsPressed(KeyBinding bind)
        {
            bool pressed = false;

            if (curButtonState.IsButtonDown(bind.button) && oldButtonState != null)
            {
                if (oldButtonState.IsButtonDown(bind.button))
                    pressed = false;
                else
                    pressed = true;
            }
            else if (curButtonState.IsButtonDown(bind.button))
                pressed = true;

            if (curKeyState.IsKeyDown(bind.key) && oldKeyState != null)
            {
                if (oldKeyState.IsKeyDown(bind.key))
                    pressed = false;
                else
                    pressed = true;
            }
            else if (curKeyState.IsKeyDown(bind.key))
                pressed = true;

            if (pressed == true)
                bind.repeatDelay = KeyBinding.REPEAT_DELAY;

            return pressed;
        }
Exemplo n.º 3
0
        public static bool IsPressedRepeatable(KeyBinding bind)
        {
            bool isTriggered = false;
            DateTime oldTime = bind.lastPressed;
            DateTime newTime = DateTime.Now;
            TimeSpan span = newTime - oldTime;

            int remainingDelay = 0;
            if (bind.repeatDelay > 0)
                remainingDelay = bind.repeatDelay - (int)span.TotalMilliseconds;
            if (remainingDelay <= 0)
                bind.repeatDelay = 0;

            if (IsPressed(bind))
            {
                bind.lastPressed = DateTime.Now;
                return true;
            }
            else
            {
                if (IsBindDown(bind) && oldButtonState != null)
                {
                    if (WasBindDown(bind))
                    {
                        if (remainingDelay <= 0)
                        {
                            if (span.TotalMilliseconds >= REPEAT)
                            {
                                isTriggered = true;
                                bind.lastPressed = DateTime.Now;
                            }
                            else
                                isTriggered = false;
                        }
                    }
                    else
                    {
                        isTriggered = true;
                        bind.lastPressed = DateTime.Now;
                    }
                }
                else if (IsBindDown(bind))
                {
                    isTriggered = true;
                    bind.lastPressed = DateTime.Now;
                }
            }

            return isTriggered;
        }
Exemplo n.º 4
0
        public static bool IsBindDown(KeyBinding bind)
        {
            if (curKeyState.IsKeyDown(bind.key) || curButtonState.IsButtonDown(bind.button))
                return true;

            return false;
        }