-
-
Save TomyLobo/d6473dd2a494cad724e2 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 python | |
from math import cos, sin, pi | |
from time import sleep, time | |
import sys, os, signal | |
if len(sys.argv) < 2: | |
device_id = os.popen("xinput list | sed -rn 's/^.*mouse.*id=([0-9]+).*$/\\1/ip; T; Q'").read().rstrip('\n') | |
else: | |
device_id = sys.argv[1] | |
if len(sys.argv) < 3: | |
property_id = os.popen("xinput list-props %s | sed -rn 's/^.*matrix.*\(([0-9]+)\).*$/\\1/ip; T; Q'" % device_id).read().rstrip('\n') | |
else: | |
property_id = sys.argv[2] | |
print "device id = %s" % device_id | |
print "property id = %s" % property_id | |
degree = pi / 180 | |
period = 2 # seconds | |
amplitude = 20 * degree | |
try: | |
while True: | |
t = time() | |
f = cos(t * pi * 2 / period) * amplitude | |
assert not os.system("xinput set-prop %s %s %s, %s, 0, %s, %s, 0, 0, 0, 1" % (device_id, property_id, cos(f), -sin(f), sin(f), cos(f))) | |
sleep(0.1) | |
except KeyboardInterrupt: | |
assert not os.system("xinput set-prop %s %s 1, 0, 0, 0, 1, 0, 0, 0, 1" % (device_id, property_id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment