I'm currently building an application where a user has a list of items that need to be triggered. The operator triggers this using a shortcut ("ADD"-button). Now most items only consist out of one action which is being executed, however, there are some items that include multiple steps. These steps need to be controlled by the operator.
So eventhough it is one item which is being triggered, the steps inside of the item need to be controlled by the shortcut.
private void function triggerItem()
{
// Perform Step 1
// PAUSE (AWAIT KEYPRESS)
// Perform Step 2
// PAUSE (AWAIT KEYPRESS)
// Perform Step 3
}
So for now in order to test it, I have just used a messagebox to "pause" in between the different steps, but I would like to make it a bit more clear. So I have created a panel with a keydown event that can capture the "ADD"-button being pressed to make the function continue.
But I think I would need a sort of Task that I can await the result for before continuing with the rest of the actions. Except I can't see how I can await a keydown event from a panel to return a value to the await function.
How could I achieve this?
private void showWarning()
{
// SHOW THE WARNING
panWarning.Show();
// ENSURE THE FOCUS IS SET TO THE PANEL TO CAPTURE THE KEY DOWN EVENT
panWarning.Focus();
// AWAIT THE KEYPRESS TO CONTINUE THE FUNCTION
}
private void panWarning_KeyDown(object sender, KeyEventArgs e)
{
// CHECK WHICH BUTTON WAS PRESSED
switch (e.KeyCode)
{
case Keys.Add:
// CONTINUE
break;
case Keys.Escape:
// ABORT
break;
}
}
Any suggestions? Thank you.