keypi · shipped · week of
A Raspberry Pi as an AI agent's hands: USB keyboard, mouse and HDMI capture in one evening
An agent that can see a screen and press keys needs no software on the machine it works on. A Pi Zero as a USB keyboard and mouse, with a capture stick for eyes, got there in one evening.
keypi: a Raspberry Pi Zero as USB keyboard and mouse, and an HDMI capture stick, for AI agents · github
Some computers cannot be reached by software: a BIOS screen, an installer, a recovery mode, a machine kept off the network on purpose. A person works on those with a screen, a keyboard and a mouse. I wanted an AI agent to have the same three things.
Three parts
A Raspberry Pi Zero W plugs into the target's USB port and says it is a keyboard and a mouse. An HDMI capture stick takes the target's picture to the computer the agent runs on. The agent looks at a frame, decides, and sends keys and clicks to the Pi over Wi-Fi.
agent's computer target
+--------------+ +----------+
| screenshot <-+-- HDMI ---+ screen |
| decide | | |
| keys, clicks +-- Wi-Fi | |
+--------------+ | | |
Pi Zero -+ USB port |
+----------+
The capture stick goes into the agent's computer and not the Pi, because the Zero has one USB data port and that one is busy being a keyboard.
A keyboard made of files
Linux can present a small computer as a USB device. Set up that way, the Pi gets three files, and writing a few bytes to one of them is a key press or a mouse move on the target.
keyboard report, 8 bytes [modifiers][0][key][key][key][key][key][key] absolute mouse: x and y from 0 to 32767 relative mouse: kept for BIOS screens
Keys are sent as positions on a US keyboard, so the target's layout has to be US. At first each command was an SSH login to the Pi, one or two seconds every time. A small web service on the Pi, behind a random token, brought that to well under a second.
No OCR
I had planned a step that turns the picture into text. It was never needed: the model reads the screenshot itself. The tool scales each frame to 1,280 pixels wide, can draw a coordinate grid over it, and can cut a zoomed crop when the text is small.
Grabbing one frame takes about 3.2 seconds, most of it spent opening the capture device. At 1920 by 1080 the stick's uncompressed mode manages 5 frames a second and keeps text sharp; its compressed mode is faster and blurrier.
Teaching the mouse where the screen is
The mouse works in its own numbers, 0 to 32767, and the agent thinks in pixels of a screenshot. How one maps to the other changes with the resolution, the monitors and the capture source, so the tool measures it. It moves the pointer over a 5 by 5 grid, finds the pointer in each frame, and fits a line.
The first run found the pointer at 4 of the 25 points. It was comparing each frame with two fixed frames taken earlier, and anything else moving on a busy screen ruined that. Comparing each frame with the ones just before and after found all 25.
The fit was then off by a median of 0.64 pixels, and against the true pointer position by at most 2.
What went wrong on the way
- The first "hello world" went into the wrong window. Notepad had reopened one of my own files, and the agent typed "hello wor" into it before noticing. The rule since: look at what has focus before typing.
- The Pi's first boot took ten minutes. Normal boots take 30 to 40 seconds, which is too slow to catch a BIOS key if the Pi is powered by the machine it controls. It needs its own power for that, and I have not built that yet.
- The picture looked purple. I checked with colour bars, which came through exactly. The purple was the wallpaper.
The first real job, and the way round
The reason for building it that evening was a Mac that needed about 9 GB freed from Recovery mode. The capture stick showed the Mac's Recovery terminal clearly. The keyboard half never arrived: the Mac asked the Pi to identify itself eight times, about three seconds apart, and gave up. Windows had accepted the same Pi an hour earlier.
So the hands went over the network. I typed two commands on the Mac, and they opened a connection out to my desktop and started a temporary login server inside Recovery, open only to that connection and only to one key. Recovery is a thin system: it had no way to make the server's key, and no du or python3 either, so the key was made on the desktop, and file sizes were added up with find and stat.
The first agent would not take this route; its replies were stopped by its own safety checks three times. A second agent did the work. It confirmed the exact folder and version first, deleted one old phone-simulator image of 8,994,719,232 bytes, and left the rest. Free space reached about 37 GB, without turning off any of the Mac's protections.
The steps are in the repository, with my addresses taken out.
One evening, and what it has not done
From the first message to a typed "hello world" took 75 minutes, and to a calibrated mouse and a finished tool under two hours. The whole evening was 2 hours 46 minutes.
As a keyboard and mouse it has typed and clicked its way around a Windows desktop. It has not yet changed a BIOS setting, run an installer, or worked on a machine that is truly offline; those are what it is for, and the next thing to try.
The code is public: keypi on GitHub.
I'm Ovi. I recompile old Windows games to run in a browser, build a virtual GPU for Windows XP, and write tools for my own machines, with AI since 2020. Projects and the latest log