Introducing a new way to review your PRs.

Read the announcement

aprilnea / openlogi

⚡️A native, local-first alternative to Logitech Options+, written in Rust 🦀 — remap buttons, DPI, and SmartShift over HID++. No account, no telemetry.

View on GitHub

25 documents · Updated Nov 23, 2026

docs / input-injection

Synthetic input injection

Synthetic input injection turns an OpenLogi action into an operating-system action. The openlogi-inject crate keeps the shared action meaning separate from desktop input, then sends the result through the native event path or a platform service. This lets button and gesture bindings control keyboard, mouse, scroll, media, window, system, text, and command behavior on supported desktop systems. See Input and overlay controls for the wider input flow.

Injection boundary

The injection boundary is the hand-off from OpenLogi's platform-neutral action vocabulary to the desktop environment. Callers provide an Action; the injector classifies its effect and then emits an event, calls a system service, starts a background task, or does nothing when the action belongs to another layer.

The public crate surface exposes one action entry point plus focused helpers for held chords, scroll, desktop switching, and platform diagnostics. The shared shortcut model uses a KeyCombo, which describes modifiers and a USB HID keyboard usage instead of a platform key code. Each platform can therefore preserve the same binding meaning while selecting its own native input form. crates/…/lib.rs defines this boundary.

flowchart LR
    A[Configured action] --> B[Action effect]
    B -->|Input event| C[Platform event path]
    B -->|System behavior| D[Platform service]
    B -->|Command or workflow| E[Background task]
    B -->|Device or agent action| F[Hook or HID layer]
    B -->|None| G[No output]
    C --> H[Desktop application]
    D --> H

Action classification

The injector groups actions by the user-visible result they seek. This keeps device-owned behavior out of the operating-system event path and gives each platform a clear place to handle unsupported effects.

Effect familyResult
Keyboard and mouseEmit press and release events.
ScrollEmit vertical or horizontal wheel movement.
Media and system behaviorUse a native shortcut or desktop service.
Text and workflowsRun supported text, key, delay, and command steps in order.
Application targetOpen a configured application, folder, path, or URL.
Agent-side actionLeave handling to the hook or HID layer.
NoneSuppress the input.

An action keeps one owner. For example, opening an application is handled as an application request, while device controls such as DPI and SmartShift remain with the device-control path.

References: crates/…/inject.rs• L401-489 crates/…/linux.rs• L39-61 crates/…/windows.rs• L210-231

Held chord lifecycle

A held chord is a synthetic key chord whose down edge stays active until the physical press ends. ModifiersOnly taps the ordinary key and holds only its modifiers. WholeChord keeps the ordinary key down as well. The returned HeldChord is the release owner; dropping it releases the synthetic output.

The injector tracks ownership of physical outputs across active chords. Shared modifiers stay down until their last owner ends, and a modifier that the user already holds is not released by the injector. Replacing a binding releases only keys that no longer belong to the new chord. Platform mappings are resolved before ownership is counted, so outputs that share one physical key remain balanced. This prevents overlapping bindings from cutting off one another.

References: crates/…/inject.rs• L49-68 crates/…/inject.rs• L160-263 crates/…/inject.rs• L517-638 crates/…/keycode.rs• L127-150

Platform event paths

Each supported operating system exposes the same action entry point but uses its own event and service path. The backend chooses the closest native behavior rather than claiming that one desktop action has identical meaning everywhere.

PlatformInput boundaryService boundary
macOSCore Graphics events and an optional virtual keyboardAccessibility, desktop, media, and system-defined services
LinuxOne shared virtual input deviceD-Bus and desktop-specific services or helpers
WindowsWin32 SendInput eventsNative Windows shortcuts and the command shell

macOS event path

The macOS backend emits keyboard, mouse, and scroll events through the system input path. It also uses native services for media controls, browser and menu actions, desktop Spaces, window actions, screenshots, and sleep when a plain key event is not the right system interface.

The shared HID shortcut model is translated to macOS virtual keycodes. Layout-aware and menu-aware paths preserve the meaning of shortcuts in the frontmost application. The optional virtual keyboard carries events that need a real HID boundary; Core Graphics remains the fallback when the virtual device cannot accept an edge. Key identity stays stable across press and release, including keypad keys and the macOS representation of Print Screen as F13.

Synthetic keyboard and mouse events carry an OpenLogi source marker. This lets the receiving input hook distinguish an emitted action from new physical input. See Global input hooks for the receiving side.

