예제 #1
0
        char Delete()
        {
            if (CurrentTextRun == null)
            {
                return('\0');
            }
            else
            {
                if (CharIndex < 0)
                {
                    return('\0');
                }

                char        toBeRemovedChar = CurrentChar;
                EditableRun removingTextRun = CurrentTextRun;
                int         removeIndex     = CurrentTextRunCharIndex;
                CharIndex--;
                EditableRun.InnerRemove(removingTextRun, removeIndex, 1, false);
                if (removingTextRun.CharacterCount == 0)
                {
                    CurrentLine.Remove(removingTextRun);
                    EnsureCurrentTextRun();
                }
                CurrentLine.TextLineReCalculateActualLineSize();
                CurrentLine.RefreshInlineArrange();
                return(toBeRemovedChar);
            }
        }
        char BackSpaceOneChar()
        {
            if (CurrentTextRun == null)
            {
                return('\0');
            }
            else
            {
                if (CharIndex == 0)
                {
                    return('\0');
                }

                //move back 1 char and do delete
                EditableRun removingTextRun = CurrentTextRun;
                int         removeIndex     = CurrentTextRunCharIndex;
                SetCurrentCharStepLeft();
                char toBeRemovedChar = CurrentChar;

                EditableRun.InnerRemove(removingTextRun, removeIndex, 1, false);
                if (removingTextRun.CharacterCount == 0)
                {
                    CurrentLine.Remove(removingTextRun);
                    EnsureCurrentTextRun();
                }
                CurrentLine.TextLineReCalculateActualLineSize();
                CurrentLine.RefreshInlineArrange();
                return(toBeRemovedChar);
            }
        }
예제 #3
0
        void Enqueue( )
        {
            ConsoleKeyInfo _key = Console.ReadKey(true);

            onKeyPressed(new EventArgs <ConsoleKeyInfo>(_key));
            switch (_key.Key)
            {
            case ConsoleKey.Backspace:
                if (!string.IsNullOrEmpty(CurrentLine.ToString( )))
                {
                    CurrentLine.Remove(CurrentLine.Length - 1, 1);
                    onCurrentLineChanged(EventArgs.Empty);
                }
                break;

            case ConsoleKey.LeftArrow:
            case ConsoleKey.RightArrow:
            case ConsoleKey.UpArrow:
            case ConsoleKey.DownArrow:
                break;

            case ConsoleKey.Enter:
                InputLines.Enqueue(CurrentLine.ToString( ));
                CurrentLine.Clear( );
                onCurrentLineChanged(EventArgs.Empty);
                onNewInputLineAdded(EventArgs.Empty);
                break;

            default:
                CurrentLine.Append(_key.KeyChar);
                onCurrentLineChanged(EventArgs.Empty);
                break;
            }
        }
        public void RemoveSelectedTextRuns(VisualSelectionRange selectionRange)
        {
            int precutIndex = selectionRange.StartPoint.LineCharIndex;

            CurrentLine.Remove(selectionRange);
            CurrentLine.TextLineReCalculateActualLineSize();
            CurrentLine.RefreshInlineArrange();
            EnsureCurrentTextRun(precutIndex);
        }
예제 #5
0
        public void RemoveSelectedTextRuns(VisualSelectionRange selectionRange)
        {
#if DEBUG
            //if (!CurrentLine.dbugHasOwner)
            //{

            //}
#endif
            int precutIndex = selectionRange.StartPoint.LineCharIndex;
            CurrentLine.Remove(selectionRange);
            InvalidateCurrentRun();

            CurrentLine.TextLineReCalculateActualLineSize();
            CurrentLine.RefreshInlineArrange();
            SetCurrentCharIndex2(precutIndex);
        }
예제 #6
0
        public void SplitToNewLine()
        {
            EditableRun lineBreakRun = new EditableTextRun(this.Root, '\n', this.CurrentSpanStyle);
            EditableRun currentRun   = CurrentTextRun;

            if (CurrentLine.IsBlankLine)
            {
                CurrentLine.AddLast(lineBreakRun);
            }
            else
            {
                if (CharIndex == -1)
                {
                    CurrentLine.AddFirst(lineBreakRun);
                    SetCurrentTextRun(null);
                }
                else
                {
                    EditableRun rightSplitedPart = EditableRun.InnerRemove(currentRun,
                                                                           CurrentTextRunCharIndex + 1, true);
                    if (rightSplitedPart != null)
                    {
                        CurrentLine.AddAfter(currentRun, rightSplitedPart);
                    }
                    CurrentLine.AddAfter(currentRun, lineBreakRun);

                    if (currentRun.CharacterCount == 0)
                    {
                        CurrentLine.Remove(currentRun);
                    }
                }
            }


            this.TextLayer.TopDownReCalculateContentSize();
            EnsureCurrentTextRun();
        }
