Skip to content

Desktop automation in Deno with autopilot: mouse, keyboard and screenshots

autopilot is a Deno module for desktop automation. It wraps the Rust autopilot-rs crate through Deno’s FFI, so a script can move the mouse, type keystrokes, read pixel colours, take screenshots of the screen, and show alerts or notifications.

An earlier version of this post called autopilot a browser automation tool, with goto() and an in-memory screenshot(). Those methods don’t exist. It controls the operating system’s input devices, not a browser page. For browser automation in Deno, use Astral or Puppeteer instead.

  • Deno
  • On Linux, the X11 and build packages listed in the README: libdbus-1-dev x11-xserver-utils wmctrl libxtst-dev cmake libc-dev libx11-dev libxcb1-dev

On first run, the module downloads a prebuilt native library from the project’s GitHub releases and caches it locally.

autopilot_example.ts
import AutoPilot from "https://deno.land/x/autopilot@0.4.0/mod.ts";
const pilot = new AutoPilot();
// Screen dimensions in pixels
const { width, height } = pilot.screenSize();
console.log(`Screen is ${width}x${height}`);
// Move the mouse to the centre of the screen, then type into whatever has focus.
// type() only accepts ASCII and throws a TypeError otherwise.
pilot
.moveMouse(width / 2, height / 2)
.type("Hello from Deno");
// Save a screenshot of the whole screen to a PNG file
pilot.screenshot("screenshot.png");

The methods run synchronously and return the AutoPilot instance, so you can chain them. Other methods include click(), tap() for a single key, mousePosition(), pixelColor(), alert() and notify().

Terminal window
deno run -A --unstable autopilot_example.ts

The README runs it with --unstable --allow-ffi. FFI needs --allow-ffi because native code runs outside Deno’s sandbox. The library loader (plug) also needs network, read, write and env access to download and cache the native binary, which is why -A is the simplest choice here. Run it in a throwaway terminal: the script really will move your mouse and type into the focused window.

  • screenshot() takes a file name and writes the file itself; it does not return image bytes.
  • Coordinates are screen pixels. On HiDPI displays, check the scale factor before you compute positions.
  • Because it drives real input devices, it won’t work on a headless server or CI runner without a display.

© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)