References: crates/…/macos.rs• L106-137 crates/…/macos.rs• L369-416 crates/…/macos.rs• L465-603 crates/…/keycode.rs• L127-162 crates/…/tests.rs• L240-341

Linux virtual device path

The Linux backend presents one shared virtual input device for keyboard, mouse-button, media, and wheel events. It creates the device on demand and waits for the desktop input stack to discover it before the first event. The device exposes scroll axes but not cursor movement, so injected actions are not treated as pointer motion.

Linux-native services fill gaps that a virtual key cannot cover. D-Bus handles session lock, suspend, desktop actions, and media-player control. The active desktop selects the supported scope: GNOME, KDE, and Hyprland do not receive the same window or workspace substitute when their behavior would differ. Fixed helper programs have bounded waits and fall back to a desktop shortcut when they are unavailable.

Text injection is not available on Linux. Shell commands and supported workflow steps run away from the input caller, so a delay or command does not block new input. Wheel input keeps fractional distance and emits both high-resolution and legacy wheel information when the values can be represented.

References: crates/…/linux.rs• L39-61 crates/…/linux.rs• L137-255 crates/…/linux.rs• L349-445 crates/…/linux.rs• L499-533 crates/…/linux.rs• L584-623 crates/…/linux.rs• L703-756

Windows input path

The Windows backend sends keyboard, mouse, wheel, browser, and media events through SendInput. It maps the shared HID usage to a Windows virtual key and includes the active foreground layout's scan-code meaning when the receiving application needs a physical key. Extended-key identity is preserved for navigation, editing, Windows, keypad, and other keys that share scan codes.

Windows maps window, desktop, lock, capture, and media actions to their nearest native shortcuts. Browser navigation uses dedicated browser keys. Text injection and sleep do not have a supported path at this boundary, so those actions are skipped or logged. Shell commands run through the Windows command shell without opening a console window.

References: crates/…/windows.rs• L102-130 crates/…/windows.rs• L159-207 crates/…/windows.rs• L210-342 crates/…/windows.rs• L507-621

Scroll output

Scroll injection turns ScrollDelta into the units accepted by each platform. The public boundary rejects non-finite input and keeps fractional distance across frames, so high-resolution motion does not lose distance through repeated rounding.

The two smooth-scroll contracts have different meanings:

  • post_smooth_scroll emits motion without declaring a trackpad gesture. This is the normal path for animated wheel movement.
  • post_phased_scroll carries gesture phases where an application must see a complete gesture. macOS posts terminal zero-distance frames when needed to keep the lifecycle balanced.

Linux and Windows have no matching phase field. They preserve the distance through their native wheel units instead. Pixel-based scroll output is therefore available only on macOS, while wheel-tick input has a path on all three platforms.

References: crates/…/inject.rs• L699-849 crates/…/linux.rs• L703-756 crates/…/windows.rs• L467-505

Synthetic event feedback

Injected input can return through OpenLogi's global input hook. macOS synthetic keyboard and mouse events carry a source marker, and the optional virtual keyboard has its own product identity. The hook uses these ownership signals to ignore the injector's output instead of treating it as new user input.

This boundary prevents a remapped click or key from starting a new gesture and creating an input loop. See Global input hooks for the receiving side, Visual overlay for UI feedback that can accompany an action, and Camera control for a related gesture-driven control path.

References: crates/…/inject.rs• L864-870 crates/…/macos.rs• L356-366 crates/…/tests.rs• L431-438

Example-driven usage

The examples provide a direct path to exercise the public injection boundary without first connecting a physical button. They parse the shared action and shortcut forms, wait for a target window, and make the resulting desktop behavior visible.

sequenceDiagram
    participant E as Example
    participant I as Injector
    participant O as Operating system
    participant W as Focused window
    E->>E: Parse action and wait
    E->>I: Execute action
    I->>O: Emit event or call service
    O->>W: Apply the action

Action injection example

inject_action sends named actions or a custom shortcut after a focus delay. It is useful for checking one action, a timed series, Linux device output, and the selected dispatch path without changing application configuration.

References: crates/…/inject_action.rs• L1-35 crates/…/inject_action.rs• L47-62 crates/…/inject_action.rs• L131-161

Held chord example

hold_chord keeps a parsed chord active for a fixed time and releases it when the returned owner is dropped. Its default mode shows a modifier-only hold; --whole-chord shows a hold that keeps the ordinary key down. This makes the two press contracts easy to compare with a desktop key monitor.

References: crates/…/hold_chord.rs• L1-31 crates/…/hold_chord.rs• L33-70 crates/…/hold_chord.rs• L74-125

