sundar@WHEATIES.AI.MIT.EDU (Sundar Narasimhan) (02/20/89)
Ok, I give up! I am trying to use XGrabKey to determine when the Caps Lock key goes down (This started out as a simple program to display something when the caps lock key is down)... 1. I first tried something like (to see if I can figure out when the caps lock key goes down at all): XtAddEventHandler(tty, KeyPress, 0, key_press, 0); to get my client widget to notice KeyPress events. This failed to work, since it never gets to see the first time the CapsLock key going down (i.e. key_press is never entered the first time capslock goes down). However as soon as I did XtAddEventHandler(tty, KeyPress|KeyRelease, 0, key_press, 0); I started to see the first CapsLock keypress transition. Running xev I noticed that the my capslock (on a Sun 3/60) generates a KeyPress the first time I press it, and a KeyRelease the second time (which is entirely logical). Why does the toolkit not see the first keypress if I just have a eventhandler for KeyPress events? 2. Obviously, this will work only if I press the CapsLock key while within my client window. Since I wanted it to work anywhere from within my display. I thought I would do something like: XGrabKey(XtDisplay(tty), XKeysymToKeycode(XtDisplay(tty),XK_Caps_Lock), AnyModifier, DefaultRootWindow(XtDisplay(tty)), FALSE, GrabModeAsync, GrabModeAsync); [Minor nit: what is this routine supposed to return? The documentation (even the newly released C Library and Protocol Reference) mentions what error values can be returned but I seem to get some bizarre number like 1401158 when the grab succeeds!] I thought by doing this, when the caps lock key is pressed, an active grab would ensue, and a keypress event would be sent to the client. The active grab does seem to happen, but my client never gets to see the keypress event (this may be related to the same problem as in 1). (If it had, it would have altered a state bit, ungrabbed the key and re-issued a passive grab, to get to see when the next time the capslock key goes down -- Is this the right way to do this? Seems awful to have to go through all these convolutions!) I've re-read the documentation and it is VERY confusing, to say the least. (BTW does anyone have a simple program that uses GrabKey along with the toolkit? Do any of the distributed clients do anything like this?) -Sundar