<!-- Source: https://medius.k4tech.net/library/inject -->
# Inject

_Press and release any input_

One field-generic verb drives every momentary input. [`inject`](/library/inject.md#inject) takes any [`Usage`](/library/types/enums.md#usage) (a button, key, or media usage); [`press`](/library/inject.md#press), [`release`](/library/inject.md#press), and [`force_release`](/library/inject.md#press) are convenience wrappers. Each call queues one [fire-and-forget](/native/injection.md#fire-and-forget) [`INJECT`](/native/commands/inject.md#inject) frame.

## inject

_Press or release any usage_

```text
fn inject(&self, usage: impl Into<Usage>, action: Action) -> Result<()>
```

_Fire-and-forget_

`usage` is any [`Usage`](/library/types/enums.md#usage): a [`Button`](/library/types/enums.md#button), a [`Key`](/library/types/structs.md#key), and a [`MediaKey`](/library/types/structs.md#media-key) all convert into one, so one verb drives every input class. `action` is the shared [`Action`](/library/types/enums.md#action) tri-state: press, soft-release, or force-release.

A usage the cloned device can't report is a no-op, and there's no firmware click or chord (compose a press then a client-timed release). [`reset`](/library/admin.md#reset) releases every override.

#### EXAMPLE

```rust
use medius::{Button, Key, MediaKey, Action};

device.inject(Button::Left, Action::Press)?;        // mouse button
device.inject(Key::LEFT_SHIFT, Action::Press)?;     // keyboard key
device.inject(MediaKey::VOLUME_UP, Action::Press)?; // media key
```

## Press and release

_press, release, force_release_

```text
fn press(&self, usage: impl Into<Usage>) -> Result<()>
```

```text
fn release(&self, usage: impl Into<Usage>) -> Result<()>
```

```text
fn force_release(&self, usage: impl Into<Usage>) -> Result<()>
```

_Fire-and-forget_

The convenience wrappers over [`inject`](/library/inject.md#inject), generic over any [`Usage`](/library/types/enums.md#usage). `press` holds it down, `release` clears the box's press or force while a physical hold stays down, and `force_release` forces it up over a physical press.

#### EXAMPLE

```rust
use medius::{Button, Key};

device.press(Button::Left)?;          // held down
device.release(Button::Left)?;        // your press cleared; a physical hold survives
device.force_release(Key::LEFT_GUI)?; // forced up even under a physical hold
```

## On AsyncDevice

_Same calls, still synchronous_

[`AsyncDevice`](/library/features/async.md) queues these frames too, so no `.await`; only the query methods are `async`.

#### EXAMPLE

```rust
use medius::{Button, Key};

// async_device: medius::AsyncDevice
async_device.press(Button::Left)?;   // no .await, it just queues the frame
async_device.press(Key::ESCAPE)?;
```

> **Note**
>
> Build an `AsyncDevice` with `cargo add medius --features async` and [`AsyncDevice::open`](/library/connection.md#async) or `Device::into_async`.
