I'm on Mac, but this should be pretty similar on Linux. I'm not really sure how this behaves on Windows, I'll let someone else poke around on that point.
One can enable monitor by creating a socks file by adding the monitor parameter to the QEMU command:
Code: Select all
-monitor unix:/tmp/qemu-monitor.sock,server,nowait
QEMU will create that file when it starts up.
So, the first thing I thought is useful is to send a cmd+opt+esc combo to QEMU. If I try that combination I get macOS 15's "force quit" window.
To access the monitor directly, one can hold ctrl+opt+2. To return to the emulator's interface, ctrl+opt+1.
To access the monitor from the command line, do this:
Code: Select all
nc -U /tmp/qemu-monitor.sock
That should show a prompt "(qemu)".
If that doesn't work, perhaps you are running QEMU as root, like me, then just sudo it. Ctrl+C should close the monitor.
To send keys, use the command "sendkey" to the monitor. Most keys are just their names, e.g. 'esc', 'tab', 'f1', etc. The option key is 'alt' and the command key is 'meta_l' or 'meta_r'.
Letters and numbers are their own values. (Yes, we can type texts like this.)
You can send a "close window" command like so:
Code: Select all
sendkey meta_l-w
Code: Select all
sendkey meta_l-alt-esc 100
You can send the command to the monitor without opening the monitor like so:
Code: Select all
echo "sendkey meta_l-alt-esc 100" | nc -U /tmp/qemu-monitor.sock
If you want to automate this as an environment function, and not enter the password every time, this is where things get complicated. But it's doable.
I put my password into a text file on my mac. It's not really safe if people can access it, so be careful when doing this. I get the value from the file and issue commands as sudo. I wrapped the monitor code in separate functions and I added root versions. Like so:
Code: Select all
qemu::send:cmd:opt:esc() {
echo "sendkey meta_l-alt-esc 100" | nc -U /tmp/qemu-monitor.sock
}
qemu:force() {
pwd=$(cat ~/Profile/Variables/pwd.txt)
echo $pwd | sudo -SE zsh -c '
source ~/.zshrc
qemu::send:cmd:opt:esc
'
}
autoload -Uz qemu::send:cmd:opt:esc
Another handy thing I've been using is a command to mount a CD-ROM image on the fly. I'm using this to test the Retro68 tool, and it's been very handy. First, in the QEMU command, I added these options:
Code: Select all
-device ide-cd,bus=ide.1,drive=cd0 \
-drive if=none,id=cd0,media=cdrom \
etc
Code: Select all
echo "change cd0 /Users/user/Classic/Discs/MyImage.img" | nc -U /tmp/qemu-monitor.sock
Code: Select all
#!/bin/bash
# Path to your CD-ROM image
CDROM_IMAGE="$1"
# Send commands to QEMU monitor socket
send_monitor_command() {
printf "$1\n" | nc -U /tmp/qemu-monitor.sock
}
# Eject current media (if any)
send_monitor_command "eject -f cd0"
# Insert new media
send_monitor_command "change cd0 $CDROM_IMAGE"
You can forcefully quit it, create a snapshot of the machine, pause and resume, generate a memory dump, manipulate the mouse, get useful info, and some advanced stuff.
I imagine these tools can be used for potential user interfaces, bash scripts, apple scripts, and other clever things.