crosvm supports virtio-input devices that provide human input devices like multi-touch devices, trackpads, keyboards, and mice.
Events may be sent to the input device via a socket carrying virtio_input_event structures. On Unix-like platforms, this socket must be a UNIX domain socket in stream mode (AF_UNIX/AF_LOCAL, SOCK_STREAM). Typically this will be created by a separate program that listens and accepts a connection on this socket and sends the desired events.
On Linux, it is also possible to grab an evdev device and forward its events to the guest.
The general syntax of the input option is as follows:
--input DEVICE-TYPE[KEY=VALUE,KEY=VALUE,...]
For example, to create a 1920x1080 multi-touch device reading data from /tmp/multi-touch-socket:
crosvm run \ ... --input multi-touch[path=/tmp/multi-touch-socket,width=1920,height=1080] ...
The available device types and their specific options are listed below.
Linux only.
Passes an event device node into the VM. The device will be grabbed (unusable from the host) and made available to the guest with the same configuration it shows on the host.
Options:
path (required): path to evdev device, e.g. /dev/input/event0Example:
crosvm run \ --input evdev[path=/dev/input/event0] \ ...
Add a keyboard virtio-input device.
Options:
path (required): path to event source socketExample:
crosvm run \ --input keyboard[path=/tmp/keyboard-socket] \ ...
Add a mouse virtio-input device.
Options:
path (required): path to event source socketExample:
crosvm run \ --input mouse[path=/tmp/mouse-socket] \ ...
Add a multi-touch touchscreen virtio-input device.
Options:
path (required): path to event source socketwidth (optional): width of the touchscreen in pixels (default: 1280)height (optional): height of the touchscreen in pixels (default: 1024)name (optional): device name stringIf width and height are not specified, the first multi-touch input device is sized to match the GPU display size, if specified.
Example:
crosvm run \ ... --input multi-touch[path=/tmp/multi-touch-socket,width=1920,height=1080,name=mytouch2] ...
Add a rotating side button/wheel virtio-input device.
Options:
path (required): path to event source socketExample:
crosvm run \ --input rotary[path=/tmp/rotary-socket] \ ...
Add a single-touch touchscreen virtio-input device.
Options:
path (required): path to event source socketwidth (optional): width of the touchscreen in pixels (default: 1280)height (optional): height of the touchscreen in pixels (default: 1024)name (optional): device name stringIf width and height are not specified, the first single-touch input device is sized to match the GPU display size, if specified.
Example:
crosvm run \ ... --input single-touch[path=/tmp/single-touch-socket,width=1920,height=1080,name=mytouch1] ...
Add a switches virtio-input device. Switches are often used for accessibility, such as with the Android Switch Access feature.
Options:
path (required): path to event source socketExample:
crosvm run \ --input switches[path=/tmp/switches-socket] \ ...
Add a trackpad virtio-input device.
Options:
path (required): path to event source socketwidth (optional): width of the touchscreen in pixels (default: 1280)height (optional): height of the touchscreen in pixels (default: 1024)name (optional): device name stringExample:
crosvm run \ ... --input trackpad[path=/tmp/trackpad-socket,width=1920,height=1080,name=mytouch1] ...
Add a custom virtio-input device.
path (required): path to event source socketconfig-path (required): path to file configuring devicecrosvm run \ --input custom[path=/tmp/keyboard-socket,config-path=/tmp/custom-keyboard-config.json] \ ...
This config_path requires a JSON-formatted configuration file. “events” configures the supported events. “name” defines the customized device name, “serial” defines customized serial name, “properties” defines the device properties and “axis_info” defines the axis information.
An example configuration file covering all property types can be found in /devices/tests/data/input/example_custom_multitouchscreen_config.json. It configures a device equivalent to the default multitouch screen device (crosvm run --input=multi-touch,...). Another example can be found in /devices/tests/data/input/example_custom_keyboard_config.json, which configures a device equivalent to the default keyboard (crosvm run --input=keyboard,...).
Here is a portion of the example config file:
{{#include ../../../../devices/tests/data/input/example_custom_multitouchscreen_config.json::12}}
...
{{#include ../../../../devices/tests/data/input/example_custom_multitouchscreen_config.json:23:33}}
...
{{#include ../../../../devices/tests/data/input/example_custom_multitouchscreen_config.json:68:}}