Keyboard and Mouse integration? #20
-
I am running a Raspberry Pi Pico (RP2040) I noticed that in boot.py, the default example calls Keyboard, Mouse, and Consumer Control. How do you integrate this into code.py with JoystickXL? I have 3 axis (X/Y/Slider), and 11 buttons, I'd like 4 of the buttons to be keyboard or mouse commands, is this possible? (Star Citizen does not like a joystick button to "activate" certain block buttons, and only the mouse works) I've done this with the Adafruit USB HID package previously with another button box, but when I tried to integrate that into the same code.py as JoystickXL, neither Joystick or Keyboard/Mouse would function. I'd prefer to not run 2 Picos per machine, or have to keep a mouse next to the box. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
For now, I've just installed Joystick Gremlin and VJoy to handle remapping the joystick buttons to the keyboard and mouse, but that is not my preferred solution ;) |
Beta Was this translation helpful? Give feedback.
-
Are you using the standard import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.mouse import Mouse
from joystick_xl.inputs import Axis, Button, Hat
from joystick_xl.joystick import Joystick
joystick = Joystick()
joystick.add_input(
Button(board.GP0),
)
keyboard = Keyboard(usb_hid.devices)
key = digitalio.DigitalInOut(board.GP1)
key.switch_to_input(pull=digitalio.Pull.UP)
mouse = Mouse(usb_hid.devices)
click = digitalio.DigitalInOut(board.GP2)
click.switch_to_input(pull=digitalio.Pull.UP)
while True:
joystick.update()
if key.value is False:
keyboard.send(Keycode.SHIFT, Keycode.A)
if click.value is False:
mouse.click(Mouse.RIGHT_BUTTON) |
Beta Was this translation helpful? Give feedback.
Are you using the standard
boot.py
from the JoystickXL documentation to configure CircuitPython HID devices? It enables keyboard, mouse, consumer control and joystick devices, and all of them should work as long as you have the appropriate libraries installed on your device - JoystickXL for the joystick functions andadafruit_hid
for the rest. I just tried the following quick test on a Pico and everything worked as expected: