Ejemplo n.º 1
0
        public override void SendKey(KeyInfo key_info)
        {
            bool already_handled = false;

            // try the B/W toggle key (F12)
            if (key_info.SpecialKey == SpecialKey.F12)
            {
                this.Application.BlackAndWhite = !this.Application.BlackAndWhite;
                this.Invalidate();
                this.Controls.InvalidateAll();
                this.Application.Terminal.ResetBuffer();
                already_handled = true;
            }

            // try the repaintall key (F10)
            if (key_info.SpecialKey == SpecialKey.F10)
            {
                this.Invalidate();
                this.Controls.InvalidateAll();
                this.Application.Terminal.ResetBuffer();
                already_handled = true;
            }

            // try next field key (TAB)
            if (key_info.SpecialKey == SpecialKey.Tab)
            {
                FocusedControl.SelectNextControl(FocusedControl, forward: true, tabStopOnly: true);
                already_handled = true;
            }

            // try form accept key (ENTER)
            if (already_handled == false)
            {
                if (key_info.SpecialKey == SpecialKey.Enter)
                {
                    if (this.AcceptButton != null)
                    {
                        if (this.AcceptButton.Enabled)
                        {
                            if (!(this.FocusedControl is Button))
                            {
                                this.AcceptButton.OnClick(EventArgs.Empty);
                                already_handled = true;
                            }
                        }
                    }
                }
            }

            // try form cancel key (ESC)
            if (already_handled == false)
            {
                if (key_info.SpecialKey == SpecialKey.F4)
                {
                    if (this.CancelButton != null)
                    {
                        if (this.CancelButton.Enabled)
                        {
                            this.CancelButton.OnClick(EventArgs.Empty);
                        }
                        already_handled = true;
                    }
                }
            }

            // try the registered shortcuts for any control
            if (already_handled == false)
            {
                var _controls = Controls.TabIndexList;
                var node      = _controls.First;

                while (node != null)
                {
                    var c = node.Value;
                    if (c.Visible && c.Enabled && c.HasShortCut && key_info.KeyChar == c.ClickShortCut)
                    {
                        c.OnClick(EventArgs.Empty);
                        already_handled = true;
                        break;
                    }

                    node = node.Next;
                }
            }

            // try the key preview for the form
            if (already_handled == false)
            {
                if (this.KeyPreview == true || this.Focused)
                {
                    var e = new KeyPressEventArgs(key_info);
                    OnKeyPress(e);
                    already_handled = e.Handled;
                }
            }

            // otherwise send to the focused control for further management
            if (already_handled == false)
            {
                if (_focusedControl != null)
                {
                    _focusedControl.SendKey(key_info);
                }
            }
        }
Ejemplo n.º 2
0
        private void _performKeyPress(KeyInfo key)
        {
            if (Enabled == false)
            {
                return;
            }

            switch (key.SpecialKey)
            {
            case SpecialKey.Home:
            {
                SelectionStart = 0;
                break;
            }

            case SpecialKey.End:
            {
                SelectionStart = Text.Length;         //TODO: works??
                break;
            }

            case SpecialKey.LeftArrow:
            {
                SelectionStart -= 1;
                break;
            }

            case SpecialKey.RightArrow:
            {
                SelectionStart += 1;
                break;
            }

            case SpecialKey.UpArrow:
            {
                if (this.Height == 1)
                {
                    SelectionStart -= 1;
                }
                break;
            }

            case SpecialKey.DownArrow:
            {
                if (this.Height == 1)
                {
                    SelectionStart += 1;
                }
                break;
            }

            case SpecialKey.Delete:
            {
                _deleteCurrentChar();
                Invalidate();
                break;
            }

            case SpecialKey.Backspace:
            {
                if (_selectionStart > 0)
                {
                    SelectionStart -= 1;
                    _deleteCurrentChar();
                    Invalidate();
                }

                break;
            }

            case SpecialKey.Enter:
            {
                break;
            }

            default:
            {
                if (this.ReadOnly == false)
                {
                    if (this.Overwrite == false)
                    {
                        OverwriteText(key.KeyChar);
                    }
                    else
                    {
                        // Paste(key.KeyChar)
                        OverwriteText(key.KeyChar);
                    }
                    Invalidate();
                    SelectionStart += 1;
                }

                break;
            }
            }
        }
Ejemplo n.º 3
0
 public static Message WM_KEY(KeyInfo key_info) => new Message(WM_MessageType.WM_KEY, key_info);
Ejemplo n.º 4
0
 public KeyPressEventArgs(KeyInfo info)
 {
     KeyInfo = info;
 }
Ejemplo n.º 5
0
 public void SendKey(KeyInfo key_info)
 {
     MessageQueue.PostMessage(Message.WM_KEY(key_info));
 }