Calculates your average wpm just by listening in the background. Ideal if you can type much faster than you can read.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
855 B

  1. import pyxhook
  2. import time
  3. timer = None
  4. last_press = None
  5. total_time = 0
  6. total_words = 0
  7. def OnKeyPress(event):
  8. global timer
  9. global last_press
  10. global total_time
  11. global total_words
  12. if event.Ascii > 65 and event.Ascii < 122:
  13. if timer is None:
  14. timer = time.time()
  15. last_press = time.time()
  16. elif time.time() - last_press <= 1:
  17. last_press = time.time() #Reset timer
  18. else:
  19. #Reset word count
  20. words = 1
  21. timer = None
  22. elif (event.Key == "Return" or chr(event.Ascii) == ' ') and timer is not None:
  23. #Calculate wpm
  24. deltaT = time.time() - timer
  25. print("Typed 1 word in " + str(deltaT) + " seconds.")
  26. print(str(60 / deltaT) + " wpm.")
  27. total_time += deltaT
  28. total_words += 1
  29. print("Avg: " + str(total_words * 60 / total_time))
  30. timer = None
  31. h = pyxhook.HookManager()
  32. h.KeyDown = OnKeyPress
  33. h.HookKeyboard()
  34. h.start()