Skip to content

Instantly share code, notes, and snippets.

@TomyLobo

TomyLobo/sea.py Secret

Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomyLobo/d6473dd2a494cad724e2 to your computer and use it in GitHub Desktop.
Save TomyLobo/d6473dd2a494cad724e2 to your computer and use it in GitHub Desktop.
#!/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