Skip to content

Instantly share code, notes, and snippets.

@smellslikeml
Created October 21, 2018 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smellslikeml/47b0895a923136c04acd936b2b94884e to your computer and use it in GitHub Desktop.
Save smellslikeml/47b0895a923136c04acd936b2b94884e to your computer and use it in GitHub Desktop.
cursor logger - record cursor position
#!/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