Solved

XSendEvent

Posted on 1997-03-05
5
535 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
ID: 1292398
Adjusted points to 50
0
 

Author Comment

by:tulip
ID: 1292399
Adjusted points to 100
0
 
LVL 2

Accepted Solution

by:
lockhart earned 100 total points
ID: 1292400
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
ID: 1292401
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
ID: 1292402
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 108
has22 challenge 11 92
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 248
changeXy challenge 13 81
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 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