XtrmJosh
XtrmJosh

Reputation: 949

PostMessage for Linux

I've written a few programs on Windows which utilise PostMessage to send keystrokes and mouse events to a target application. I cannot find a way to do this on Linux except possibly using DBus, but what I've seen so far suggests that I would need the target applications window to be focused.

The other alternative I've found is X11 API (keysym.h), but this also appears to require a focused window.

Is there a way to send mouse/keyboard events to a window which is not in focus on Linux?

Upvotes: 1

Views: 1525

Answers (1)

Přemysl Šťastný
Přemysl Šťastný

Reputation: 1852

If I've got it right, you want method how to trigger event to application, which is running on X server. There are many methods, how to do it. One of most easier is throw tool known as xdotool.

http://www.semicomplete.com/projects/xdotool/

Example:

xdotool type --window Firefox hello

This shall send 'hello' trigger keyboard sequence without focusing Firefox itself.

Upvotes: 1

Related Questions