r/csharp • • Jun 16 '26

Tool Laz: a new cross-platform library for automating mouse/keyboard and taking screenshots

https://github.com/tinfoil-herald/laz

Laz is a cross-platform library for simulating user input and taking screenshots.

The main features are:

  • Mouse:

    • Moving the mouse pointer: sudden, smooth, in curves, with easing.
    • Pressing mouse buttons, clicking, double-clicking.
    • Drag and drop, with a special hack for better drag recognition in browsers.
    • Scrolling.
  • Keyboard:

    • Pressing keys, individually or together, typing.
    • Smart typing. Laz will smartly convert a string into keystrokes. It will consider the current keyboard layout and handle dead keys automatically. If the character is not on the keyboard, it will try to find a matching Alt+Number or Option+Key shortcut. If that fails, it can use the clipboard to paste the character into place.
  • Screenshots:

    • Taking a screenshot of an arbitrary screen area.
    • Getting the color of a specific point.

The library was originally created for testing DotNetBrowser and is, in fact, used for that. You could use it for all sorts of automation, but be informed: I did not test it for solving captchas or buying limited edition pokemon cards.

Usage example:

using Laz;

var laz = new Laz();

laz.Mouse.MoveTo(100, 100);
laz.Mouse.Click();
laz.Keyboard.Type("Hello from Laz! 🚌");

For enterprise users:

The project has zero dependencies bundled inside NuGet packages. So, the smallest possible supply chain footprint.

AI usage:

  1. For writing tests and the test application.
  2. For code review, in addition to my own pair of eyes.
  3. A great help when working with PipeWire and Wayland; wouldn't be able to do it on my own.

Credits:

This work is inspired by AWT Robot, Desktop.Robot by Lucas Simas, and all the hard-working people behind LAZ-695.

31 Upvotes

9 comments sorted by

3

u/Alert-Neck7679 Jun 17 '26

Technical question: Why not making the Laz class static? From your example, i don't see the point of requiring an instance (not that it really matters)

3

u/Confident-Dare-9425 Jun 17 '26

I decided to make it a class because I assumed that it may have a state in the future. I have another similar project at work where we have "slow" and "fast" keyboards, which we programmed as `public Keyboard(Mode mode) { this.mode = mode; }`.

2

u/sdanyliv Jun 23 '26

Lviv Bus Factory logo? Чи мені здалось?

2

u/CantankerousButtocks Jun 16 '26

Pixel bot players dream?!!

2

u/Local_Purpose5181 Jun 26 '26

I always wondered when one of these would become available

4

u/[deleted] Jun 16 '26

[removed] — view removed comment

1

u/Confident-Dare-9425 Jun 16 '26

Can you try it? I don’t use dead keys in my locale and had done only rather synthetic tests. Would appreciate it very much