예제 #7
0
        public void SplitToNewLine()
        {
            Run currentRun = CurrentTextRun;

            if (CurrentLine.IsBlankLine)
            {
                CurrentLine.AddLineBreakAfterLastRun();
            }
            else
            {
                if (CharIndex == -1)
                {
                    CurrentLine.AddLineBreakBeforeFirstRun();
                    SetCurrentTextRun(null);
                }
                else
                {
                    CopyRun rightSplitedPart = Run.InnerRemove(currentRun,
                                                               CurrentTextRunCharIndex + 1, true);
                    if (rightSplitedPart != null)
                    {
                        CurrentLine.AddAfter(currentRun, rightSplitedPart);
                    }

                    CurrentLine.AddLineBreakAfter(currentRun);
                    if (currentRun.CharacterCount == 0)
                    {
                        CurrentLine.Remove(currentRun);
                    }
                }
            }


            this.TextLayer.TopDownReCalculateContentSize();
            EnsureCurrentTextRun();
        }
예제 #8
0
        public static string ConvertKeyToString(Keys key, bool usingShift)
        {
            string output    = "";
            bool   usesShift = usingShift;

            if (key >= Keys.A && key <= Keys.Z)
            {
                output += key.ToString();
            }
            else if (key >= Keys.NumPad0 && key <= Keys.NumPad9)
            {
                output += ((int)(key - Keys.NumPad0)).ToString();
            }
            else if (key >= Keys.D0 && key <= Keys.D9)
            {
                string num = ((int)(key - Keys.D0)).ToString();
                #region special num chars
                if (usesShift)
                {
                    switch (num)
                    {
                    case "1":
                    {
                        num = "!";
                    }
                    break;

                    case "2":
                    {
                        num = "\"";
                    }
                    break;

                    case "3":
                    {
                        num = "#";
                    }
                    break;

                    case "4":
                    {
                        num = "?";
                    }
                    break;

                    case "5":
                    {
                        num = "%";
                    }
                    break;

                    case "6":
                    {
                        num = "&";
                    }
                    break;

                    case "7":
                    {
                        num = "/";
                    }
                    break;

                    case "8":
                    {
                        num = "(";
                    }
                    break;

                    case "9":
                    {
                        num = ")";
                    }
                    break;

                    case "0":
                    {
                        num = "=";
                    }
                    break;

                    default:
                        //wtf?
                        break;
                    }
                }
                #endregion
                output += num;
            }
            else if (key == Keys.OemPeriod)
            {
                output += ".";
            }
            else if (key == Keys.OemTilde)
            {
                output += "'";
            }
            else if (key == Keys.Space)
            {
                output += " ";
            }
            else if (key == Keys.OemMinus)
            {
                output += "-";
            }
            else if (key == Keys.OemPlus)
            {
                output += "+";
            }
            else if (key == Keys.OemQuestion && usesShift)
            {
                output += "?";
            }
            else if (key == Keys.Back)
            {
                //backspace
                if (CurrentLine.Length >= 1)
                {
                    CurrentLine = CurrentLine.Remove(CurrentLine.Length - 1);
                }
            }

            if (!usesShift) //shouldn't need to upper because it's automagically in upper case
            {
                output = output.ToLower();
            }

            return(output);
        }
