API

Ethernet UDP mouse API

Python helper for relative mouse move and clicks over UDP to our RP2350/RP2040/Teensy4.1 Ethernet firmware.

Overview

Communicate with our RP2350/RP2040/Teensy4.1 Ethernet firmware. Supports W5500, Adafruit Ethernet FeatherWing, and other similar Ethernet modules.

Install

  1. Download rpudp.py and example.py
  2. Flash / power your Ethernet board and note its IP address
  3. Firmware listens on port 7777 by default. Currently it cannot be changed.

Quick start

Point RPUDP at the board IP and port, then call open() before move/click.

quickstart.pypython
from rpudp import RPUDP

dev = RPUDP('192.168.68.69', 7777)

if not dev.open():
    raise SystemExit("Failed to open socket")

dev.move(50, -20)
dev.click(RPUDP.BTN_L)
dev.close()

Methods

MethodReturnsDescription
RPUDP(ip, port=7777)RPUDPCreate a client for the board at ip:port.
open()boolCreate the UDP socket. Returns False if IP/port are invalid.
close()NoneClose the socket.
isConnected()boolTrue when a socket exists (does not prove the board is reachable).
move(x, y)NoneSend relative mouse movement.
setButtons(mask)NoneSet the held button mask (bitfield). Use RELEASE (0x00) to release.
click(mask, down_ms=30)NonePress buttons for down_ms milliseconds, then release.

Button constants

Pass these masks to click() and setButtons().

buttons.pypython
RPUDP.RELEASE  # 0x00 — release all
RPUDP.BTN_L     # 0x01 — left
RPUDP.BTN_R     # 0x02 — right
RPUDP.BTN_M     # 0x04 — middle
RPUDP.BTN_X1    # 0x08 — side / back
RPUDP.BTN_X2    # 0x10 — side / forward

Full example

example.pypython
from rpudp import RPUDP

dev = RPUDP('192.168.68.69', 7777)

print(f'RP connected on port: {dev.port}') # always prints even if wrong IP. I need to add a handshake


# Relative mouse movement (x, y)
dev.move(50, -20)

# Button press
dev.click(RPUDP.BTN_L)              # left click for 30 ms (default)
dev.click(RPUDP.BTN_R, down_ms=50)  # right click for 50ms

# Hold a button down until you tell it to release
dev.setButtons(RPUDP.BTN_L) # hold left click
# do something
dev.setButtons(RPUDP.RELEASE) # release all


dev.close()