Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!widener!ukma!memstvx1!utkcs2!emory!wuarchive!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!xn.ll.mit.edu!hsdndev!bunny!bunny.gte.com!vp01 From: vp01@bunny.gte.com (Vincent Phuah) Newsgroups: comp.windows.x Subject: XSendEvent question Message-ID: <1991May8.113157@bunny.gte.com> Date: 8 May 91 15:31:57 GMT Sender: news@gte.com Reply-To: vphuah@gte.com Followup-To: vp01@gte.com Organization: GTE Laboratories, Inc. Lines: 107 Keywords:XSendEvent, PointerWindow Hi there, Wonder if someone could help me. I'm trying to simulate button press/release events using XSendEvent with the PointerWindow option, but having a lot of trouble getting it to work. Would appreciate if you could take a look at my code and tell me what I'm doing wrong. Instead of using the PointerWindow option, I tried using the window id of a command button in the event structure and the XSendEvent routine, but that didn't work either. Thanks for your help in advance. ----- /* * * Code to send an button press/release event to * a window(likely a command button window) specified by the pointer. */ #include "xbook.h" int SendButtonPress(); SendButtonPress( display, window, state) Display *display; Window window; int state; /* unused */ { XButtonEvent event; int status; event.type = ButtonPress; event.display = display; event.root = RootWindow( display, DefaultScreen( display )); event.same_screen = True; event.x = 0; event.y = 0; event.x_root = 0; event.y_root = 0; event.subwindow = (Window)None; event.time = CurrentTime; event.state = 0x00; status = XSendEvent( display, PointerWindow, False , ButtonPressMask, &event ); sleep(1); if ( status != 0 ) { event.type = ButtonRelease; event.state = Button1Mask; event.time = CurrentTime; status = XSendEvent( display, PointerWindow, False, ButtonReleaseMask, &event ); } XFlush(display); return( status ); } main(argc,argv) int argc; char **argv; { Display *display; if (argc != 2) { printf("Must specify display name.\n"); exit(0); } if ((display = XOpenDisplay(argv[1])) == NULL) { printf("Cannot open display\n"); exit(-1); } if (SendButtonPress(display, PointerWindow, 0x0100) > 0) printf("Send Button Event ok\n"); else printf("SentEvent Not OK\n"); exit(0); } -- +-+-+-+-+-+-+-+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * Vincent Phuah * * GTE Laboratories Email: vphuah@gte.com * * 40 Sylvan Road Tel: (617) 466-4130 * * Waltham, MA 02254 FAX: (617) 890-9320 * +-+-+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+