keyboard events for motif

Hi everybody,

I'm trying to get my motif program to process keyboard events e.g. the user hits the 'f' key on the keyboard and the program calls a function. Now I know how to process events like buttons and pulldown menus in Motif, and I know how to get xlib to do what I want but I'm not sure how to combine the two things into one program.

So basically I want to be able to execute a particular function using the pulldown menus (this part I have working) but I also want to be able to execute the same function via a single keypress. I'm sure there must be some way to do this.

Thanks in advance,
Mark


cubexyz

cubexyz's picture

Ok, I have managed to add

Ok, I have managed to add xlib keyboard functions to the motif program.
But now I have another interesting issue.

When I use the pulldown menus but I don't select any entries sometimes the motif program will stop processing keyboard commands from the drawing area. It still is processing keyboard commands but only for the keys used by the menubar (e.g. the arrow keys).

When one hits the escape key to get out of the menubar I'm thinking it should return focus to the drawing area below, but it actually only does that when a entry is selected from a pulldown menu. Guess I need to read up on focus-type functions.

Mark


fredk

fredk's picture

How are you creating the

How are you creating the menubar and menu items?

The easiest way to add your desired functionality is to use accelerator keys for each of the menu items.
For example, for an Exit button, you might want Ctrl+Q to be the accelerator.
So you set these resources on the exit button:
XtVaSetValues( exitButton,
XmNaccelerator, "CtrlQ",
XmNacceleratorText, "Ctrl+Q",
NULL );

You can set just a key, without any modifiers, but I would discourage that.
For example, if you have the key "I" as an accelerator, you would not be able to type an "I" into any text field - the key press would be interpreted as an accelerator instead of a field input.
--
Fred K