20.26. Sending a Keystroke Combination to a Specified Guest Virtual machine

The virsh send-key domain --codeset --holdtime keycode command allows you to send a sequence as a keycode to a specific guest virtual machine. Each keycode can either be a numeric value or a symbolic name from the corresponding codeset below.
If a --holdtime is given, each keystroke will be held for the specified amount in milliseconds. The --codeset allows you to specify a code set, the default being Linux, but the following options are permitted:
  • linux - choosing this option causes the symbolic names to match the corresponding Linux key constant macro names and the numeric values are those offered by the Linux generic input event subsystems.
  • xt - this will send a value that is defined by the XT keyboard controller. No symbolic names are provided
  • atset1 - the numeric values are those that are defined by the AT keyboard controller, set1 (XT compatible set). Extended keycodes from the atset1 may differ from extended keycodes in the XT codeset. No symbolic names are provided.
  • atset2 - The numeric values are those defined by the AT keyboard controller, set 2. No symbolic names are provided.
  • atset3 - The numeric values are those defined by the AT keyboard controller, set 3 (PS/2 compatible). No symbolic names are provided.
  • os_x - The numeric values are those defined by the OS-X keyboard input subsystem. The symbolic names match the corresponding OS-X key constant macro names.
  • xt_kbd - The numeric values are those defined by the Linux KBD device. These are a variant on the original XT codeset, but often with different encoding for extended keycodes. No symbolic names are provided.
  • win32 - The numeric values are those defined by the Win32 keyboard input subsystem. The symbolic names match the corresponding Win32 key constant macro names.
  • usb - The numeric values are those defined by the USB HID specification for keyboard input. No symbolic names are provided.
  • rfb - The numeric values are those defined by the RFB extension for sending raw keycodes. These are a variant on the XT codeset, but extended keycodes have the low bit of the second bite set, instead of the high bit of the first byte. No symbolic names are provided.

Example 20.53. How to send a keystroke combination to a guest virtual machine

The following example sends the Left Ctrl, Left Alt, and Delete in the Linux encoding to the guest1 virtual machine, and holds them for 1 second. These keys are all sent simultaneously, and may be received by the guest in a random order:
virsh send-key guest1 --codeset Linux --holdtime 1000 KEY_LEFTCTRL KEY_LEFTALT KEY_DELETE

Note

If multiple keycodes are specified, they are all sent simultaneously to the guest virtual machine and as such may be received in random order. If you need distinct keycodes, you must run the virsh send-key command multiple times in the order you want the sequences to be sent.