Script issue (xdotool) when Qemu/KVM window is active

I have a “pixel change” bash script which triggers an xdotool action when something happens on the left side of the screen. The script works fine when I’m working in any window on the right side of the screen, with one exception: when I’m working in a Windows machine on Virtual Machine Manager. I’m on i3wm.

xdotool search --name 'Jobboard - Mozilla Firefox' windowactivate --sync windowfocus key f key y

The above line activates Firefox and yet outputs “fy” in whatever Windows app I’m in at the moment.

I tried breaking it down into multiple commands to no avail. How do I keep xdotool to make its thing in the correct window as intended?

EDIT: the issue is fixed by installing spice-guest-tool on the guest machine, however… spice-guest-tools messes with some other stuff, i.e. advanced clipboard management in Windows, and I’d prefer not to use it.

My apologies for not fully understanding your problem.
Here is a sketch script which can be called by keyboard shortcut and changes the active window by wmctrl.
(In i3 config I uncommented line
default_border normal
to see the active window ID in yad title bar at the time of keyboard shortcut was activated)
Find the 2 lines that may help you.

#!/bin/sh
#list windows and select which one to activate
rm -f $HOME/mywins.txt
ACTWIN=$(wmctrl -lp | grep $(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | \
 awk '{print $5}' | sed 's/,//' | sed 's/^0x/0x0/'))
 WINAME=$(echo $ACTWIN | awk '{ print $1 }')

wmctrl -lx > mywins.txt

awk '{ print $1 "\t" $3 }' mywins.txt > mywid_cl.txt

declare -a data
while IFS=$'\t' read -r vorname nachname
do
    data+=("$vorname" "$nachname")
done < mywid_cl.txt
echo $WINAME
yad --title="$WINAME" --width=500 --height=500 --list \
--select-action="/bin/sh -c \"printf \%\s'\t' %s > $HOME/mynextwin.txt\"" \
--column="Name" --column="Win" "${data[@]}"

SKIPTO=$(awk -F '\t' '{print $1}' $HOME/mynextwin.txt)
    wmctrl -i -R $SKIPTO