Example #1
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (WaitingForKey)
            {
                var pressedKeys = input.CurrentKeyboardState.GetPressedKeys();

                foreach (Keys key in pressedKeys)
                {
                    if (!input.IsNewKey(key))
                        continue;
                    if (key == Keys.Escape)
                    {
                        WaitingForKey = false;
                        OnKeySelectionFinished();
                        return;
                    }

                    Key = key;
                    WaitingForKey = false;
                    OnKeySelectionFinished();
                    return;
                }
            }
        }
Example #2
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            var pressedKeys = input.CurrentKeyboardState.GetPressedKeys();
            var shiftPressed = (input.CurrentKeyboardState.GetPressedKeys().Contains(Keys.LeftShift));

            foreach (Keys key in pressedKeys)
            {
                if (!input.IsNewKey(key))
                    continue;

                if (!Enabled) continue;

                if (key == Keys.Back)
                    InputText = InputText.Length > 1 ? InputText.Remove(InputText.Length - 1, 1) : string.Empty;
                else if (key == Keys.Space)
                    InputText = InputText.Insert(InputText.Length, " ");
                else if (key.IsDigit() || key.IsLetter())
                {
                    if (CaseKeeping == CaseKeeping.Lower || !shiftPressed)
                        InputText += key.ToString().ToLower();
                    else if (CaseKeeping == CaseKeeping.Upper || shiftPressed)
                        InputText += key.ToString().ToUpper();
                }

            }
        }