Example #1
0
 /// <summary>
 /// Вызывает событие нажатия Tab
 /// </summary>
 protected virtual void CallTabDown()
 {
     TabDown?.Invoke(this, EventArgs.Empty);
 }
Example #2
0
        private void KeyPressed(object sender, KeyboardInput.KeyEventArgs e, KeyboardState ks)
        {
            if (Active)
            {
                int oldPos = Cursor.TextCursor;
                switch (e.KeyCode)
                {
                case Keys.Enter:
                    EnterDown?.Invoke(this, e);
                    break;

                case Keys.Up:
                    UpArrow?.Invoke(this, e);
                    break;

                case Keys.Down:
                    DnArrow?.Invoke(this, e);
                    break;

                case Keys.Tab:
                    TabDown?.Invoke(this, e);
                    break;

                case Keys.Left:
                    if (KeyboardInput.CtrlDown)
                    {
                        Cursor.TextCursor = IndexOfLastCharBeforeWhitespace(Cursor.TextCursor, Text.Characters);
                    }
                    else
                    {
                        Cursor.TextCursor--;
                    }
                    ShiftMod(oldPos);
                    break;

                case Keys.Right:
                    if (KeyboardInput.CtrlDown)
                    {
                        Cursor.TextCursor = IndexOfNextCharAfterWhitespace(Cursor.TextCursor, Text.Characters);
                    }
                    else
                    {
                        Cursor.TextCursor++;
                    }
                    ShiftMod(oldPos);
                    break;

                case Keys.Home:
                    Cursor.TextCursor = 0;
                    ShiftMod(oldPos);
                    break;

                case Keys.End:
                    Cursor.TextCursor = Text.Length;
                    ShiftMod(oldPos);
                    break;

                case Keys.Delete:
                    if (DelSelection() == null && Cursor.TextCursor < Text.Length)
                    {
                        Text.RemoveCharacters(Cursor.TextCursor, Cursor.TextCursor + 1);
                    }
                    break;

                case Keys.Back:
                    if (DelSelection() == null && Cursor.TextCursor > 0)
                    {
                        Text.RemoveCharacters(Cursor.TextCursor - 1, Cursor.TextCursor);
                        Cursor.TextCursor--;
                    }
                    break;

                case Keys.A:
                    if (KeyboardInput.CtrlDown)
                    {
                        if (Text.Length > 0)
                        {
                            Cursor.SelectedChar = 0;
                            Cursor.TextCursor   = Text.Length;
                        }
                    }
                    break;

                case Keys.C:
                    if (KeyboardInput.CtrlDown)
                    {
                        clipboard = DelSelection(true);
                    }
                    break;

                case Keys.X:
                    if (KeyboardInput.CtrlDown)
                    {
                        if (Cursor.SelectedChar.HasValue)
                        {
                            clipboard = DelSelection();
                        }
                    }
                    break;

                case Keys.V:
                    if (KeyboardInput.CtrlDown)
                    {
                        if (clipboard != null)
                        {
                            DelSelection();
                            foreach (char c in clipboard)
                            {
                                if (Text.Length < Text.MaxLength)
                                {
                                    Text.InsertCharacter(Cursor.TextCursor, c);
                                    Cursor.TextCursor++;
                                }
                            }
                        }
                    }
                    break;

                case Keys.D2:
                    if (KeyboardInput.CtrlDown && KeyboardInput.AltDown)
                    {
                        if (Text.Length < Text.MaxLength)
                        {
                            Text.InsertCharacter(Cursor.TextCursor, '@');
                            Cursor.TextCursor++;
                        }
                    }
                    break;

                case Keys.D4:
                    if (KeyboardInput.CtrlDown && KeyboardInput.AltDown)
                    {
                        if (Text.Length < Text.MaxLength)
                        {
                            Text.InsertCharacter(Cursor.TextCursor, '$');
                            Cursor.TextCursor++;
                        }
                    }
                    break;
                }
            }
        }