2.4 KiB
2.4 KiB
title, description, published, date, tags, editor, dateCreated
title | description | published | date | tags | editor | dateCreated |
---|---|---|---|---|---|---|
Share an input device with a guest using evdev | true | 2024-05-15T19:20:21.209Z | markdown | 2022-08-13T00:26:02.801Z |
Share an input device
In this section, we'll explore how to share a locally attached input device with a guest virtual machine.
With evdev
As of libvirt version 7.4.0, the Linux evdev event interface can be used to share an input device physically attached to the host with a guest, in a low-latency manner.
Preparation
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 containingevent
in their name:
ls /dev/input/by-id/* | grep event | grep -v if
This command should output the names of eligible devices.
Example output:
/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
- Make sure that the correct one is selected by registering its inputs in your console:
cat /dev/input/by-id/usb-Logitech_G513_RGB_MECHANICAL_GAMING_KEYBOARD_156930783132-event-kbd
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:
<EFBFBD><EFBFBD>c $
<0A><>c<EFBFBD><63><EFBFBD>c<EFBFBD><63><EFBFBD>c<EFBFBD>$<24><>c<EFBFBD>$<24><>c<63><D78F>c<63><D78F>c
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 section):
<input type='evdev'>
<source dev='/dev/input/by-id/usb-Logitech_G513_RGB_MECHANICAL_GAMING_KEYBOARD_156930783132-event-kbd' grab='all' repeat='on'/>
</input>
Usage
Once the virtual machine is started, the input device will be captured by the guest system.
Press Left Ctrl + Right Ctrl simultaneously to switch your devices between the guest and the host. {.is-info}