Simple keystroke counter
I wrote this script to count the amount of keystrokes I do on my
computer. All updates will be posted here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import sys | |
| import atexit | |
| import time | |
| global count | |
| global fname | |
| fname = '/home/mgccl/.keycount' | |
| def savecounter(): | |
| f = open(fname,'w') | |
| f.write(str(count)) | |
| f.write('\n') | |
| f.close() | |
| atexit.register(savecounter) | |
| f = open(fname,'r') | |
| count = int(f.readline()) | |
| f.close() | |
| t = time.time() | |
| input = open("/dev/input/event"+sys.argv[1],'rb') | |
| while True: | |
| input.read(96) | |
| count+=1 | |
| #print(count) | |
| if (time.time() - t > 60): | |
| t = time.time() | |
| savecounter() |
It’s simple. So simple it’s have some bugs. For example, if you keep holding a key, it will be counted repeatedly.