예제 #9
0
        public void Update(GameTime gameTime)
        {
            #region update ui area

            _oskShowHide.Update(gameTime.ElapsedGameTime);
            switch (OskAlignment)
            {
            case AlignmentX.Left:
                _oskOffset = new Vector2(0,
                                         Game.Height - _oskLower.Height * (float)Math.Sin(_oskShowHide * MathHelper.PiOver2));
                break;

            case AlignmentX.Center:
                _oskOffset = new Vector2(Game.Center.X - _oskLower.Width / 2f,
                                         Game.Height - _oskLower.Height * (float)Math.Sin(_oskShowHide * MathHelper.PiOver2));
                break;

            case AlignmentX.Right:
                _oskOffset = new Vector2(Game.Width - _oskLower.Width,
                                         Game.Height - _oskLower.Height * (float)Math.Sin(_oskShowHide * MathHelper.PiOver2));
                break;
            }
            OskArea = new Rectangle((int)_oskOffset.X, (int)_oskOffset.Y, _oskLower.Width, _oskLower.Height);

            foreach (var b in _oskButtonHits)
            {
                b.TimeToLive.Update(gameTime.ElapsedGameTime);
            }
            _oskButtonHits.RemoveAll(b => b.TimeToLive.IsComplete);

            #endregion

            #region reset states

            _oskPreviousState.Clear();
            _oskPreviousState.AddRange(_oskCurrentState);
            _oskCurrentState.Clear();

            foreach (var k in Keyboard.GetState().GetPressedKeys().Where(k => !_oskCurrentState.Contains(k))
                     )
            {
                _oskCurrentState.Add(k);
            }

            _taps.Clear();
            if (Game.UnifiedInput.Action)
            {
                _taps.Add(Game.UnifiedInput.Location);
            }
            foreach (var t in Game.TouchInput.Touches.Where(t => !_taps.Contains(t)))
            {
                _taps.Add(t);
            }
            if (_oskVisible)
            {
                //bool shift;
                //var shR = new Rectangle(_oskRects[Keys.LeftShift].X + (int)_oskOffset.X, _oskRects[Keys.LeftShift].Y + (int)_oskOffset.Y,
                //        _oskRects[Keys.LeftShift].Width, _oskRects[Keys.LeftShift].Width);
                //var shL = new Rectangle(_oskRects[Keys.LeftShift].X + (int)_oskOffset.X, _oskRects[Keys.LeftShift].Y + (int)_oskOffset.Y,
                //        _oskRects[Keys.LeftShift].Width, _oskRects[Keys.LeftShift].Width);
                //if (_taps.Any(k => shR.Contains(k) || shL.Contains(k)))
                // {
                //    shift = true;
                // }

                foreach (var t in _taps)
                {
                    var p = new Point((int)t.X, (int)t.Y);
                    foreach (var r in _oskRects)
                    {
                        var or = new Rectangle(r.Value.X + (int)_oskOffset.X, r.Value.Y + (int)_oskOffset.Y,
                                               r.Value.Width,
                                               r.Value.Height);
                        if (or.Contains(p))
                        {
                            _oskCurrentState.Add(r.Key);


                            _oskButtonHits.Add(new OskButton
                            {
                                TimeToLive = new Tween(new TimeSpan(0, 0, 0, 1), 1, 0),
                                Rect       = new Rectangle(r.Value.X, r.Value.Y, r.Value.Width, r.Value.Height)
                            });
                        }
                        if (
                            new Rectangle(_oskExitRect.X + (int)_oskOffset.X, _oskExitRect.Y + (int)_oskOffset.Y,
                                          _oskExitRect.Width, _oskExitRect.Width).Contains(p))
                        {
                            IsOskVisable = false;
                        }
                    }
                }
            }

            #endregion

            if (TypedKey(Keys.CapsLock))
            {
                _isOskCaps = !_isOskCaps;
            }
            Typed.Clear();
            foreach (var t in _keys)
            {
                if (!TypedKey(t))
                {
                    continue;
                }
                var l = t.ToString();
                if (l.Length == 1)
                {
                    //if (Released(Keys.LeftShift) && Released(Keys.RightShift))
                    //    l = l.ToLower();
                    if (Pressed(Keys.LeftShift) || Pressed(Keys.RightShift) && !_isOskCaps)
                    {
                        l = l.ToUpper();
                    }
                    else if (_isOskCaps)
                    {
                        l = l.ToUpper();
                    }
                    else
                    {
                        l = l.ToLower();
                    }
                }
                else
                {
                    #region Name Numbers

                    if (l.StartsWith(D) & !l.Equals(DecimalStr) &
                        !l.Equals(Divide))
                    {
                        l = l.Substring(1);
                        if (Pressed(Keys.LeftShift) || Pressed(Keys.RightShift))
                        {
                            switch (l)
                            {
                            case Zero:
                            {
                                l = ZeroShift;
                                break;
                            }

                            case One:
                            {
                                l = OneShift;
                                break;
                            }

                            case Two:
                            {
                                l = TwoShift;
                                break;
                            }

                            case Three:
                            {
                                l = ThreeShift;
                                break;
                            }

                            case Four:
                            {
                                l = FourShift;
                                break;
                            }

                            case Five:
                            {
                                l = FiveShift;
                                break;
                            }

                            case Six:
                            {
                                l = SixShift;
                                break;
                            }

                            case Seven:
                            {
                                l = SevenShift;
                                break;
                            }

                            case Eight:
                            {
                                l = EightShift;
                                break;
                            }

                            case Nine:
                            {
                                l = NineShift;
                                break;
                            }
                            }
                        }
                    }
                    #endregion

                    else if (l.StartsWith(NumPad))
                    {
                        l = l.Substring(6);
                    }
                    else
                    {
                        switch (l)
                        {
                        case OemCommaStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemCommaShift
                                    : OemComma;
                            break;
                        }

                        case OemPeriodStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemPeriodShift
                                    : OemPeriod;
                            break;
                        }

                        case OemQuestionStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemQuestionShift
                                    : OemQuestion;
                            break;
                        }

                        case OemSemicolonStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemSemicolonShift
                                    : OemSemicolon;
                            break;
                        }

                        case OemQuotesStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemQuotesShift
                                    : OemQuotes;
                            break;
                        }

                        case OemOpenBracketsStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemOpenBracketsShift
                                    : OemOpenBrackets;
                            break;
                        }

                        case OemCloseBracketsStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemCloseBracketsShift
                                    : OemCloseBrackets;
                            break;
                        }

                        case OemPipeStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemPipeShift
                                    : OemPipe;
                            break;
                        }

                        case OemPlusStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemPlusShift
                                    : OemPlus;
                            break;
                        }

                        case OemMinusStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemMinusShift
                                    : OemMinus;
                            break;
                        }

                        case TabStr:
                        {
                            l = Tab;
                            break;
                        }

                        case MultiplyStr:
                        {
                            l = Multiply;
                            break;
                        }

                        case DivideStr:
                        {
                            l = Divide;
                            break;
                        }

                        case SubtractStr:
                        {
                            l = Subtract;
                            break;
                        }

                        case AddStr:
                        {
                            l = Add;
                            break;
                        }

                        case DecimalStr:
                        {
                            l = Dot;
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }
                    }
                }
                Typed.Add(l);
                CurrentLine += l;
            }

            // Check input for spacebar
            if (TypedKey(Keys.Space) && CurrentLine != string.Empty &&
                CurrentLine[CurrentLine.Length - 1].ToString() != Space)
            {
                CurrentLine += Space;
            }


            // Check input for backspace
            if (TypedKey(Keys.Back) && CurrentLine != string.Empty)
            {
                CurrentLine = CurrentLine.Remove(CurrentLine.Length - 1, 1);
            }

            // Check input for enter
            if (TypedKey(Keys.Enter))
            {
                PreviousLine = CurrentLine;
                CurrentLine  = string.Empty;
            }
            if (Any())
            {
                Game.UnifiedInput.Hidden = true;
            }
            if (_oskCurrentState == _oskPreviousState)
            {
                return;
            }

            var remove = new List <Procedure <KeyboardInput> >();
            foreach (var keyboardListener in _keyboardListeners)
            {
                try
                {
                    keyboardListener(this);
                }
                catch
                {
                    remove.Add(keyboardListener);
                }
            }
            _keyboardListeners.RemoveAll(remove.Contains);
        }
