xdotool
is a compiled program, you can use it from anywhere. And it may be pre-installed on your distribution. You orchestrate it with any scripting language. Comes recommended by many, but can get tedious when scripting more elaborate chains.
An example command to be used within any scripting language/shell:
xdotool type "Hello Unix.StackExchange Reader"
More can be found starting here: xdotool
XAUT
"(formerly X Automation)" is a C Library and a Python module "to programatically simulate keyboard and mouse use, as well as manipulate windows. The inspiration for this came from AutoIt as well as AutoHotkey".
On most recent distros xaut
or xautomation
should also be available.
An example py
script could look like:
import xaut
kbd = xaut.keyboard()
kbd.type("Hello Unix.StackExchange Reader{Return}")
This "forces" you to use Python, but if you do something more elaborate, like wanting to read input from AD or *SQL, you'll probably quickly appreciate the powers python gives you with the ecosystem of useful module it has.
To get a window id run:
sleep 5; xdotool getactivewindow
This will wait 5 seconds and then get the active window ID. Run this command, click on Firefox, and wait for it to finish. Use that ID in the next step.
You can send keystrokes directly to specific window, by executing:
xdotool type --window [window ID] Hello World
Use the command man xdotool
to get a full list of commands and functions!
Xdotool will generate key events and send them directly to window Firefox. But sending keystrokes to a specific window uses a different API than simply typing to the active window, and many applications just ignore them.
Best Answer
I've figured it out myself:
xdotool mousemove 500 100 getmouselocation --shell mousemove restore
This briefly moves the mouse to the specified position (x=500, y=100 in this example), prints
WINDOW
which is thewindowid
on top, then moves the mouse back.This is probably not the intended usage of mousemove, but I could not find any better way to do what I wanted.