Beispiel #1
0
 private void OnKeyPressed(object sender, KeyPressEventArgs e)
 {
     if (pendingReadLine && currentCommandProcess != null)
     {
         if (!currentCommandProcess.HasExited)
         {
             if (pendingReadLine)
             {
                 if (e.KeyChar == '\n')
                 {
                     PipeManager.SendMessage(new Message(MessageType.ReadLineResponse, currentReadLineString), currentCommandProcess);
                     pendingReadLine       = false;
                     currentReadLineString = "";
                 }
                 else
                 {
                     currentReadLineString += e.KeyChar.ToString();
                 }
             }
             //e.Handled = true;
             return;
         }
     }
     if (currentCommandString == null)
     {
         currentCommandString = "";
     }
     if (e.KeyChar == '\b' && currentCommandString.Length > 0)
     {
         currentCommandString = currentCommandString.Remove(currentCommandString.Length - 1, 1);
         return;
     }
     currentCommandString += e.KeyChar;
 }
Beispiel #2
0
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (pendingRead)
            {
                PipeManager.SendMessage(new Message(MessageType.ReadResponse, ((int)e.KeyCode).ToString()), currentCommandProcess);
                pendingRead        = false;
                e.Handled          = true;
                e.SuppressKeyPress = cancelKeyPress;
                cancelKeyPress     = false;
                return;
            }

            if (e.KeyCode == Keys.Enter && !commandRunning)
            {
                //e.Handled = true;
                string[] data = currentCommandString.Split(new char[] { ' ' }, 2);
                currentCommand     = data[0];
                currentCommandArgs = data.Length > 1 ? data[1] : "";
                //MessageBox.Show("Command: \"" + currentCommand + "\" with arguments: \"" + currentCommandArgs + "\"");
                currentCommandString = "";
                currentCommandArgs   = "";

                //if (currentCommand == "echo")
                //{
                //    TerminalWriteLine("Echo: " + currentCommandArgs, true);
                //    TerminalWrite("ROOT§" + Environment.MachineName + "> ");
                //}

                currentCommandProcess = Process.Start(new ProcessStartInfo(currentCommand, currentCommandArgs)
                {
                    RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true
                });
                commandRunning = true;
                commandWorkerThread.Start();
            }

            //MessageBox.Show("Keys: " + e.KeyData + " | ConsoleKey: " + ((ConsoleKey)Enum.Parse(typeof(ConsoleKey), e.KeyValue.ToString())).ToString());
        }