예제 #10
0
        public override bool OnHandleEvent(EventArgs e)
        {
            // handle key down events
            if (e is ConsoleKeyDownEventArgs keyDown)
            {
                switch (keyDown.KeyChar)
                {
                    #region -- Return --
                case '\r':
                    var command = Command;
                    if (currentLineIndex >= lines.Count - 1 && manager.CanExecute(command))
                    {
                        executeCommandOnKeyUp = command;
                    }
                    else
                    {
                        InsertNewLine();
                        Invalidate();
                    }
                    return(true);

                    #endregion
                    #region -- Escape --
                case '\x1B':
                    if (lastInputCommand != null)
                    {
                        ResetLastInputCommand();
                        Invalidate();
                    }
                    else if (currentLineIndex > 0 || currentLineOffset > 0)
                    {
                        currentLineIndex  = 0;
                        currentLineOffset = 0;
                        Invalidate();
                    }
                    else if (CurrentLine.ContentLength > 0 && lines.Count > 0)
                    {
                        Command = String.Empty;
                        Invalidate();
                    }
                    return(true);

                    #endregion
                    #region -- Backspace --
                case '\b':
                    CurrentLine.FixLineEnd(ref currentLineOffset);
                    if (currentLineOffset > 0)
                    {
                        ClearLastInputCommand();
                        currentLineOffset--;
                        if (CurrentLine.Remove(currentLineOffset))
                        {
                            Invalidate();
                        }
                    }
                    else if (currentLineIndex > 0)
                    {
                        ClearLastInputCommand();

                        if (currentLineIndex >= lines.Count)
                        {
                            currentLineIndex = lines.Count - 1;
                        }

                        var prevLine = lines[currentLineIndex - 1];
                        var currLine = CurrentLine;

                        currentLineOffset = prevLine.ContentLength;

                        if (currLine.ContentLength > 0)                                 // copy content
                        {
                            prevLine.InsertLine(currentLineOffset, currLine.content);
                        }

                        lines.RemoveAt(currentLineIndex);
                        currentLineIndex--;

                        Invalidate();
                    }
                    return(true);

                    #endregion
                    #region -- Tab --
                case '\t':
                    for (var i = 0; i < 4; i++)
                    {
                        if (CurrentLine.Insert(ref currentLineOffset, ' ', overwrite))
                        {
                            ClearLastInputCommand();
                            currentLineOffset++;
                            Invalidate();
                        }
                    }
                    return(true);

                    #endregion
                default:
                    if (!Char.IsControl(keyDown.KeyChar))
                    {
                        #region -- Char --
                        if (CurrentLine.Insert(ref currentLineOffset, keyDown.KeyChar, overwrite))
                        {
                            ClearLastInputCommand();
                            currentLineOffset++;
                            Invalidate();
                        }
                        #endregion
                        return(true);
                    }
                    else
                    {
                        switch (keyDown.Key)
                        {
                            #region -- Delete --
                        case ConsoleKey.Delete:
                            if (currentLineOffset >= CurrentLine.ContentLength)
                            {
                                ClearLastInputCommand();

                                if (currentLineIndex < lines.Count - 1)
                                {
                                    CurrentLine.InsertLine(currentLineOffset, lines[currentLineIndex + 1].content);
                                    lines.RemoveAt(currentLineIndex + 1);
                                    Invalidate();
                                }
                            }
                            else if (CurrentLine.Remove(currentLineOffset))
                            {
                                ClearLastInputCommand();
                                Invalidate();
                            }
                            return(true);

                            #endregion
                            #region -- Up,Down,Left,Right --
                        case ConsoleKey.UpArrow:
                            if (currentLineIndex > 0)
                            {
                                if (currentLineIndex >= lines.Count)
                                {
                                    if (lines.Count > 1)
                                    {
                                        currentLineIndex = lines.Count - 2;
                                    }
                                    else
                                    {
                                        currentLineIndex = 0;
                                    }
                                }
                                else
                                {
                                    currentLineIndex--;
                                }
                                Invalidate();
                            }

                            InvalidateCursor();
                            return(true);

                        case ConsoleKey.DownArrow:
                            if (currentLineIndex < lines.Count - 1)
                            {
                                currentLineIndex++;
                                Invalidate();
                            }
                            else if (currentLineIndex >= lines.Count)
                            {
                                currentLineIndex = lines.Count - 1;
                            }

                            InvalidateCursor();
                            return(true);

                        case ConsoleKey.LeftArrow:
                            if ((keyDown.KeyModifiers & ConsoleKeyModifiers.CtrlPressed) != 0)
                            {
                                MoveCursorByToken(CurrentLine.Content, true);
                                InvalidateCursor();
                                return(true);
                            }
                            else if (currentLineOffset > 0)
                            {
                                if (currentLineOffset < CurrentLine.ContentLength)
                                {
                                    currentLineOffset--;
                                }
                                else
                                {
                                    currentLineOffset = CurrentLine.ContentLength - 1;
                                }
                            }
                            else
                            {
                                currentLineOffset = 0;
                            }

                            Invalidate();
                            InvalidateCursor();
                            return(true);

                        case ConsoleKey.RightArrow:
                            if ((keyDown.KeyModifiers & ConsoleKeyModifiers.CtrlPressed) != 0)
                            {
                                MoveCursorByToken(CurrentLine.Content, false);
                                InvalidateCursor();
                                return(true);
                            }
                            else if (currentLineOffset < CurrentLine.ContentLength)
                            {
                                currentLineOffset++;
                            }
                            else
                            {
                                currentLineOffset = CurrentLine.ContentLength;
                            }

                            Invalidate();
                            InvalidateCursor();
                            return(true);

                            #endregion
                        }
                    }
                    break;
                }
            }
            else if (e is ConsoleKeyUpEventArgs keyUp)
            {
                switch (keyUp.Key)
                {
                    #region -- Home,End,Up,Down,PageUp,PageDown --
                case ConsoleKey.Enter:
                    if (executeCommandOnKeyUp != null)
                    {
                        ClearLastInputCommand();

                        if (commandAccepted != null)
                        {
                            commandAccepted.SetResult(executeCommandOnKeyUp);
                        }

                        executeCommandOnKeyUp = null;
                    }
                    break;

                case ConsoleKey.PageUp:
                    MoveHistory(false);
                    return(true);

                case ConsoleKey.UpArrow:
                {
                    if ((keyUp.KeyModifiers & ConsoleKeyModifiers.AltPressed) != 0)
                    {
                        MoveHistory(false);
                        return(true);
                    }
                }
                break;

                case ConsoleKey.PageDown:
                    MoveHistory(true);
                    return(true);

                case ConsoleKey.DownArrow:
                {
                    if (manager is IConsoleReadLineHistory history && (keyUp.KeyModifiers & ConsoleKeyModifiers.AltPressed) != 0)
                    {
                        MoveHistory(true);
                        return(true);
                    }
                }
                break;

                case ConsoleKey.End:
                    if ((keyUp.KeyModifiers & ConsoleKeyModifiers.CtrlPressed) != 0)
                    {
                        currentLineIndex = lines.Count - 1;
                    }
                    currentLineOffset = CurrentLine.ContentLength;
                    Invalidate();
                    return(true);

                case ConsoleKey.Home:
                    if ((keyUp.KeyModifiers & ConsoleKeyModifiers.CtrlPressed) != 0)
                    {
                        currentLineIndex = 0;
                    }
                    currentLineOffset = 0;
                    Invalidate();
                    return(true);

                    #endregion
                    #region -- Insert --
                case ConsoleKey.Insert:
                    overwrite = !overwrite;
                    Invalidate();
                    return(true);

                case ConsoleKey.V:
                    if ((keyUp.KeyModifiers & ConsoleKeyModifiers.CtrlPressed) != 0)
                    {
                        var clipText = GetClipboardText();
                        var first    = true;
                        foreach (var(startAt, len) in Procs.SplitNewLinesTokens(clipText))
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else                                     // new line
                            {
                                InsertNewLine();
                            }

                            CurrentLine.InsertLine(ref currentLineOffset, clipText, startAt, len);
                            Invalidate();
                        }
                        return(true);
                    }
                    break;

                    #endregion
                default:
                {
                    //if (manager is IConsoleReadLineHistory history && (keyUp.KeyModifiers & ConsoleKeyModifiers.CtrlPressed) != 0 && keyUp.Key == ConsoleKey.R)
                    //	;
                }
                break;
                }
            }

            return(base.OnHandleEvent(e));
        }         // proc OnHandleEvent
