title: user32.GetAsyncKeyState on python to capture keys and mouseclicks
body: <pre><code>import time
  import ctypes
  import threading
  user32 = ctypes.windll.user32
  mouse_clicks = 0
  keystrokes = 0
  def getKeyPressed():
      global mouse_clicks
      global keystrokes
      for i in range(0,256):
          if user32.GetAsyncKeyState(i):
           #   if not i == 19:
               #   print &quot;pressed %d and st = %d &quot; % (i, user32.GetAsyncKeyState(i))
              if i == 1:
                  mouse_clicks += 1
                  print &quot;left&quot;
                  return time.time()
              elif 32 &lt; i &lt; 127:
                  keystrokes += 1
      return None
  def pr():
      global mouse_clicks
      global keystrokes
      while True:
          print &quot;mouse = %d and key = %d &quot;% (mouse_clicks, keystrokes)
          time.sleep(1)
  
  th = threading.Thread(target=pr)
  th.start()
  while True:
      getKeyPressed()
  </code></pre>
  <p><strong>The above code produces multiple click results when pressed once</strong>
  how do I get the correct number of keystrokes and clicks by modifying the above program?</p>