-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspacemouse_input.py
More file actions
36 lines (30 loc) · 1.05 KB
/
Copy pathspacemouse_input.py
File metadata and controls
36 lines (30 loc) · 1.05 KB
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
import pyspacemouse
class SpaceMouseInput:
"""Handles SpaceMouse input and provides movement/rotation data."""
def __init__(self):
try:
self.device_connected = pyspacemouse.open()
except Exception as e:
print("⚠ Warning: No SpaceMouse detected. Running in fallback mode.")
print("🔄 Running in fallback mode (keyboard/mouse input).")
self.device_connected = False
def get_input(self):
"""Reads input from SpaceMouse and returns movement/rotation data."""
if not self.device_connected:
return None
state = pyspacemouse.read()
if state is None:
return None
return {
"tx": state.x,
"ty": state.y,
"tz": state.z,
"rx": state.roll,
"ry": state.pitch,
"rz": state.yaw,
"buttons": state.buttons
}
def close(self):
"""Closes the SpaceMouse connection."""
if self.device_connected:
pyspacemouse.close()