Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. # LINUX VERSION
  2. # Counts the total number of keystrokes
  3. # Designed to compare battery performance wireless keyboards for Batteroo / Batteriser
  4. # Just a quick implementation of pyxhook
  5. # Most of this code is from the example file https://github.com/JeffHoogland/pyxhook
  6. # Requires pyxhook module
  7. # Visit GitHub https://github.com/JeffHoogland/pyxhook
  8. # Just Download the raw pyxhook.py file and put it in the same folder as this script
  9. # and run this script with python
  10. # Press Esc at any time to Quit and show the count - remember Esc counts as a key!
  11.  
  12. import pyxhook
  13. import time
  14.  
  15. def keystroke_pressed(key_pressed):
  16.     # uncomment below to see the key pressed
  17.     #print key_pressed
  18.     counter()
  19.  
  20.     # press 'Esc' key to quit
  21.     if key_pressed.Ascii == 27:
  22.         global running
  23.         running = False
  24.  
  25. def counter():
  26.     counter.count += 1
  27.  
  28. hookmanager = pyxhook.HookManager()
  29.  
  30. hookmanager.KeyDown = keystroke_pressed
  31.  
  32. hookmanager.HookKeyboard()
  33.  
  34. hookmanager.start()
  35.  
  36. # start counter at 0
  37. # note pressing the escape key counts as a key!
  38. counter.count = 0
  39.  
  40. running = True
  41.  
  42. while running:
  43.     time.sleep(0.1)
  44.  
  45. hookmanager.cancel()
  46.  
  47. print "\n"
  48. print "-------------------------------------"
  49. print "Keys have been pressed " + str(counter.count) + " times"
  50. print "-------------------------------------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement