jerryl@is.Morgan.COM (Jerry Liebelson) (05/15/91)
Hi -- Below is a simple program that creates an ApplicationShell containing a BulletinBoard widget which contains a single PushButton widget. I install accelerators for a lot of the keys on a Sun-4 keyboard that will trigger the button's callback routine. PROBLEM: I can't get the following keys to trigger the callback: F1, F4, F10, Arrow Keys, Insert, Delete, BackSpace I know the arrow keys are involved with the tab grouping, so I call XmRemoveTabGroup, but to no avail. And I realize that F10 is a default accelerator for the MenuBar widget. Basically, I want to have the complete freedom to bind any key on a Sun-4 keyboard to what I want. How can I get these keys to trigger the callback? Thanks. -- |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| | Jerry Liebelson | EMAIL: jerryl@is.morgan.com | | Information Systems | uunet!is.morgan.com!jerryl | | Morgan Stanley, Inc. | VOICE: (212) 703-2409 | | 1633 Broadway 36th Floor | FAX: (212) 703-2371 | | New York, NY 10019 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ------------------------------- cut here ------------------------------------- #include <stdio.h> #include <Intrinsic.h> #include <StringDefs.h> #include <keysym.h> #include <Xm/BulletinB.h> #include <Xm/PushB.h> void ButtonCallback(); Widget AppShell; static String Accelerators= { "#override \n\ Shift<KeyPress>R15: ArmAndActivate() \n\ Shift<KeyPress>R9: ArmAndActivate() \n\ Shift<KeyPress>R7: ArmAndActivate() \n\ Shift<KeyPress>R13: ArmAndActivate() \n\ Shift<KeyPress>Tab: ArmAndActivate() \n\ Shift<KeyPress>F21: ArmAndActivate() \n\ Shift<KeyPress>F22: ArmAndActivate() \n\ Shift<KeyPress>F23: ArmAndActivate() \n\ Shift<KeyPress>F24: ArmAndActivate() \n\ Shift<KeyPress>F25: ArmAndActivate() \n\ Shift<KeyPress>F26: ArmAndActivate() \n\ Shift<KeyPress>F28: ArmAndActivate() \n\ Shift<KeyPress>F30: ArmAndActivate() \n\ Shift<KeyPress>F31: ArmAndActivate() \n\ Shift<KeyPress>F32: ArmAndActivate() \n\ Shift<KeyPress>F34: ArmAndActivate() \n\ Shift<KeyPress>Left: ArmAndActivate() \n\ Shift<KeyPress>Down: ArmAndActivate() \n\ Shift<KeyPress>Right: ArmAndActivate() \n\ Shift<KeyPress>Up: ArmAndActivate() \n\ Shift<KeyPress>Help: ArmAndActivate() \n\ Shift<KeyPress>KP_Add: ArmAndActivate() \n\ Shift<KeyPress>KP_Subtract: ArmAndActivate() \n\ Shift<KeyPress>KP_Enter: ArmAndActivate() \n\ Shift<KeyPress>Return: ArmAndActivate() \n\ Shift<KeyPress>Insert: ArmAndActivate() \n\ Shift<KeyPress>BackSpace: ArmAndActivate() \n\ Shift<KeyPress>Delete: ArmAndActivate() \n\ Shift<KeyPress>Num_Lock: ArmAndActivate() \n\ <KeyPress>R15: ArmAndActivate() \n\ <KeyPress>R9: ArmAndActivate() \n\ <KeyPress>R7: ArmAndActivate() \n\ <KeyPress>R13: ArmAndActivate() \n\ <KeyPress>Tab: ArmAndActivate() \n\ <KeyPress>F1: ArmAndActivate() \n\ <KeyPress>F2: ArmAndActivate() \n\ <KeyPress>F3: ArmAndActivate() \n\ <KeyPress>F4: ArmAndActivate() \n\ <KeyPress>F5: ArmAndActivate() \n\ <KeyPress>F6: ArmAndActivate() \n\ <KeyPress>F7: ArmAndActivate() \n\ <KeyPress>F8: ArmAndActivate() \n\ <KeyPress>F9: ArmAndActivate() \n\ <KeyPress>F10: ArmAndActivate() \n\ <KeyPress>F11: ArmAndActivate() \n\ <KeyPress>F12: ArmAndActivate() \n\ <KeyPress>F13: ArmAndActivate() \n\ <KeyPress>F14: ArmAndActivate() \n\ <KeyPress>F15: ArmAndActivate() \n\ <KeyPress>F16: ArmAndActivate() \n\ <KeyPress>F17: ArmAndActivate() \n\ <KeyPress>F18: ArmAndActivate() \n\ <KeyPress>F19: ArmAndActivate() \n\ <KeyPress>F20: ArmAndActivate() \n\ <KeyPress>F21: ArmAndActivate() \n\ <KeyPress>F22: ArmAndActivate() \n\ <KeyPress>F23: ArmAndActivate() \n\ <KeyPress>F24: ArmAndActivate() \n\ <KeyPress>F25: ArmAndActivate() \n\ <KeyPress>F26: ArmAndActivate() \n\ <KeyPress>F28: ArmAndActivate() \n\ <KeyPress>F30: ArmAndActivate() \n\ <KeyPress>F31: ArmAndActivate() \n\ <KeyPress>F32: ArmAndActivate() \n\ <KeyPress>F34: ArmAndActivate() \n\ <KeyPress>Left: ArmAndActivate() \n\ <KeyPress>Down: ArmAndActivate() \n\ <KeyPress>Right: ArmAndActivate() \n\ <KeyPress>Up: ArmAndActivate() \n\ <KeyPress>Help: ArmAndActivate() \n\ <KeyPress>KP_Add: ArmAndActivate() \n\ <KeyPress>KP_Subtract: ArmAndActivate() \n\ <KeyPress>KP_Enter: ArmAndActivate() \n\ <KeyPress>Return: ArmAndActivate() \n\ <KeyPress>Insert: ArmAndActivate() \n\ <KeyPress>BackSpace: ArmAndActivate() \n\ <KeyPress>Delete: ArmAndActivate() \n\ <KeyPress>Num_Lock: ArmAndActivate()" }; static Atom WmDeleteWindowAtom, WmProtocolsAtom; typedef struct { KeySym keySym; char *keyName; } KEY; static KEY Keys[] = { XK_F1, "F1", XK_F2, "F2", XK_F3, "F3", XK_F4, "F4", XK_F5, "F5", XK_F6, "F6", XK_F7, "F7", XK_F8, "F8", XK_F9, "F9", XK_F10, "F10", XK_F11, "F11", XK_F12, "F12", XK_F13, "L3", XK_F14, "L4", XK_F15, "L5", XK_F16, "L6", XK_F17, "L7", XK_F18, "L8", XK_F19, "L9", XK_F20, "L10", XK_F21, "Pause", XK_F22, "PrSc", XK_F23, "ScrollLock", XK_F24, "R4", XK_F25, "R5", XK_F26, "R6", XK_F31, "KP_5", XK_KP_Enter, "KP_Enter", XK_Return, "Return", XK_Help, "Help", XK_Insert, "Insert", XK_Delete, "Delete", XK_BackSpace, "BackSpace", XK_Right, "Right", XK_Left, "Left", XK_Up, "Up", XK_Down, "Down", XK_R7, "Home", XK_R13, "End", XK_R9, "PgUp", XK_R15, "PgDn", XK_Tab, "TAB", XK_KP_Add, "KP_Add", XK_KP_Subtract, "KP_Subtract", XK_Num_Lock, "NumLock" }; static int NumKeys = sizeof(Keys)/sizeof(Keys[0]); /***************************************************************************/ int main(argc, argv) int argc; char **argv; { Widget board, button; Arg argList[10]; int i; XtAppContext appContext; Display *displayPtr; char appClass[64]; strcpy(appClass,argv[0]); if (islower(appClass[0])) appClass[0] = toupper(appClass[0]); else if (islower(appClass[1])) appClass[1] = toupper(appClass[1]); AppShell = XtAppInitialize ( &appContext, appClass, NULL, 0, &argc, argv, NULL, NULL, 0 ); board = XtCreateManagedWidget("board", xmBulletinBoardWidgetClass, AppShell, NULL, 0); XmRemoveTabGroup(board); i=0; XtSetArg (argList[i], XmNaccelerators, XtParseAcceleratorTable(Accelerators)); i++; button = XtCreateManagedWidget("button", xmPushButtonWidgetClass, board, argList, i); XtAddCallback(button, XmNactivateCallback, ButtonCallback, NULL); XtRealizeWidget(AppShell); XtInstallAllAccelerators(button, board); XtAppMainLoop(appContext); exit(-1); } void ButtonCallback(widget, clientData, callData) Widget widget; caddr_t clientData; XmAnyCallbackStruct *callData; { char keyString[12]; KeySym keySym; register int i; XLookupString(&callData->event->xkey, keyString, sizeof(keyString), &keySym, NULL); if (callData->event->xkey.state & ShiftMask) fprintf(stderr, "Shift "); for (i = 0; i < NumKeys; i++) { if (keySym == Keys[i].keySym ) fprintf(stderr, Keys[i].keyName); } fprintf(stderr, " Pressed\n"); }