예제 #11
0
        public void Update()
        {
            #region reset states

            _oskPreviousState.Clear();
            _oskPreviousState.AddRange(_oskCurrentState);
            _oskCurrentState.Clear();
            foreach (var k in Enum.GetValues(typeof(Keys)))
            {
                if ((Keys)k == Keys.None)
                {
                    continue;
                }
                if (Keyboard.GetState().IsKeyDown((Keys)k) && !_oskCurrentState.Contains((Keys)k))
                {
                    _oskCurrentState.Add((Keys)k);
                }
            }

            #endregion

            Typed.Clear();
            foreach (var t in _keys)
            {
                if (!TypedKey(t))
                {
                    continue;
                }
                var l = t.ToString();
                if (l == "Tab")
                {
                    l = "\t";
                }
                else if (l.Length == 1)
                {
                    //if (Released(Keys.LeftShift) && Released(Keys.RightShift))
                    //    l = l.ToLower();
                    if (Pressed(Keys.LeftShift) || Pressed(Keys.RightShift) && IsCapsLock)
                    {
                        l = l.ToUpper();
                    }
                    else if (IsCapsLock)
                    {
                        l = l.ToUpper();
                    }
                    else
                    {
                        l = l.ToLower();
                    }
                }
                else
                {
                    #region Name Numbers

                    if (l.StartsWith(D) & !l.Equals(DecimalStr) &
                        !l.Equals(Divide))
                    {
                        l = l.Substring(1);
                        if (Pressed(Keys.LeftShift) || Pressed(Keys.RightShift))
                        {
                            switch (l)
                            {
                            case Zero:
                            {
                                l = ZeroShift;
                                break;
                            }

                            case One:
                            {
                                l = OneShift;
                                break;
                            }

                            case Two:
                            {
                                l = TwoShift;
                                break;
                            }

                            case Three:
                            {
                                l = ThreeShift;
                                break;
                            }

                            case Four:
                            {
                                l = FourShift;
                                break;
                            }

                            case Five:
                            {
                                l = FiveShift;
                                break;
                            }

                            case Six:
                            {
                                l = SixShift;
                                break;
                            }

                            case Seven:
                            {
                                l = SevenShift;
                                break;
                            }

                            case Eight:
                            {
                                l = EightShift;
                                break;
                            }

                            case Nine:
                            {
                                l = NineShift;
                                break;
                            }
                            }
                        }
                    }

                    #endregion

                    else if (l.StartsWith(NumPad))
                    {
                        l = l.Substring(6);
                    }
                    else
                    {
                        switch (l)
                        {
                        case OemCommaStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemCommaShift
                                    : OemComma;
                            break;
                        }

                        case OemPeriodStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemPeriodShift
                                    : OemPeriod;
                            break;
                        }

                        case OemQuestionStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemQuestionShift
                                    : OemQuestion;
                            break;
                        }

                        case OemSemicolonStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemSemicolonShift
                                    : OemSemicolon;
                            break;
                        }

                        case OemQuotesStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemQuotesShift
                                    : OemQuotes;
                            break;
                        }

                        case OemOpenBracketsStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemOpenBracketsShift
                                    : OemOpenBrackets;
                            break;
                        }

                        case OemCloseBracketsStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemCloseBracketsShift
                                    : OemCloseBrackets;
                            break;
                        }

                        case OemPipeStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemPipeShift
                                    : OemPipe;
                            break;
                        }

                        case OemPlusStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemPlusShift
                                    : OemPlus;
                            break;
                        }

                        case OemMinusStr:
                        {
                            l = Pressed(Keys.LeftShift) || Pressed(Keys.RightShift)
                                    ? OemMinusShift
                                    : OemMinus;
                            break;
                        }

                        case TabStr:
                        {
                            l = Tab;
                            break;
                        }

                        case MultiplyStr:
                        {
                            l = Multiply;
                            break;
                        }

                        case DivideStr:
                        {
                            l = Divide;
                            break;
                        }

                        case SubtractStr:
                        {
                            l = Subtract;
                            break;
                        }

                        case AddStr:
                        {
                            l = Add;
                            break;
                        }

                        case DecimalStr:
                        {
                            l = Dot;
                            break;
                        }
                        }
                    }
                }
                Typed.Add(l);
                CurrentLine += l;
            }

            // Check input for spacebar
            if (TypedKey(Keys.Space) && CurrentLine != string.Empty &&
                CurrentLine[CurrentLine.Length - 1].ToString() != Space)
            {
                CurrentLine += Space;
            }


            // Check input for backspace
            if (TypedKey(Keys.Back) && CurrentLine != string.Empty)
            {
                CurrentLine = CurrentLine.Remove(CurrentLine.Length - 1, 1);
            }

            // Check input for enter
            if (TypedKey(Keys.Enter))
            {
                PreviousLine = CurrentLine;
                CurrentLine  = string.Empty;
                Typed.Add("\n");
            }
            if (_oskCurrentState == _oskPreviousState)
            {
                return;
            }

            var remove = new List <Action <KeyboardInput> >();
            foreach (var keyboardListener in _keyboardListeners)
            {
                try
                {
                    keyboardListener(this);
                }
                catch
                {
                    remove.Add(keyboardListener);
                }
            }
            _keyboardListeners.RemoveAll(remove.Contains);
        }