Keyboard and Mouse HID with Rpi4 to Windows 10

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Partyexpress
 
Posts: 1
Joined: Fri Aug 12, 2022 10:50 am

Keyboard and Mouse HID with Rpi4 to Windows 10

Post by Partyexpress »

Hi There,

I have a Raspberry pi4-8Gb, and I'm trying to get the following script going for a project.

This is the main script that I am talking about. I want to set up keyboard and mouse. I am looking to take a variable string to put into a command and have it "type it" on Windows 10 computer. Also click on certain x-y coordinates of the screen.

import usb_hid
from adafruit_hid.mouse import Mouse

m = Mouse(usb_hid.devices)

# Click the left mouse button.
m.click(Mouse.LEFT_BUTTON)

# Move the mouse diagonally to the upper left.
m.move(-100, -100, 0)

# Roll the mouse wheel away from the user one unit.
# Amount scrolled depends on the host.
m.move(0, 0, -1)

# Keyword arguments may also be used. Omitted arguments default to 0.
m.move(x=-100, y=-100)
m.move(wheel=-1)

# Move the mouse while holding down the left button. (click-drag).
m.press(Mouse.LEFT_BUTTON)
m.move(x=50, y=20)
m.release_all() # or m.release(Mouse.LEFT_BUTTON)

Here is the link to the script that I am trying to use..

https://docs.circuitpython.org/projects ... _hid.mouse

I've installed Raspian64 with the new version directly off the web site. This version has the new Administrator mode, where you need to create a second account to set up xvnc. I've done that to get into it.

I am using Thonny to program it.

I don't know where to go from here. I know you have to set up the Pi as a keyboard and mouse somehow.

Is there a set up script to set this up, or has someone confirmed that this works?

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: Keyboard and Mouse HID with Rpi4 to Windows 10

Post by danhalbert »

This gives the basics: https://learn.adafruit.com/circuitpytho ... -and-mouse

Have you gotten the mouse code to work? I have not tried using a Pi as a USB device (as opposed to host). I know you can use an OTG cable on a Pi Zero, and I think you can use the USB-C port on a 4B.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”