---
title: "System-wide input, display capture, click-through overlays, accessory apps"
url: https://recursiveai.org/oneplatform/docs/system-desktop/
description: "Four additions for programs that look at and act on the whole desktop, not only on their own windows: remote-desktop and automation tools, screen…"
version: "1.1.0"
source: https://github.com/recursive-ai-oss/oneplatform-csharp/blob/02f1c4ca42c0483f86b1473003132a3386877ddd/docs/system-desktop.md
---

# System-wide input, display capture, click-through overlays, accessory apps

Four additions for programs that look at and act on the whole desktop, not only on their own windows: remote-desktop and automation tools, screen annotators, tray utilities. They are opt-in and separate from the app's own event queue and `InputInjector`. Namespace `OnePlatform.SystemDesktop`.

A missing capability or permission is always a typed exception that names what is missing and how to get it, never a silent no-op: `ShellUnavailableException` (service plus requirement), and its subclass `OsPermissionException` (`Permission`) when the user can grant the thing.

## System-wide input: `SystemInput`

```csharp
using var input = await SystemInput.OpenAsync();   // or SystemInput.Open()
input.ClickAt(400, 300);
input.TypeText("Hello é€ 日本");
input.Key(Key.LeftControl, true); input.KeyPress(Key.S); input.Key(Key.LeftControl, false);
input.Scroll(0, 3);                                 // three notches down
```

Members: `MoveTo`, `MoveBy`, `Button`, `Click`, `ClickAt`, `Scroll(dx, dy)` (notches; positive is down and right), `Key`, `KeyPress`, `TypeText`. Events reach the window under the pointer or with the keyboard focus, whichever program owns it. Positions are desktop coordinates, the ones `ScreenCapture.GetDisplays` reports (points on macOS). `Key` names a physical key by its position on a US keyboard; `TypeText` sends characters whatever the layout, so any Unicode works, but the target sees text, not key presses. Calls return when the system took the event, not when the target handled it. Threading: any thread, one call at a time.

| System | Backend (`SystemInputBackend`) | Needs |
|---|---|---|
| Windows | `Windows`: `SendInput`; absolute moves across the virtual desktop, scan codes for keys, Unicode packets for text | an interactive desktop. A locked desktop, a secure prompt, or a target running at a higher integrity level is refused by Windows; the call then throws `ShellUnavailableException` (events delivered fewer than sent) where Windows says so, and otherwise the target never sees the input. |
| macOS | `Quartz`: `CGEventPost` at the HID tap | the **Accessibility** permission (System Settings, Privacy & Security). Checked with `AXIsProcessTrusted`, without the system prompt; `OsPermissionException` with `Permission == "Accessibility"` when missing. |
| Linux, X11 | `XTest`: the XTEST extension on `DISPLAY` (or `SystemInputOptions.DisplayName`) | libXtst. Characters no key makes are bound to a spare key code for the length of the key stroke, so a target that does not follow keyboard-map changes sees nothing for them. Under Xwayland it reaches X windows only. |
| Linux, Wayland | `RemoteDesktopPortal`: the XDG RemoteDesktop portal (a session with keyboard and pointer, plus the ScreenCast monitors for absolute positions) | the desktop's portal backend, and the user accepting its dialog; declining throws `OsPermissionException` ("Remote desktop access"). Disposing the `SystemInput` closes the session. `AbsolutePointer = false` skips the monitor request, leaving only `MoveBy`. |

`Auto` picks the portal when `WAYLAND_DISPLAY` is set (or there is no `DISPLAY`), XTEST otherwise. libei is not used: the portal's `Notify*` methods cover the same ground without a second protocol.

## Display capture: `ScreenCapture`

```csharp
foreach (var d in ScreenCapture.GetDisplays()) Console.WriteLine($"{d.Id} {d.Name} {d.Bounds} x{d.Scale}");
ScreenshotImage shot = ScreenCapture.CaptureDisplay(displayId);   // BGRA, rows top to bottom, alpha 255
File.WriteAllBytes("screen.png", shot.ToPng());
```

`GetDisplays` lists displays, primary first, with `Id` (pass it back; opaque), `Name`, `Bounds` (desktop pixels, points on macOS), `IsPrimary` and `Scale` (pixels per bounds unit). `CaptureDisplay` / `CaptureDisplayAsync` return a `ScreenshotImage`.

| System | Backend (`ScreenCaptureBackend`) | Needs |
|---|---|---|
| Windows | `Windows`: GDI `BitBlt` of the composed screen with `CAPTUREBLT`, so GPU-drawn and layered windows are included | an interactive desktop |
| macOS | `Quartz`: `CGDisplayCreateImage` | the **Screen Recording** permission, checked with `CGPreflightScreenCaptureAccess` (without it the system returns only the wallpaper, which would look like a capture); `OsPermissionException` with `Permission == "Screen Recording"` |
| Linux, X11 | `X11`: `XGetImage` of the root window, monitors from RandR | nothing. Under Xwayland it shows X windows only. |
| Linux, Wayland | `ScreenshotPortal`: the XDG Screenshot portal | the portal. It captures the **whole desktop in one image** (one display, id 0, bounds unknown), and **may ask the user to confirm** (the first time, or always with `Interactive = true`); a cancelled request throws `OsPermissionException`. The image the portal writes is read and then deleted. |

## Click-through overlays: `OverlayOptions.ClickThrough`

An overlay window (`WindowOptions.Overlay`) with `ClickThrough = true` takes no pointer input: clicks, movement and the wheel go to whatever is below it. `Window.ClickThrough` reports it. Fixed for the window's lifetime. Pair it with `OverlayKeyboard.None`.

- Windows: `WS_EX_TRANSPARENT | WS_EX_LAYERED` (opaque layered window).
- macOS: `ignoresMouseEvents`.
- Wayland: an empty input region (`wl_surface.set_input_region`) on the layer surface.
- X11: an empty input shape (Shape extension, `ShapeInput`); without the extension or libXext, creating the window throws `OverlayUnavailableException`.

## macOS accessory apps: `PlatformOptions.AccessoryApp`

`true` runs the app with `NSApplicationActivationPolicyAccessory`: no Dock icon, no app menu in the menu bar, not in the Cmd-Tab switcher; its windows still take focus. For tray-icon tools and overlays. Ignored on other systems.

## What is proven where

See the changelog entry; the tests are `SystemDesktopPortableTests` (tables, PNG reader, portal conversations against a stand-in portal), `SystemDesktopX11Tests` (Xvfb), `SystemDesktopWindowsTests`, `SystemDesktopMacTests` and the click-through test in `DesktopWindowKwinTests` (a nested compositor).
