From bloom-picayune.mit.edu!snorkelwacker.mit.edu!stanford.edu!agate!sprite.Berkeley.EDU!ouster Wed Apr 15 20:28:47 EDT 1992 Article: 521 of comp.lang.tcl Path: bloom-picayune.mit.edu!snorkelwacker.mit.edu!stanford.edu!agate!sprite.Berkeley.EDU!ouster From: ouster@sprite.Berkeley.EDU (John Ousterhout) Newsgroups: comp.lang.tcl Subject: Re: binding number keys in Tk Date: 15 Apr 1992 22:24:53 GMT Organization: U.C. Berkeley Sprite Project Lines: 46 Distribution: world Message-ID: References: <1992Apr13.234146.12982@stortek.com> NNTP-Posting-Host: tyranny.berkeley.edu In article <1992Apr13.234146.12982@stortek.com>, v040376@autspc1.stortek.com (Jeff Hanson) writes: |> I am trying to bind the number keys on the keyboard in an entry widget |> using tk1.4. But when I specify the keysym for the 1, 2, or 3 keys I get |> an error from bind. The error is : |> |> specified button "1" for non-button event |> |> It appears that tk is assuming "1" is shorthand for button-1 as is stated |> in the bind man page. I verified the keysym for the number keys using |> xmodmap -pk and I am able to bind other keys such as the keypad number keys |> (using KP_1 for a keysym). Here is the command I am using for the binding: |> |> bind myentry {%W insert cursor "%A"} |> |> My questions are then am I doing something wrong, or is there a bug in the |> tk code with respect to this feature. Oops. It's a bug. I've found and fixed it in my sources, and here's a context diff that you should be able to apply to fix it too. Sorry for the error, and thanks for reporting the problem. *** /tmp/,RCSt1215855 Wed Apr 15 15:22:45 1992 --- tkBind.c Wed Apr 15 15:20:01 1992 *************** *** 1242,1247 **** --- 1242,1250 ---- if (patPtr->eventType == -1) { patPtr->eventType = ButtonPress; eventMask |= ButtonPressMask; + } else if ((patPtr->eventType == KeyPress) + || (patPtr->eventType == KeyRelease)) { + goto getKeysym; } else if ((patPtr->eventType != ButtonPress) && (patPtr->eventType != ButtonRelease)) { Tcl_AppendResult(interp, "specified button \"", field, *************** *** 1258,1263 **** --- 1261,1267 ---- patPtr->needMods &= masks[patPtr->detail]; patPtr->hateMods &= masks[patPtr->detail]; } else { + getKeysym: hPtr = Tcl_FindHashEntry(&keySymTable, (char *) field); if (hPtr == NULL) { Tcl_AppendResult(interp, "bad event type or keysym \"",