From: Óscar Fuentes on 10 Feb 2010 15:57 After hours of experimentation and browsing code on the Internet I still haven't found how to bind a key (let's say F4) without reacting to keypresses that includes modifiers (Control-F4) or destroying existing bindings (Alt-F4). http://wiki.tcl.tk/1401 suggests proc bind'plainkey {tag key script} { bind $tag <Control-$key> { } bind $tag <Alt-$key> { } bind $tag $key $script } this doesn't work because destroys existing bindings for <Control-$key> and <Alt-$key>. This could be fixed if there existed a way to check that <Alt-$key> is not bound to something through for `tag', either directly or indirectly.
From: Alexandre Ferrieux on 10 Feb 2010 16:20 On Feb 10, 9:57 pm, Óscar Fuentes <o...(a)wanadoo.es> wrote: > After hours of experimentation and browsing code on the Internet I still > haven't found how to bind a key (let's say F4) without reacting to > keypresses that includes modifiers (Control-F4) or destroying existing > bindings (Alt-F4). > > http://wiki.tcl.tk/1401 > > suggests > > proc bind'plainkey {tag key script} { > bind $tag <Control-$key> { } > bind $tag <Alt-$key> { } > bind $tag $key $script > } > > this doesn't work because destroys existing bindings for <Control-$key> > and <Alt-$key>. This could be fixed if there existed a way to check that > <Alt-$key> is not bound to something through for `tag', either directly > or indirectly. The tricky part is that bindings don't compete the same way, depending on whether they are one the same tag or not. Within a given tag, the most specific binding will preclude more general ones, so Control-F4 will take over F4. But if they are on different tags, no such competition arises, and your only control is that of tag order and [break]. Note that if the order is not what you want (i.e your binding on F4 is on a tag that is *before* the one on Control-F4), your last chance is to use percent fields and make tests. For example, the '%s' field (state) seems to contain some information about mod keys: it is 0 for no mods, 4 for control (on my keyboard/ OS). So you can grab that weed :} -Alex
From: Óscar Fuentes on 11 Feb 2010 09:55 Alexandre Ferrieux <alexandre.ferrieux(a)gmail.com> writes: > On Feb 10, 9:57 pm, Óscar Fuentes <o...(a)wanadoo.es> wrote: >> After hours of experimentation and browsing code on the Internet I still >> haven't found how to bind a key (let's say F4) without reacting to >> keypresses that includes modifiers (Control-F4) or destroying existing >> bindings (Alt-F4). > > The tricky part is that bindings don't compete the same way, [helpful explanation snipped] It is sad that the programmer has to resort to tricks and hacks for such simple thing as binding a key. Most of the time working with Tcl/Tk is a pleasure, but at places the design decisions made seem inspired by the worst X tradition. Anyways, I know no way of binding F4 without destroying the ability of closing windows with Alt-F4 on MS Windows, unless the binding for F4 inspects the modifiers and does the job of Alt-F4. Hideous.
From: Alexandre Ferrieux on 11 Feb 2010 10:04 On Feb 11, 3:55 pm, Óscar Fuentes <o...(a)wanadoo.es> wrote: > Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> writes: > > On Feb 10, 9:57 pm, Óscar Fuentes <o...(a)wanadoo.es> wrote: > >> After hours of experimentation and browsing code on the Internet I still > >> haven't found how to bind a key (let's say F4) without reacting to > >> keypresses that includes modifiers (Control-F4) or destroying existing > >> bindings (Alt-F4). > > > The tricky part is that bindings don't compete the same way, > > [helpful explanation snipped] > > It is sad that the programmer has to resort to tricks and hacks for such > simple thing as binding a key. Most of the time working with Tcl/Tk is a > pleasure, but at places the design decisions made seem inspired by the > worst X tradition. > > Anyways, I know no way of binding F4 without destroying the ability of > closing windows with Alt-F4 on MS Windows, unless the binding for F4 > inspects the modifiers and does the job of Alt-F4. Hideous. Warning, you missed my point: if you bind <Key-F4> on a tag that's different from the system one doing Alt-F4, they don't compete. In the handler, all you have to do then is: inspect_modifiers if {no_modifiers} {do my stuff;break} You can see that you don't have to reimplement the behavior of Alt-F4. -Alex
From: Óscar Fuentes on 11 Feb 2010 10:32
Alexandre Ferrieux <alexandre.ferrieux(a)gmail.com> writes: >> Anyways, I know no way of binding F4 without destroying the ability of >> closing windows with Alt-F4 on MS Windows, unless the binding for F4 >> inspects the modifiers and does the job of Alt-F4. Hideous. > > Warning, you missed my point: if you bind <Key-F4> on a tag that's > different from the system one doing Alt-F4, they don't compete. In the > handler, all you have to do then is: > > inspect_modifiers > if {no_modifiers} {do my stuff;break} > > You can see that you don't have to reimplement the behavior of Alt-F4. Some observations here, to explain why I seemed to miss your point: I tried bind all <Key-F4> continue which blocks Alt-F4 on wish. But after your insistence, discovered that bind . <Key-F4> continue doesn't block Alt-F4. However, on a pristine wish instance: (Oscar) 1 % bindtags . .. Wish all (Oscar) 2 % bind . (Oscar) 3 % bind Wish (Oscar) 4 % bind all <<PrevWindow>> <Key-Tab> <KeyRelease-F10> <Key-F10> <Alt-KeyRelease> <Alt-Key> <KeyRelease-Alt_R> <Key-Alt_R> <KeyRelease-Alt_L> <Key-Alt_L> No binding for Alt-F4. So I can't explain why binding to `all' blocks Alt-F4. Furthermore, can't explain why Alt-F4 works at all on a new wish instance. Maybe some handling at the C level. But now I think that the problem of binding a bare keypress becomes much simpler, although not as simple as it should. Thanks Alex. |