Esempio n. 1
0
        // Update pressed keys
        private void UpdateInput()
        {
            OldKeyboardState     = CurrentKeyboardState;
            CurrentKeyboardState = Keyboard.GetState();

            Keys[] PressedKeys;
            PressedKeys = CurrentKeyboardState.GetPressedKeys();

            foreach (Keys Key in PressedKeys)
            {
                if (OldKeyboardState.IsKeyUp(Key))
                {
                    if (Key == Keys.Back && TextString.Length > 0) // backspace
                    {
                        TextString = TextString.Remove(TextString.Length - 1, 1);
                    }
                    else if (TextString.Length > 16)
                    {
                        break;
                    }
                    else if (Key == Keys.Space)
                    {
                        TextString = TextString.Insert(TextString.Length, " ");
                    }
                    else if (Key == Keys.OemQuotes) // apostrophe
                    {
                        TextString = TextString.Insert(TextString.Length, "\'");
                    }
                    else if (Key.ToString().Length == 1)
                    {
                        TextString += Key.ToString();
                    }
                }
            }
        }
Esempio n. 2
0
    public void UpdateInput()
    {
        if (!this.IsFinished)
        {
            oldKeyboardState     = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            Keys[] pressedKeys;
            pressedKeys = currentKeyboardState.GetPressedKeys();

            foreach (Keys key in pressedKeys)
            {
                if (oldKeyboardState.IsKeyUp(key))
                {
                    if (key == Keys.Back && TextString.Length > 0)
                    {
                        TextString = TextString.Remove(TextString.Length - 1, 1);
                    }
                    else if (key == Keys.Space)
                    {
                        TextString = TextString.Insert(TextString.Length, " ");
                    }
                    else if (key == Keys.Enter)
                    {
                        this.IsFinished = true;
                    }
                    else
                    {
                        string keyString   = key.ToString();
                        bool   isUpperCase = ((Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock) &&
                                               (!currentKeyboardState.IsKeyDown(Keys.RightShift) &&
                                                !currentKeyboardState.IsKeyDown(Keys.LeftShift))) ||
                                              (!Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock) &&
                                               (currentKeyboardState.IsKeyDown(Keys.RightShift) ||
                                                currentKeyboardState.IsKeyDown(Keys.LeftShift))));

                        if (keyString.Length == 1)
                        {
                            TextString += isUpperCase ? keyString.ToUpper() : keyString.ToLower();
                        }
                    }
                }
            }
        }
    }
Esempio n. 3
0
        public void TextEntered(TextEventArgs e)
        {
            if (HasFocus)
            {
                switch (e.Unicode[0])
                {
                case '\b':
                    if (TextString.Length > 0)
                    {
                        TextString = TextString.Remove(TextString.Length - 1, 1);
                    }
                    return;

                default:
                    if (CheckLength(e.Unicode))
                    {
                        TextString += e.Unicode;
                    }
                    break;
                }
            }
        }
Esempio n. 4
0
        protected override void OnKeyPressed(Reactive.KeyInput.Key pKey)
        {
            char newChar = pKey.Character;

            switch (pKey.KeysValue)
            {
            case Keys.Back:
                if (!string.IsNullOrEmpty(TextString) &&
                    _cursorPosition > 0)
                {
                    _cursorPosition = _cursorPosition - 1;
                    TextString      = TextString.Remove(_cursorPosition, 1);
                }
                break;

            case Keys.Delete:
                if (!string.IsNullOrEmpty(TextString) &&
                    TextString.Length > _cursorPosition)
                {
                    TextString = TextString.Remove(_cursorPosition, 1);
                }
                break;

            case Keys.Left:
                _cursorPosition = _cursorPosition > 0 ? _cursorPosition - 1 : 0;
                break;

            case Keys.Right:
                _cursorPosition = TextString.Length > _cursorPosition
                        ? _cursorPosition + 1
                        : _cursorPosition;
                break;

            case Keys.Home:
                _cursorPosition = 0;
                break;

            case Keys.End:
                _cursorPosition = TextString.Length;
                break;

            default:
                if ((int)pKey.Character >= 32)
                {
                    if (string.IsNullOrEmpty(TextString))
                    {
                        TextString = pKey.Character.ToString();
                    }
                    else
                    if (_cursorPosition == TextString.Length)
                    {
                        TextString = TextString + pKey.Character.ToString();
                    }
                    else
                    {
                        TextString = TextString.Insert(_cursorPosition, pKey.Character.ToString());
                    }
                    _cursorPosition++;
                }
                break;
            }
            ResetMillisecondTimer();
            SetCursorCoordinatesPosition();
        }