Solved

XSendEvent

Posted on 1997-03-05
5
527 Views
Last Modified: 2013-12-26
I am using XGrabPointer to grab all Button events.  I then
use XNextEvent to read the event in the queue that is waiting to be read.  (No problems to this point.)

I then attempt to repost the same event using XSendEvent.
I recieve absolutely no sign that the Send works.  It
does not return an error.  I have tried to tweek many of
the variables in the event with no change and even the
arguments to XSendEvent.  I tried changing the window I
was sending to, but that did not work either.

Here is what I used (and many other versions);
     XSendEvent(display, root, True, 0xFFFF, &report);

What am I forgetting to do?

0
Comment
Question by:tulip
  • 3
5 Comments
 

Author Comment

by:tulip
Comment Utility
Adjusted points to 50
0
 

Author Comment

by:tulip
Comment Utility
Adjusted points to 100
0
 
LVL 2

Accepted Solution

by:
lockhart earned 100 total points
Comment Utility
Why don't you use XPeekEvent()?  Then if you want to remove the event and not put it back you can do it, but if you want to leave it on the queue XPeekEvent() does that.  Unless you want the event to go to the back of the queue (as would happen in your current scenario).  In any case, you should use the Display and Window members of the event structure as your 1st and 2nd args to make sure the event gets sent to the same display and window it was going to when you plucked it via XNextEvent().  So,  XSendEvent (report.display, report.window, True, 0xFFFFFFFFL, &report) would seem appropriate (and don't forget that the event mask is a LONG).

Another alternative would be XPutBackEvent().  To tell you the truth, I've never tried to do what you are trying to do and can't tell you why it is failing.  I've always used XPeekEvent() to look at an event and decide if I want to do something or postpone actions.  

I suspect that the problem is that XNextEvent() takes a display and event as args and XSendEvent() additionally takes a window, propogate boolean and event mask.  The target for the event seems to be different.  If you let X figure out where the event needs to go by using XPutBackEvent() or don't even deal with having to put it back by using XPeekEvent() you shouldn't have this problem.

If you need to search for specific kinds of events in the queue for some reason, you can use XCheckWindowEvent() to look for specific events going to specific windows.

Hope this helps.

Mike
0
 

Expert Comment

by:erb
Comment Utility
FYI, there is a small program that uses XSendEvent to take
input from the serial port and make X think they are keystrokes.
The README tells some setup hints, like *AllowSendEvents: yes
in .xdefaults.  Source code included.

  http://www.tableau.com/kt21.README
  http://www.tableau.com/kt21.tar.gz

Dave

0
 

Author Comment

by:tulip
Comment Utility
Thanks for the help!
I believe that a full description of the problems I ran into might help others.  Here goes:

-Definately check out the programs mentioned by erb.  It was invaluable.

-The window that you send to and the windows mentioned in the XEvent structure that one sends must be correct.  All events propagate up towards the root window until that are grabbed by an interested window.  Thus you must send to the window you are interested in communicating with.

-AllowSendEvent  will cause some hassles.  I have it working for most application now.  I am still working on the window manager so that it will accept my events properly.  Make sure to check resources if all else fails.

-Make sure to use XFlush() so that your XSendEvent will be
executed.

-Check the state value of the XEvent structure for correctness.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 76
Named range not carried over 10 57
Fibonacci challenge 11 82
mapBully challenge 6 88
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video discusses moving either the default database or any database to a new volume.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now