简体   繁体   中英

Pause program until key is pressed

I have made some script in c# and my need is to pause script until user press any key. I need many pauses of this type in my program, so making event for every single is realy boring. Is any way, how you can pause app until key is pressed? Something like Console.ReadKey() in console application?

//some kind of running code
//------------------
//pause until key is pressed
//-------------------
//code running after key press

Your tags suggest this is a WPF application without a console. If you just need to detect a key press, you could override the KeyDown event.

<Window KeyDown="OnKeyDown" />

Then

private void OnKeyDown(object sender, KeyEventArgs e)
{
    // signal your activity to continue
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM