wiki/gofurther/evdev.md

79 lines
2.4 KiB
Markdown
Raw Normal View History

2022-08-13 00:26:05 +00:00
---
title: Share an input device with a guest using evdev
description:
published: true
2024-05-15 19:20:23 +00:00
date: 2024-05-15T19:20:21.209Z
2022-08-13 00:26:05 +00:00
tags:
editor: markdown
dateCreated: 2022-08-13T00:26:02.801Z
---
2022-08-25 10:40:46 +00:00
# Share an input device
2022-08-13 00:26:05 +00:00
2024-05-15 19:20:17 +00:00
In this section, we'll explore how to share a locally attached input device with a guest virtual machine.
2023-02-08 19:09:04 +00:00
2024-05-15 19:20:17 +00:00
## With evdev
2022-08-25 10:40:46 +00:00
2024-05-15 19:20:17 +00:00
As of libvirt version 7.4.0, the [Linux evdev event interface](https://www.kernel.org/doc/html/latest/input/input.html?highlight=evdev#evdev) can be used to share an input device physically attached to the host with a guest, in a low-latency manner.
2022-08-25 10:40:46 +00:00
2024-05-15 19:20:17 +00:00
### Preparation
2023-05-13 16:00:23 +00:00
2024-05-15 19:20:17 +00:00
Before sharing an input device, follow these steps:
- List available input devices on your host system, excluding those containing `if` in their name, including those containing `event` in their name:
2023-05-13 15:58:29 +00:00
```
ls /dev/input/by-id/* | grep event | grep -v if
```
2022-08-13 00:26:05 +00:00
2024-05-15 19:20:17 +00:00
This command should output the names of eligible devices.
Example output:
2022-08-13 00:26:05 +00:00
```
2023-05-13 15:56:23 +00:00
/dev/input/by-id/usb-Corsair_CORSAIR_HARPOON_RGB_PRO_Gaming_Mouse_1902B02BAF5E04655DEB612AF5001C05-event-mouse
/dev/input/by-id/usb-Logitech_G513_RGB_MECHANICAL_GAMING_KEYBOARD_156930783132-event-kbd
/dev/input/by-id/usb-Logitech_USB_Keyboard-event-kbd
/dev/input/by-id/usb-Logitech_USB_Optical_Mouse-event-mouse
2022-08-25 10:40:46 +00:00
```
2024-05-15 19:20:17 +00:00
- Make sure that the correct one is selected by registering its inputs in your console:
2022-08-25 10:40:46 +00:00
2022-08-25 20:26:04 +00:00
```
2023-05-13 15:56:23 +00:00
cat /dev/input/by-id/usb-Logitech_G513_RGB_MECHANICAL_GAMING_KEYBOARD_156930783132-event-kbd
2022-08-25 20:26:04 +00:00
```
2022-08-25 10:40:46 +00:00
2024-05-15 19:20:17 +00:00
This step ensures you're working with the desired input device.
- Test the device by interacting with it on the host system. You should see gibberish characters displayed on your screen:
2023-05-13 15:56:23 +00:00
2022-08-25 20:26:04 +00:00
```
<EFBFBD><EFBFBD>c $
2023-02-08 18:58:01 +00:00
<EFBFBD><EFBFBD>c<EFBFBD><EFBFBD><EFBFBD>c<EFBFBD><EFBFBD><EFBFBD>c<EFBFBD>$<24><>c<EFBFBD>$<24><><63><D78F><63><D78F>c
2022-08-25 20:26:04 +00:00
```
2023-02-08 19:09:53 +00:00
2024-05-15 19:20:17 +00:00
### Adding the input device to your virtual machine
- To share the input device with your virtual machine, add the following XML snippet to its domain definition (inside the <device> section):
2023-05-13 15:56:23 +00:00
```
<input type='evdev'>
<source dev='/dev/input/by-id/usb-Logitech_G513_RGB_MECHANICAL_GAMING_KEYBOARD_156930783132-event-kbd' grab='all' repeat='on'/>
</input>
```
2023-05-13 16:00:23 +00:00
### Usage
2023-05-13 15:59:21 +00:00
2024-05-15 19:20:17 +00:00
Once the virtual machine is started, the input device will be captured by the guest system.
2023-05-13 15:57:19 +00:00
> Press <kbd>Left Ctrl + Right Ctrl</kbd> simultaneously to switch your devices between the guest and the host.
{.is-info}
2023-05-13 15:56:23 +00:00
2023-05-13 16:00:23 +00:00
2023-05-13 15:56:23 +00:00
## Resources
2023-02-08 19:09:53 +00:00
2023-05-13 15:56:23 +00:00
* https://libvirt.org/formatdomain.html#input-devices
2023-02-08 19:09:53 +00:00
---
*[**Go to parent page**](https://wiki.phyllo.me/)*