5

On Ubuntu desktop, can I use xdotool to mouse click (e.g. click a link) and press some keys (e.g. ctrl+s) on a window (e.g. Firefox's window) that is not in the front, so that I can work on another different window which may need to lie on top of the other windows, while at the same time, let xdotool to work on a hidden window? Thanks.

5

You can send keystrokes directly to specific window, by executing:

xdotool type --window Firefox hello

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. (source: man xdotool, link)

Also it says that Firefox 3 seemed to ignore all input when it does not have focus, not sure about recent versions.

  • Thanks. How about other browsers, such as google chrome? – Tim May 5 '15 at 14:44
  • I have tried on Chromium, doesn't work. But works in Xterm, for example (if SendEvents is enabled in ctrl+click menu). – kirill-a May 5 '15 at 19:33
  • It's not that Firefox ignores events when it doesn't have focus. Xdotool has two methods to generate fake events. One is synthesizing events, which can send an event to any window, but the receiver is informed that the event is synthetic and many applications drop synthetic events (out of a misguided security concern — if you let other users access your X session, that's not the only thing you need to worry about). Another method is the XTEST extension, which generates “genuine-looking” events, but that method only works to the focused window. – Gilles May 5 '15 at 23:22
  • no matter what i do, xdotool is simply typing them in the LXTerminal I ran the command in! – Michael yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.