Created
October 21, 2018 17:48
-
-
Save smellslikeml/47b0895a923136c04acd936b2b94884e to your computer and use it in GitHub Desktop.
cursor logger - record cursor position
This file contains 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/env python | |
import os | |
import time | |
from Xlib import display | |
old_x = 0 | |
old_y = 0 | |
old_dur = 0 | |
end_time = 0 | |
logfile = os.environ['HOME'] + '/.cursor.log' | |
while True: | |
data = display.Display().screen().root.query_pointer()._data | |
new_x = data["root_x"] | |
new_y = data["root_y"] | |
if old_x != new_x or old_y != new_y: | |
start_time = time.time() | |
dur = start_time - end_time | |
if dur > old_dur: | |
pass | |
with open(logfile, 'a') as outfile: | |
outfile.write(':'.join(map(str, [new_x,new_y])) + ',') | |
else: | |
#print("Mouse Event duration: {}".format(old_dur)) | |
with open(logfile, 'a') as outfile: | |
outfile.write('\n') | |
else: | |
end_time = time.time() | |
old_x = new_x | |
old_y = new_y | |
old_dur = dur |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment