I am writing this program that I want to run forever through a while loop, and whenever a user presses a certain key on the keyboard, he quits the program. I looked everywhere, but I only saw KeyEvents, but WindowsForm is not active while the program is running. Does anyone have a solution for me?
Edit: the program takes the cursor, so the activation of the event in the user interface is almost impossible
Edit two:
public void MainMethod()
{
while (true)
{
if (checkBox1.Checked == true) state = State.PERFORM_ACTION_ONE;
if (checkBox2.Checked == true) state = State.PERFORM_ACTION_TWO;
switch (state)
{
case State.PERFORM_ACTION_ONE:
DoSomething();
break;
}
}
}
source
share