Exemple #1
0
        /// <summary>
        /// Base method handles keyboard input for the entry.  Override to add custom
        /// behavior.
        /// </summary>
        protected internal override void OnKeyPressed(KeyboardData keyData)
        {
            base.OnKeyPressed(keyData);

            if (keyData.Character != 0 &&
                ValidateCharacter(keyData.Character))
            {
                if (_waitingToOverwrite)
                {
                    TextInput           = keyData.Character.ToString();
                    CursorPos           = 1;
                    _waitingToOverwrite = false;
                }
                else if (TextInput.Length < MaximumCharacters)
                {
                    TextInput += keyData.Character;
                    CursorPos++;
                }
            }
            else if (keyData.KeyCode == TCODKeyCode.Backspace &&
                     TextInput.Length > 0)
            {
                TextInput = TextInput.Substring(0, TextInput.Length - 1);
                CursorPos--;
            }
            else if (keyData.KeyCode == TCODKeyCode.Enter)
            {
                _waitingToCommitText = true;
                ParentWindow.ReleaseKeyboard(this);
            }
            else if (keyData.KeyCode == TCODKeyCode.Escape)
            {
                TextInput            = CurrentText;
                _waitingToCommitText = true;
                ParentWindow.ReleaseKeyboard(this);
            }
        }