Last active
March 18, 2019 09:12
-
-
Save ramnes/ec62ddffa4e0fe657f87 to your computer and use it in GitHub Desktop.
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 python3 | |
"""xev output data parser to get mouse polling rate. | |
Usage: | |
$ chmod a+x mouserate | |
$ xev | mouserate | |
""" | |
import sys | |
import re | |
previous = 0 | |
time_re = re.compile('time (\d+)') | |
while True: | |
line = sys.stdin.readline() | |
match = time_re.search(line) | |
if match: | |
time = int(match.group(1)) | |
if previous: | |
try: | |
rate = round(1000 / (time - previous), 2) | |
print("{:.2f}Hz".format(rate)) | |
sys.stdout.flush() | |
except ZeroDivisionError: | |
pass | |
previous = time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment