title: Detecting no key press in c++
body: <p>I have tried various methods such as getchar(), kbhit(), and getch() to write a program that records the key pressed and not pressed at regular time intervals, but find a way to detect when the key is not pressed Could not. How can I detect unpressed state?</p>
  <pre><code>#include    &lt;iostream&gt;
  #include    &lt;fstream&gt;
  #include    &lt;chrono&gt;
  #include    &lt;ctime&gt;
  #include    &lt;string&gt;
  #include    &quot;getch.h&quot;
  
  
  ...
  
      fileName += to_string(localTime-&gt;tm_year + 1900) + monStr + 
          dayStr + &quot;_&quot; + hourStr + minStr + secStr;
  
      while(loopState)
      {
          readFile.open(fileName);
          loopState = readFile.is_open();
      }
      writeFile.open(fileName);
  
      while(true)
      { 
          currentClock = clock();
          if(currentClock % 100 == 0)
          { 
              /* if(getch() == ' ')
                  cout &lt;&lt; &quot;1&quot;;
              // code here
              */
          }
      }
  
      return 0;
   }
  </code></pre>