-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_mouse_movements.py
56 lines (44 loc) · 1.06 KB
/
test_mouse_movements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import mindwavelsl
import numpy as np
import os
import win32api
from win32api import GetSystemMetrics
def move_mouse(x, y):
win32api.SetCursorPos((x,y))
width = GetSystemMetrics(0)
height = GetSystemMetrics(1)
print("Width =", width)
print("Height =", height)
mwlsl = mindwavelsl.MindwaveLSL('localhost', 13854)
mwlsl.setup()
mwlsl.write('{"enableRawOutput": true, "format": "Json"}')
prevatt = -1
prevmed = -1
currpos = [1200,1200]
while True:
try:
data = mwlsl.make_sample(mwlsl.read())
except KeyboardInterrupt:
raise
except:
continue
# Check pos 13, 14 for attention, meditation
if any([np.isnan(data[14]), np.isnan(data[13])]):
continue
if prevatt == -1:
prevatt = data[13]
prevmed = data[14]
continue
newx = currpos[0] + 10 * (prevatt - data[13])
newy = currpos[1] + 10 * (prevmed - data[14])
if newx < 0: newx = 0
if newy < 0: newy = 0
if newx > width: newx = width
if newy > height: newy = height
print((data[13], data[14]))
print((newx,newy))
print()
move_mouse(newx, newy)
currpos = [newx, newy]
prevatt = data[13]
prevmed = data[14]