Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bind e.g. <Alt-5> ?

Status
Not open for further replies.

japskar

Programmer
Feb 13, 2002
27
0
0
Hi,
currently I'm working on a piece of code for binding keysequences to action.
So far, so good. But I can't get my
&quot;bind all <Alt-nr> {......}&quot; working for nr=1 to 5

&quot;bind all <Alt-6> {.....}&quot; however, works fine

what's the problem here?

-Jasper
 
I tried it and it works fine. Of course, the syntax is:
bind all <Alt-$nr> {...}
not
bind all <Alt-nr> {...} Bob Rashkin
rrashkin@csc.com
 
Yes sorry, I wasn't precise in my formulation of the problem.
But....strange.
Can you try this for me?:

pack [button .b1 -text {Button1} -command {puts {invoked button1}}]
pack [button .b2 -text {Button2} -command {puts {invoked button2}}]
bind all <Alt-5> {.b1 invoke}
bind all <Alt-6> {.b2 invoke}

it only triggers .b2
-Jasper
 
I'll bet you'd notice even stranger behavior if you tried binding to [tt]<Alt-1>[/tt], [tt]<Alt-2>[/tt], or [tt]<Alt-3>[/tt]. At the very least, I think you'd be surprised to see the bindings fire when the user held down the Alt key while clicking one of the mouse buttons...

What you're experiencing is one of those traps that people encounter when they use abbreviated binding descriptions. For many KeyPress events, you can get by with providing only the keysym. So, [tt]<a>[/tt] is equivalent to [tt]<KeyPress-a>[/tt], and [tt]<Control-a>[/tt] is equivalent to [tt]<Control-KeyPress-a>[/tt].

On the other hand, Tcl also allows you to abbreviate ButtonPress events, so [tt]<1>[/tt] is equivalent to [tt]<ButtonPress-1>[/tt]. And [tt]<Alt-1>[/tt] through [tt]<Alt-5>[/tt] is equivalent to [tt]<Alt-ButtonPress-1>[/tt] through [tt]<Alt-ButtonPress-5>[/tt].

Solution? Bind to [tt]<Alt-KeyPress-5>[/tt]. And be very careful relying on abbreviated event descriptions in bindings. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
I NEVER would have thought of that Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top