uinput
Create and inject virtual input events
TLDR
Show resulting YAML device description merge and exit (dry-run)
Merge YAML device description(s) to resulting virtual device
Merge reference device description from device node(s) to resulting virtual device
SYNOPSIS
Not a standalone command. User-space applications interact with the `uinput` facility by opening the `/dev/uinput` device file and issuing specific `ioctl` commands to create, configure, and send events from virtual input devices.
PARAMETERS
N/A
As `uinput` is a kernel module interface accessed programmatically, it does not have command-line parameters like typical shell commands. Interaction is performed through `ioctl` system calls and writing data to the `/dev/uinput` device file.
DESCRIPTION
The `uinput` (User Input) facility is a Linux kernel module that enables user-space applications to create and manage virtual input devices. Instead of being a standalone shell command executed directly from the terminal, `uinput` provides a programmatic interface, typically exposed via the `/dev/uinput` device file.
This powerful capability allows user-space programs to simulate hardware input events, effectively emulating keyboards, mice, joysticks, touchpads, or other input devices. By writing specific `ioctl` commands and `input_event` structures to the `/dev/uinput` file, applications can send synthetic events directly into the kernel's input subsystem.
`uinput` is widely utilized for purposes such as:
• Input automation and scripting
• Remote control software
• Gaming emulation and custom controller setups
• Testing frameworks that require simulated user interaction
It bridges the gap between software logic and the kernel's native input handling, making it a fundamental component for advanced input management in Linux.
CAVEATS
Requires Root Privileges: Creating and managing virtual input devices typically requires root access or specific Linux capabilities (e.g., `CAP_SYS_ADMIN` or `CAP_NET_ADMIN`) to interact with `/dev/uinput`.
Security Implications: Malicious use of `uinput` could allow an unauthorized program to simulate user input, leading to potential security vulnerabilities or system compromise.
Programming Required: Utilizing `uinput` involves writing code (e.g., in C, Python, etc.) to interact with the device file and its specific `ioctl` commands, rather than simple shell scripting.
Kernel Module Dependency: The `uinput` kernel module must be loaded (`modprobe uinput`) for the `/dev/uinput` device file to exist and be functional.
LOADING THE MODULE
The `uinput` kernel module needs to be loaded into the kernel before it can be used. This can usually be done temporarily with: `sudo modprobe uinput`.
To ensure the module is loaded automatically on system boot, you can add `uinput` to a configuration file like `/etc/modules-load.d/uinput.conf` (or similar distribution-specific configuration paths).
COMMON USE CASES
`uinput` is extensively used for:
` • Input Automation: Scripting keyboard presses, mouse movements, or other input events for automated tasks and macros.
` • Remote Control: Implementing software that allows one system to control the input of another, such as virtual KVMs or desktop sharing.
` • Gaming Emulation: Creating virtual gamepads, joysticks, or custom controllers to map unusual input devices or software logic to standard game inputs.
` • Software Testing: Generating synthetic input events to rigorously test application behavior and responsiveness under various input conditions.
`
PROGRAMMING INTERFACE OVERVIEW
Using `uinput` typically involves the following steps in a user-space program:
` 1. Open `/dev/uinput`: Obtain a file descriptor to the `uinput` device.
` 2. Set Capabilities: Use `ioctl` calls (e.g., `UI_SET_EVBIT`, `UI_SET_KEYBIT`, `UI_SET_RELBIT`, `UI_SET_ABSBIT`) to specify which event types (keys, relative movements, absolute positions, etc.) the virtual device will support.
` 3. Create Device: Populate a `uinput_user_dev` structure with device information (name, vendor/product IDs, bus type) and use `ioctl(UI_DEV_CREATE)` to register the virtual device with the kernel.
` 4. Send Events: Write `input_event` structures to the `uinput` file descriptor to generate synthetic input events.
` 5. Destroy Device: When finished, use `ioctl(UI_DEV_DESTROY)` and close the file descriptor to unregister the virtual device.
`
HISTORY
The `uinput` facility has been an integral part of the Linux kernel's input subsystem since its introduction. Designed to provide a standardized, programmatic interface for user-space applications to create and control virtual input devices, it has evolved alongside the kernel's capabilities. Its development was driven by the need for robust methods to automate input, facilitate remote control, and enable various emulation scenarios, solidifying its role as a fundamental component for advanced input management in Linux.
SEE ALSO
modprobe(8), evdev(4), ioctl(2), input(4)