---
title: "Send system-wide keyboard and mouse input from C#"
url: https://recursiveai.org/oneplatform/cookbook/send-keyboard-and-mouse-input-to-other-apps-csharp/
description: "Send system-wide keyboard and mouse input from C# with OnePlatform. Click in another app, type text, and check what each desktop backend needs."
version: "1.2.0"
---

# Send system-wide keyboard and mouse input from C#

**OnePlatform** is a free, open-source library for windows, input, clipboard, displays and gamepads in .NET from Recursive AI. MIT or Apache-2.0, no native DLLs to ship.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePlatform) · [GitHub](https://github.com/recursive-ai-oss/oneplatform-csharp) · [Docs](https://recursiveai.org/oneplatform/docs/) · [Download example (.zip)](https://recursiveai.org/oneplatform/cookbook/send-keyboard-and-mouse-input-to-other-apps-csharp/send-keyboard-and-mouse-input-to-other-apps-csharp.zip)

```shell
dotnet add package RecursiveAI.OnePlatform
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OnePlatform.SystemDesktop;

using var input = await SystemInput.OpenAsync();
input.ClickAt(240, 160);
input.TypeText("Hello from C#");
System.Console.WriteLine("Sent Hello from C#");
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/oneplatform/cookbook/send-keyboard-and-mouse-input-to-other-apps-csharp/send-keyboard-and-mouse-input-to-other-apps-csharp.zip) and `dotnet run`.

Keyboard input goes to the focused window; `SystemInput` doesn’t target apps by name, process ID, or window handle.

Before running, place a blank editor’s text area over desktop point `(240, 160)` or change the coordinates to a point inside it. Run from a separate terminal that doesn’t cover the editor. The receiving app shows `Hello from C#`. The sender prints:

```text
Sent Hello from C#
```

On macOS, allow **Accessibility** access; on Wayland, approve the desktop’s remote-input dialog and allow monitor access for absolute clicks. If access is denied, OnePlatform throws `OsPermissionException`. Use plain ASCII for this example: on X11, some apps drop characters that aren’t mapped on the keyboard.

## Variations

After `TypeText`, press the physical Space key and append more text. In a blank single-line field this leaves `Hello from C# again`.

```csharp
input.KeyPress(OnePlatform.Key.Space);
input.TypeText("again");
```

## Related recipes

- [Capture the screen in C#](https://recursiveai.org/oneplatform/cookbook/capture-the-screen-in-csharp/)
- [Test window input headlessly](https://recursiveai.org/oneplatform/cookbook/test-window-input-headlessly/)

## The short answer

Open a `SystemInput` session, use `ClickAt(x, y)` to move the pointer and click, then use `TypeText` to type into the focused window. For a key such as Space, use `KeyPress` instead of `TypeText`. These calls send events through the desktop, not through your OnePlatform app’s own event queue. Dispose the session when you’re done; on Wayland this closes the portal session.

## Can C# send keyboard and mouse input to a background app?

`SystemInput` doesn’t take an app name, process ID, or window handle. The desktop routes the click to whatever is under the pointer and sends typed text to whatever has keyboard focus. Keep the target visible and use a point inside the editable field, not just somewhere in its window. The click needs to give the field focus before the text can land there. A successful return means the OS took the events, not that your target handled them. If the receiver is part of your test, check its visible result or wait for its own acknowledgement before continuing.

## What permissions do simulated keyboard and mouse input need?

On Windows, run from an interactive desktop, with a target at the same or a lower integrity level; a normal app can’t use this to type into an elevated prompt. On macOS, `SystemInput` checks the sending app’s Accessibility permission without opening the system prompt. On X11, OnePlatform uses the XTEST extension and `libXtst`. The machine must have `libXtst` installed as a system library; you don’t ship it with your app. Under Xwayland, this backend reaches X windows only. On native Wayland, `OpenAsync` uses the XDG RemoteDesktop portal and waits for the user to approve the session. Use `OpenAsync` rather than blocking a UI thread while that dialog is open.

## Why does X11 sometimes drop non-ASCII text?

The XTEST backend sends keystrokes. If a character isn’t in the current keyboard map, OnePlatform temporarily assigns it to a spare keycode. Some receivers don’t follow those keyboard-map changes and drop the character. That’s why the sample uses ASCII rather than promising that `TypeText` works for every character in every app. Test the exact text against the receiver and keyboard layout you’ll use. `KeyPress` is for physical keys and shortcuts; it doesn’t fix missing character mappings.
