How do you send keyboard input to a program?
That is, under a Linux GUI, is there a good manual (programmable) way, or tool, of simulating keyboard input on a running program on Linux, so that I can send from the command-line, e.g., "Control-T" to a Firefox process and "echo 'hello'\n" to a Gnome-Terminal process without actually focusing on each of those processes and typing in directly?
Enter keyboard characters literally as they are to be sent. The codes and functions are defined in the tables below. In the table below, keyboard keys are presented with the code that should be entered in the SendKeys window. To repeat keys, add a number of repeats to the key code as follows: {LEFT 42} or {h 10}.
xdotool
does have a way of sending keystrokes if limited to a focused window:
WID=`xdotool search "Mozilla Firefox" | head -1`
xdotool windowactivate $WID
xdotool key ctrl+l
It's an old topic, but one still may be looking for this, someone mentioned here solution where window must be activated when using xdotool. However you can specify window and even use xdotool to find it. Here is example I tried to accomplish, change it as you need.
xdotool key --window $(xdotool search --name "Spotify (Premium |Free )?- Linux Preview" | head -n1) ctrl+KP_Down
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With