title: How to set a bool variable to true when a key is pushed and false when it is pushed again?
body: <p>I am having quite an issue in C# right now I am trying to code a function that detects when the F8 button is pushed and set the bool F8Pushed to true then when it is pushed again set F8Pushed to false.</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>static bool IsKeyPressed() //This Function Returns True if F8 Is Pushed and False if F8 is up
  {
      bool is_pressed = (GetAsyncKeyState(119) &amp; 0x8000) != 0;
      return is_pressed;
  }
  
  static void CheckHotKey() //This is the Function that I am calling the other function from for debugging.
  {
      while (true)
      {
          Console.WriteLine(IsKeyPressed());
      }
  }
  </code></pre>
  
  <p>Now the problem that I am having and cannot resolve is that I cant find a way to get the variable to copy its self to another variable and be able to go back to false if that makes sense. I can get a bool set to true if <code>IsKeyPressed() == true</code> however I cannot figure out how to get it back to false when it returns true again.</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT:
  Thanks for you help guys however I am still having some trouble heres an update.</p>
  
  <pre><code>static bool IsKeyPressed()
      {
          is_pressed = (GetAsyncKeyState(119) &amp; 0x8000) != 0 &amp;&amp; !is_pressed; 
          return is_pressed;
      }
  
      static void CheckHotKeys()
      {
          while (true)
          {
              IsKeyPressed();
              if(is_pressed)
              {
                  F8Pushed = true;
              }
              Console.WriteLine(F8Pushed);
              if(IsKeyPressed())
              {
                  F8Pushed = false;
              }
              Console.WriteLine(F8Pushed);
          }
      }
  </code></pre>
  
  <p>I managed to get it to work kinda however it is very buggy and alot of times the key stroke doesnt detect any ideas?</p>