Skip to content

Arrow key not functional in QEMU monitor when using nographic on Windows 11 host

Host environment

  • Operating system: Windows 11 22H2
  • OS/kernel version: OS build 22621.1702
  • Architecture: x86_64
  • QEMU flavor: qemu-system-arm
  • QEMU version: QEMU emulator version 8.0.0 (v8.0.0-12024-gd6b71850be-dirty)
  • QEMU command line:
    ./qemu-system-arm -s -S -M virt -nographic

Emulated/Virtualized environment

  • Operating system: Linux
  • OS/kernel version: v6.1
  • Architecture: ARM

Description of problem

The arrow keys do not work on the Windows QEMU when using -nographic option. On the Linux QEMU they work.

Steps to reproduce

  1. Download the qemu source code from https://download.qemu.org/qemu-8.0.0.tar.xz. THe sha256sum of the file is bb60f0341531181d6cc3969dd19a013d0427a87f918193970d9adb91131e56d0.
  2. Prepare the build system on MSYS2 according to the instructions on https://wiki.qemu.org/Hosts/W32#Native_builds_with_MSYS2.
  3. Uncompress the source code using tar -xf qemu-8.0.0.tar.xz.
  4. Change the working directory to qemu-8.0.0/. The build configuration command is ./configure --target-list=arm-softmmu --extra-cflags="-g -ggdb"
  5. Run the command ./qemu-system-arm -s -S -M virt -nographic.
  6. Press Ctrl-C A to switch to QEMU monitor.
  7. Input "help" command to the monitor.
  8. Press Arrow-Up key.
  9. The previous "help" command does not appear in the monitor prompt.

Additional information

  1. The pre-built binary downloaded from https://qemu.weilnetz.de/w64/qemu-w64-setup-20230424.exe has the same behaviour.
  2. The QEMU from MSYS2, pacman -S mingw-w64-x86_64-qemu, has the same behaviour.
  3. If the "-nographic" option is removed, the arrow-up key works in the GTK console.
  4. Neither of arrow-up, arrow-down, arrow-right, arrow-left key work.
  5. If the valid kernel and rootfs are added in the command line by "-kernel" and "-initrd" options, neither key work after booting to the Linux successfully.
  6. If the code dwMode |= ENABLE_LINE_INPUT; in the function qemu_chr_open_stdio() is changed to dwMode |= ENABLE_LINE_INPUT|ENABLE_VIRTUAL_TERMINAL_INPUT;, build again. All arrow keys work.
  7. The VT sequence support was added in EmulatorPkg/Win/Host/WinThunk.c by this commit edk2@5601e90d.
  8. The above commit is to add VT sequence support at compile-time. Microsoft provides some code to enable it at run-time on https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example-of-enabling-virtual-terminal-processing.
  9. The function readline_handle_byte() is not called when the VT sequence is not enabled.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information