Cross-platform action coverage

The shared action name describes the intended user effect, not one identical low-level event. Each backend uses a native equivalent when one exists and makes unsupported scope or service differences explicit.

Action groupCross-platform expectation
Editing and tab shortcutsUse the platform's normal modifier convention.
Custom shortcutsStart with the shared HID key and map it to native key data.
Browser navigationUse native browser buttons or platform shortcuts.
Window and desktop actionsUse system shortcuts or services that match the platform's scope.
Media actionsUse the system media path or a media-player service.
Text and scripted workflowsRun only the steps that have a matching platform path.
Smooth scrollingPreserve distance everywhere; preserve gesture phases only where supported.
Device controlsStay outside operating-system event injection.

When an action changes, the shared vocabulary and each platform effect mapping must still agree. A missing mapping can turn a valid binding into a no-op, while a missing native equivalent should remain an explicit limitation.

References: crates/…/inject.rs• L401-445 crates/…/linux.rs• L73-100 crates/…/windows.rs• L234-266

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep Action names stable because they are part of the stored configuration format.
  • Update the effect mapping, platform key mapping, and example parsing together when adding or changing an action.
  • Preserve held-chord ownership across one-shot events, replacements, user-held modifiers, and drop-based release.
  • Keep the macOS synthetic-event marker aligned with the global hook and virtual keyboard identity.
  • Keep scroll accumulation, wheel units, gesture phases, and zero-distance terminal frames aligned with their callers.
  • Keep Linux virtual-device capabilities aligned with every key, button, media, and wheel event it emits.
  • Keep Linux desktop service selection tied to the correct desktop scope and keep fixed compositor helpers allowlisted.
  • Keep Windows foreground-layout lookup, scan-code data, and extended-key flags aligned for both key edges.
  • Keep the examples aligned with the shared action vocabulary and held-chord contract.

Important failure modes

TriggerConsequenceGuard
The platform has no equivalent for an actionThe action is skipped or only partly supported.Keep the limitation explicit and log unsupported paths where useful.
Linux cannot access /dev/uinputKeyboard, mouse, media, and wheel actions produce no OS input.Log the creation failure and use the device-path helper for diagnosis.
Linux creates the device before the desktop discovers itThe first action can be dropped.Settle the device before its first event.
A Linux desktop helper is missing, fails, or times outThe native action falls back to a shortcut or is skipped.Use fixed allowlisted helpers, bounded waits, and the defined fallback.
macOS virtual keyboard setup or a report failsKey output uses the fallback path or a held key could become unbalanced.Treat the virtual keyboard as optional and restore stranded keys through the fallback.
macOS synthetic event ownership is not markedInjected input can re-enter the global hook and start an input loop.Preserve the event marker and virtual keyboard identity contract.
A Windows key has no usable native mapping or layout scan codeA custom shortcut can be ignored or reach the wrong physical shortcut.Keep the HID mapping and foreground-layout lookup complete.
A held chord owner is dropped or replaced at the wrong timeA chord can release too soon or release a key owned by another chord.Keep the release owner for the full physical press and use the replacement path.
A workflow uses unsupported text or script stepsThat step has no effect while the workflow continues.Report unsupported steps instead of blocking the input caller.
Scroll input is non-finite or unsupported on the platformThe frame is ignored.Validate input at the boundary and provide wheel ticks where pixel output is unavailable.

Key files

FileWhy to read it
crates/…/lib.rsShows the public injection boundary used by the rest of the application.
crates/…/inject.rsDefines action dispatch, held-chord ownership, scroll contracts, and synthetic-event identity.
crates/…/linux.rsExplains the Linux virtual device, desktop service choices, helper fallbacks, and wheel output.
crates/…/macos.rsExplains macOS native actions, layout-aware shortcuts, text output, and event ownership.
crates/…/keycode.rsDefines the shared relationship between HID usages and macOS key identity.
crates/…/tests.rsShows the virtual keyboard's routing, release, and failure contract.
crates/…/windows.rsExplains Windows native actions, layout-aware key output, held modifiers, and wheel output.
crates/…/uinput.rsOwns Linux virtual-device naming and recognition.
crates/…/inject_action.rsProvides a direct manual path for sending actions.
crates/…/hold_chord.rsProvides a direct manual path for comparing held-chord behavior.
crates/…/action.rsDefines the shared action vocabulary and ownership split.
crates/…/key_combo.rsDefines the platform-neutral custom shortcut form.