我正在写一些东西,应该让我将操纵杆用作我想在 fusion 360 中使用的Spacemouse ,我通过使鼠标移动并按下鼠标中键并移动来做到这一点,并在操纵杆停止移动时释放它,但是我的问题是我的鼠标不会同时移动和点击,每次我启动脚本时,我的电脑都会发疯,我必须重置它。
这是代码:
import analogio
import board
import digitalio
import usb_hid
from adafruit_hid.mouse import Mouse
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
kbd = Keyboard(usb_hid.devices)
mouse = Mouse(usb_hid.devices)
x_axis = analogio.AnalogIn(board.A3)
y_axis = analogio.AnalogIn(board.A2)
select = digitalio.DigitalInOut(board.A1)
select.direction = digitalio.Direction.INPUT
select.pull = digitalio.Pull.UP
pot_min = 0.00
pot_max = 3.29
step = (pot_max - pot_min) / 20.0
def get_voltage(pin):
return (pin.value * 5) / 65536
def steps(axis):
""" Maps the potentiometer voltage range to 0-20 """
return round((axis - pot_min) / step)
while True:
#print(str(digitalio.DigitalInOut.value))
x = get_voltage(x_axis)
y = get_voltage(y_axis)
if select.value is False:
print("test")
if steps(x) > 20.0:
# print(steps(x))
mouse.move(x=1)
if steps(x) < 9.0:
# print(steps(x))
mouse.move(x=-1)
if steps(x) > 25.0:
# print(steps(x))
mouse.move(x=8)
if steps(x) < 1.0:
# print(steps(x))
mouse.move(x=-8)
if steps(y) > 20.0:
# print(steps(y))
mouse.move(y=1)
if steps(y) < 9.0:
# print(steps(y))
mouse.move(y=-1)
if steps(y) > 25.0:
# print(steps(y))
mouse.move(y=8)
if steps(y) < 1.0:
# print(steps(y))
mouse.move(y=-8)
while steps(x) > 20.0 or steps(x) < 9.0 or steps(x) > 25.0 or steps(x) < 1.0 or steps(y) > 20.0 or steps(y) < 9.0 or steps(y) > 25.0 or steps(y) < 1.0:
kbd.press(Keycode.SHIFT)
mouse.press(Mouse.MIDDLE_BUTTON)
else:
kbd.release(Keycode.SHIFT)
mouse.release(Mouse.MIDDLE_BUTTON)```
I hope anyone can help me with this.