public void InputTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key.Equals(Key.Return) || e.Key.Equals(Key.Enter))
     {
         OnReadLine?.Invoke(input_TextBox.Text);
         terminalData.Add(input_TextBox.Text);
         input_TextBox.Text = "";
     }
 }
示例#2
0
        private void KeyEvent(object sender, KeyEventArgs e)
        {
            if (historyNext && e.KeyCode != Keys.Enter)
            {
                historyNext = false;
            }

            if (hideNext)
            {
                string chr = (new KeysConverter().ConvertToString(e.KeyCode));

                hidden.SelectionStart  = input.SelectionStart - prefix.Length;
                hidden.SelectionLength = input.SelectionLength;

                if (chr == "Back")
                {
                    HiddenBackspace();
                }
                else if (chr.Length == 1)
                {
                    hidden.Text       += chr;
                    input.Text        += "X";
                    e.SuppressKeyPress = true;
                    input.Select(input.Text.Length, 0);
                }
                else
                {
                    e.SuppressKeyPress = true;
                    input.Select(input.Text.Length, 0);
                }
            }

            if (e.KeyCode == Keys.Enter)
            {
                string command = input.Text.Substring(prefix.Length);

                if (!hideNext && !choiceMode && !ignoreNext && !command.StartsWith("set pin "))
                {
                    history.Add(command);
                    if (!historyNext)
                    {
                        hIndex = history.Count;
                    }
                    else
                    {
                        historyNext = false;
                    }
                    prevCommand = command;
                }

                if (hideNext)
                {
                    tempText = hidden.Text;
                    hidden   = new TextBox();
                    hideNext = false;
                }
                else
                {
                    tempText = command;
                }
                ReadLineEventArgs args = new ReadLineEventArgs(command);
                if (!choiceMode && !ignoreNext)
                {
                    OnReadLine?.Invoke(this, args);
                }
                if (ignoreNext)
                {
                    ignoreNext = false;
                }
                input.Clear();
                input.Text = String.Empty;
                input.Text = prefix;
                input.Select(input.Text.Length, 0);
                input.Text         = input.Text.Replace("\r\n", String.Empty);
                input.Text         = input.Text.Trim();
                e.SuppressKeyPress = true;
            }

            if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Left)
            {
                if (input.SelectionStart <= prefix.Length)
                {
                    e.SuppressKeyPress = true;
                }
            }

            if (e.KeyCode == Keys.Home && !hideNext)
            {
                input.Select(prefix.Length, 0);
                e.SuppressKeyPress = true;
            }

            if (e.KeyCode == Keys.Up && !hideNext)
            {
                if (hIndex > 0)
                {
                    hIndex -= 1;
                }
                if (hIndex != -1)
                {
                    LoadHistory();
                }
            }

            if (e.KeyCode == Keys.Down && !hideNext)
            {
                if ((hIndex + 1) == history.Count)
                {
                    hIndex += 1;
                }

                if (hIndex >= history.Count)
                {
                    input.Text = prefix;
                    input.Select(input.Text.Length, 0);
                    return;
                }
                hIndex += 1;
                LoadHistory();
            }
        }