Skip to content

Instantly share code, notes, and snippets.

@a1ea321
Created July 16, 2018 12:05
Show Gist options
  • Save a1ea321/e2575745870bffbeb8dad11d0f81b47e to your computer and use it in GitHub Desktop.
Save a1ea321/e2575745870bffbeb8dad11d0f81b47e to your computer and use it in GitHub Desktop.
footbased mouse
from sensor import Sensor
from pymouse import PyMouse
s = Sensor()
m = PyMouse()
# init sensor
while not s.get_single_sample(): pass
m.move(10000, 10000)
x, y = m.position()
m.move(x / 2, y / 2)
X_THRESHOLD = 2.
Y_THRESHOLD = 6.
def convert(raw_value, threshold):
PARAM = 1.5
PARAM2 = 1.5
if threshold < val < 2 * threshold:
return val - threshold
return val
while True:
sample = s.get_single_sample()[1]
#y = y * 0.96 + 0.04 * (sample[0] - 1.0) * (1079 / 4.0)
x = m.position()[0]
val = sample[8]
if abs(val) > X_THRESHOLD:
x -= convert(val, X_THRESHOLD)
if str(x) == 'nan': continue
y = m.position()[1]
val = sample[7]
if abs(val) > Y_THRESHOLD:
y -= convert(val, Y_THRESHOLD)
if str(y) == 'nan': continue
m.move(x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment