循环运行,直到用户按下键

问题描述:

我应该使用什么代码来执行此逻辑:


  • 继续循环,直到用户按下所按下的键,此时程序将暂停.
  • 如果用户再次按下某个键,则继续循环.
  • 如果用户再次按下一个键,然后完全停止循环(即退出程序).
  • What code should I use to execute this logic:


    • Continue to loop until the user presses a key pressed, at which point the program will pause.
    • If the user presses a key again, then resume the loop.
    • If the user presses a key again, then stop the loop completely (i.e., quit the program).

不同的线程.主线程将读取按键,并将t的值从0增加到更高.

stdlib中还有另一个检测按键的功能,我无法回忆起该功能不要等待按键...
run the process in a different thread. main thread will read the key stroke and increase the value from t from 0 to higher.

there is another function in stdlib that detect keystroke i cannot recall that function dont wait for key stroke...
void runningProcess()
{ 
 while(1)
 {
    if(t==1)   //t is a global variable;
    {
     while(1)
     {
      if(t==2)
      {
       break;
      } 
     }
    }
    else if(t==3)
    {
      return;
    }
 }
}


void module()
{
    int notexit = 2;
    while(notexit)
    {
        if(kbhit())
        {
            if(notexit != 1)
                getch();
            notexit--;
        }
    }
}