Esempio n. 1
0
        /// <summary>
        /// The action to be taken when a button on the T9 grid is pressed.
        /// </summary>
        /// <param name="obj">The parameter passed into the command</param>
        public void ButtonClick(object obj)
        {
            if (obj is ActionEnum)
            {
                ActionEnum enumValue = (ActionEnum)obj;
                switch (enumValue)
                {
                case ActionEnum.Backspace:
                    if (!PredictiveMode && TypedText.Length > 0)
                    {
                        // Delete a character if there are characters to delete
                        if (_keyTimer.Enabled)
                        {
                            TempText          = String.Empty;
                            _keyTimer.Enabled = false;
                        }
                        else
                        {
                            TypedText = TypedText.Substring(0, TypedText.Length - 1);
                        }
                    }
                    else if (PredictiveMode)
                    {
                        // Is there temporary text?
                        if (TempText.Length > 0)
                        {
                            // Erase the last regex and get a new word
                            _predictiveHandler.DropLastRegex();
                            if (_predictiveHandler.Regex.Length > 0)
                            {
                                TempText = _predictiveHandler.NextMatch();
                            }
                            else
                            {
                                TempText = String.Empty;
                            }
                        }
                        else
                        {
                            if (TypedText[TypedText.Length - 1] == ' ')
                            {
                                // Delete the last word
                                TypedText = TypedText.TrimEnd();
                                int endOfLastWord = TypedText.LastIndexOf(' ');
                                TypedText = TypedText.Substring(0, endOfLastWord + 1);
                            }
                        }
                    }
                    break;

                case ActionEnum.InsertSpace:
                    if (PredictiveMode)
                    {
                        // Append the temporary text and a space
                        AppendTempText();
                        TypedText += " ";

                        // Clear the regex
                        _predictiveHandler.Regex = null;
                    }
                    else
                    {
                        // Insert a space, clear out the last key stuff
                        AppendTempText();
                        TypedText        += " ";
                        _lastPressedIndex = 0;
                        _lastPressedKey   = null;
                    }
                    break;

                case ActionEnum.NextWord:
                    // This key only does something if we're in predictive mode
                    if (PredictiveMode)
                    {
                        // Grab the next matching word
                        TempText = _predictiveHandler.NextMatch();
                    }
                    break;
                }
            }
            else
            {
                if (PredictiveMode)
                {
                    // Process the predictive key press
                    PredictiveButtonPress(obj as string);
                }
                else
                {
                    // Process the non-predictive keypress
                    NonPredictiveButtonPress(obj as string);
                }
            }
        }
Esempio n. 2
0
        private void UpdateText()
        {
            var keyboard        = Keyboard.GetState();
            int shiftDifference = 0;

            if (keyboard.IsKeyDown(Keys.LeftShift))
            {
                shiftDifference = 32;
            }
            if (keyboard.IsKeyDown(Keys.Q))
            {
                this.TextInField += (char)('q' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.W))
            {
                this.TextInField += (char)('w' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.E))
            {
                this.TextInField += (char)('e' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.R))
            {
                this.TextInField += (char)('r' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.T))
            {
                this.TextInField += (char)('t' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.Y))
            {
                this.TextInField += (char)('y' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.U))
            {
                this.TextInField += (char)('u' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.I))
            {
                this.TextInField += (char)('i' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.O))
            {
                this.TextInField += (char)('o' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.P))
            {
                this.TextInField += (char)('p' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.A))
            {
                this.TextInField += (char)('a' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.S))
            {
                this.TextInField += (char)('s' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.D))
            {
                this.TextInField += (char)('d' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.F))
            {
                this.TextInField += (char)('f' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.G))
            {
                this.TextInField += (char)('g' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.H))
            {
                this.TextInField += (char)('h' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.J))
            {
                this.TextInField += (char)('j' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.K))
            {
                this.TextInField += (char)('k' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.L))
            {
                this.TextInField += (char)('l' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.Z))
            {
                this.TextInField += (char)('z' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.X))
            {
                this.TextInField += (char)('x' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.C))
            {
                this.TextInField += (char)('c' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.V))
            {
                this.TextInField += (char)('v' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.B))
            {
                this.TextInField += (char)('b' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.N))
            {
                this.TextInField += (char)('n' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.M))
            {
                this.TextInField += (char)('m' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.Back) && TextInField.Length > 0)
            {
                this.TextInField = TextInField.Substring(0, TextInField.Length - 1);
                TypedText.TrimEnd();
                if (TypedText.Length > TextInField.Length)
                {
                    this.TypedText       = TextInField;
                    this.TypedTextLength = TextInField.Length;
                }
            }
        }