Send keystrokes to non-active GUI application without occupying the keyboard
Use a nested X server to input keystrokes without changing focus or keyboard grab.Proof of concept:
Xephyr -resizeable :13export DISPLAY=:13xtermxdotool type rhabarber
The Xephyr
nested X server is started and will listen on local X socket 13 (whereas :0 typically identifies the currently running X server, but when multiple sessions are ran concurrently, it could be higher).Then we set DISPLAY environment variable to :13, so any X application we start will connect to Xephyr; xterm
is our target application here. Using xdotool
or any other tool we can send keystrokes.
As the target X server is identified through $DISPLAY
, applications can be started or input events triggered from elsewhere as well. If needed, you might also run a lightweight window manager within Xephyr, e.g. to 'maximize' the application so that it fills the whole Xephyr window.