Re: XForms: How to detect SHIFT <Mouse Button> ?

Steve Lamont (
Wed, 2 Jul 97 06:21:07 PDT

To subscribers of the xforms list from (Steve Lamont) :

> I'm using a post-emptive handler to add some interactive functionality
> to xyplot ( along the lines of DEMOS/xyplotall.c ). The 'key' value
> which gets returned to this handler accurately reflects which mouse
> button was pressed, but I'd like to be able to provide modified
> response by using eg keyboard SHIFT + LEFT MOUSE BUTTON.
> Neither 'key' (nor fl_mouse_button used in a callback) seem to give
> any indication as to the concurrent status of SHIFT, ALT etc key
> modifiers. Can this be accomplished, and if so how?

I'm not sure offhand what the `raw_event' parameter contains for a
button press but if it does indeed contain the ButtonPress event that
triggered the callback, you can get this information from the `state'
mask in the XButtonEvent structure. Assuming that this theory is
correct (and, as I say, I'm not absolutely certain that XForms really
does pass you the XButtonEvent structure), you can do something like

XEvent *generic_event = ( XEvent *) raw_event;

if ( ( key == 1 ) && ( generic_event->type == ButtonPress ) ) {

XButtonPressedEvent *button_press =
( XButtonPressedEvent *) generic_event;

if ( ShiftMask & button_press->state )


It's worth a try, anyhow.

If XForms hands you some bogus synthetic event (which it may), then
you'll have to do

FL_Coord x;
FL_Coord y;
unsigned int keymask;


fl_get_mouse( &x, &y, &keymask );

if ( keymask && ( ShiftMask | Button1Mask ) )

The only reason I don't recommend this method straight out of the box
is that fl_get_mouse() requires a round trip to the server since in
its innards it calls XQueryPointer(). On a network connection, of
course, this can add significant delay.

Refer to the manual, Chapter 24, "Drawing Objects," for details on
fl_get_mouse() and your favorite Xlib reference for information on
XQueryPointer() and/or the guts of the XButtonPressedEvent structure.

To unsubscribe, send the message "unsubscribe" to or see
Xforms Home Page:
List Archive: