Re: Keys handler

Stefano Mancini (mancini@galileo.pi.infn.it)
Tue, 26 Nov 1996 19:21:28 +0100

To subscribers of the xforms list from Stefano Mancini <mancini@galileo.pi.infn.it> :

Steve Lamont wrote:
>
> > This means that using the "keycode" member of XKeyEvent and this Xform
> > function I can register only that keys on the keyboard that generates a
> > KeyPress (or KeyRelease) events ?
>
> I'm not sure I understand your question.
>
> According to the X documentation, an KeyPressedEvent or
> KeyReleasedEvent is "[g]enerated for all keys, even those mapped to
> modifier keys such as Shift or Control." (O'Reilly & Associates, Inc.,
> _The X Window System in a Nutshell_, ISBN 1-56592-017-1)
>
> This means you're going to get all keystrokes (Press or Release,
> depending upon which you've registered). You can then use whatever
> mechanism you wish to select particular keycodes using the keycode
> member of the XKeyEvent structure. I don't know offhand whether
> there's a way to filter the keystrokes at a lower level.
>
> You'd register your interest in and handle the KeyPress event as follows
>
> FL_OBJECT *canvas;
>
> [...]
>
> fl_addto_selected_xevent( FL_ObjWin( canvas ), KeyPressMask );
> fl_add_canvas_handler( canvas, KeyPress, key_press_handler, data );
>
> [...]
>
> int key_press_handler( FL_OBJECT *obj, Window window,
> int win_width, int win_height,
> XEvent *xevent, void *data )
>
> {
>
> XKeyPressEvent *key_press_event = ( XKeyPressEvent *) xevent;
>
> if ( key_press_event->keycode == XK_your_favorite_keycode ) {
>
> [...]
>
> I hope this is responsive to your question. If not, perhaps you can
> explain in more detail what you're trying to do.
>
> spl

I am trying to do program that can be driven by keyboards as well as by
mouse, using line commands. For example suppose that you want to draw a
line on a canvas object. With the mouse you pick your first point and
then moving it draw that line.
Well, my goal is to do the same thing using a "command line" input
as:
Line(0,0)-(x,y)

The initial problem that i found is that every key i press a KeyPress
event is sent to the callback, loosing previous data!
Thinking and Reading ......
I has found another way to take into account KeyPress Events.
I make this as follows:

--------- cut here ----

[...]

FL_OBJECT *canvas;
fl_add_canvas_handler( canvas, KeyPress, key_press_handler, data );

[...]
int des_canvas_key(FL_OBJECT *obj,Window win, int w, int h,
XEvent *xev, void *d)
[...]
KeySym keysym;
XComposeStatus compose;
int bufsize = MAX_COMMAND_LENGHT;
char buffer[MAX_COMMAND_LENGHT+1];
int count;
count = XLookupString(xev, buffer,bufsize,&keysym,&compose);
buffer[count] = '\n';

/* handle the string in buffer */

--------- cut here --------

As you see I don't use :
fl_addto_selected_xevent( FL_ObjWin( canvas ), KeyPressMask );

and I use the X command XLookupString to fill "buffer" of array of
characters. From XLookupString the program exit when is found a carriage
return or buffer is full.

Regards
SM
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html