maltman@lennon.austek.oz (Marcus Altman) (02/01/90)
I have a command widget whose notify() routine I wish to envoke when a specific key is pressed and the pointer is anywhere in the application window. I presume this is done with accelerator tables but I haven't been able to get very far. Has anyone got any example code? Thanks, Marcus. Email: maltman@austek.oz
converse@EXPO.LCS.MIT.EDU (Donna Converse) (02/03/90)
> I have a command widget whose notify() routine I wish to envoke when a > specific key is pressed and the pointer is anywhere in the application window. > Has anyone got any example code? Suppose the instance name of the command widget is "commandName" and the specific key is "a". To set the accelerator resource for a command widget, write a resource specification. If you are writing this application, and intend to supply some default accelerator bindings, you could put the resource specification in the application-specific class resource file (app-defaults file): *commandName.accelerators: <Key>a: notify() If you aren't writing the application, you could put the resource specification in the file where the rest of your own X default resources are given: programName*commandName.accelerators: <Key>a: notify() The value of the accelerator resource specification is an accelerator table, which gives a mapping from events such as key presses to the widget's or the application's action routines. See Appendix B of the Xt documentation for Translation Table Syntax if you have questions about writing translations. (Accelerator tables are nearly identical to translation tables; see Xt section 10.4). Actions are documented by the widget or application presenting them. The application must direct the Intrinsics to install the accelerator table of the command widget onto other widget(s) in order for you to be able to use accelerators. Ideally, any application will do this, so that users can write private accelerator resources. If you are writing an application, you can use XtInstallAccelerators(destID, srcID), which installs the accelerator table of a source widget onto a destination widget. Or, use XtInstallAllAccelerators(destID, srcID) which installs the accelerator table of the source widget, and the acclerator table of any descendant of the source widget, onto the destination widget. It is common to give a widget near the top of the widget tree as the source widget, installing all the accelerators of the application onto some widget which makes up a large part of the `surface' of the application. converse@expo.lcs.mit.edu