The Art Gallery Guardian

Simple keystroke counter


I wrote this script to count the amount of keystrokes I do on my computer. All updates will be posted here.
#!/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()
view raw keycounter.py hosted with ❤ by GitHub

It’s simple. So simple it’s have some bugs. For example, if you keep holding a key, it will be counted repeatedly.

Posted by Chao Xu on .
Tags: python, tools.