[TriLUG] sendmessage equivalent in X Windows?

Brian Phelps brphelps at ieee.org
Fri Mar 28 10:01:47 EDT 2008


I usually use XTest, there is an API call for grabbing a window. I
think: 
#aptitude install libxtst-dev
will install the development headers under Debian/Ubuntu

I believe there is also an api call for grabbing a window by several
different parameters.  Adding A menu? I have no idea how to do that,
maybe someone else here knows, it depends on what toolkit was used for
the app I guess:

Here is some example code:


#include <X11/extensions/XTest.h>
#include <stdlib.h>

#define KEY_DOWN True
#define KEY_UP   False

//the keycode constant KEYCODE_ESC = 9 was found using xev
#define KEYCODE_F11 95
#define KEYCODE_ESC 9
// To compile run: gcc -o testkey -lXtst testkey.c && ./testkey


int main() {
  Display *dpy = XOpenDisplay(NULL);
  if (!dpy) return 1;
   sleep(1);
  XTestFakeButtonEvent(dpy, 1, KEY_DOWN, CurrentTime);
  XTestFakeButtonEvent(dpy, 1, KEY_UP, CurrentTime);
   sleep(1);
  XTestFakeKeyEvent(dpy, KEYCODE_F11, KEY_DOWN, CurrentTime);
  XTestFakeKeyEvent(dpy, KEYCODE_F11, KEY_UP, CurrentTime);
  XCloseDisplay(dpy);
  return 0;
}


On Fri, 2008-03-28 at 08:58 -0400, Tim Jowers wrote:
> Hi,
> 
>   In Microsoft Windows I used to control Windows in other applications with
> sendmessage/postmessage and Window subclassing. This allows me to add a menu
> to an existing application and to simulate mouse clicks and other user input
> into the Windows. Is there an equivalent way to drive graphical applications
> in X Windows?
> 
>   Specifically, right now, I want to simulate some clicks on embedded video
> players in a web browser. E.g. Go to full-screen.
> 
> Thanks for any pointers,
> TimJowers




More information about the TriLUG mailing list