Last active
February 5, 2020 05:35
-
-
Save dhananjayraut/7f0389e7a119e2e59f91e67d26ee1762 to your computer and use it in GitHub Desktop.
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
""" | |
count mouse movements | |
first run `xinput -list` and note id of your mouse | |
then run `python mouse.py {id}` and | |
keep it running till you want to count mouse movements | |
it will update a file in working directory with current stats | |
every 100 movements. this file will be named as starting time | |
of the script. | |
""" | |
import sys | |
from datetime import datetime | |
from subprocess import Popen, PIPE | |
def main(id): | |
cmd = "xinput test " + str(id) | |
pipe = Popen(cmd, shell=True, bufsize=1000, stdout=PIPE).stdout | |
start = datetime.now() | |
filename = str(start.strftime("%d-%M-%Y-%H-%M-%S")) + ".txt" | |
motion, press, release, count = 0, 0, 0, 0 | |
while True: | |
line = str(pipe.readline()) | |
if "motion" in line: | |
motion += 1 | |
elif "press" in line: | |
press += 1 | |
elif "release" in line: | |
release += 1 | |
if count % 100 == 0: | |
with open(filename, "w") as F: | |
F.write("StartTime = " + str(start) + "\n") | |
current_time = datetime.now() | |
F.write( | |
"CurrentTime = " | |
+ str(current_time) | |
+ " difference = " | |
+ str(current_time - start) | |
+ "\n" | |
+ "motions = " | |
+ str(motion) | |
+ " press = " | |
+ str(press) | |
+ " releases = " | |
+ str(release) | |
+ "\n" | |
) | |
count += 1 | |
return | |
if __name__ == "__main__": | |
if len(sys.argv) == 1: | |
print("No id given auto detecting") | |
cmd = 'xinput list | grep Mouse | grep "=[0-9]*" -o | grep "[0-9]*" -o' | |
pipe = Popen(cmd, shell=True, bufsize=1000, stdout=PIPE).stdout | |
id = int(pipe.read().decode("utf-8")) | |
else: | |
id = int(sys.argv[1]) | |
main(id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment