if this is a winforms application (the "MessageBox.Show" says that it is) then hitting space will trigger an event depending on which control has focus.
private void form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == ' ')
ps.AddScript("netsh trace stop");
}
The problem is that you have stated that you cannot accept new events. I imagine that this is because the button3_Click event continues to run for some time, blocking other events.
I suggest you look at Threading and Async methods. Here one way (not fully tested)
private PowerShell ps = new PowerShell { };
private BackgroundWorker backgroundWorker = new BackgroundWorker();
private bool isPsRunning = false;
public void button3_Click(object sender, EventArgs e)
{
backgroundWorker.DoWork +=backgroundWorker_DoWork;
backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
backgroundWorker.RunWorkerAsync();
}
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
isPsRunning = false;
}
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
isPsRunning = true;
ps.AddScript("netsh trace start persistent=yes capture=yes tracefile=" + progpath + @"\nettrace.etl");
}
private void form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (isPsRunning && e.KeyChar == ' ')
ps.AddScript("netsh trace stop");
}