Subject: ?? Re: Tk : Translating Keysyms to eqiv Tk modifier strings. - DN [1]
jay <jjddss@my-deja.com> - 11 Jan 2000 - comp.lang.tcl
In article <3879E574.EDD0C1BD@cassini.f9.co.uk>,
jchoksi@bigfoot.com wrote:
> bind $entrywidget <KeyPress> {{puts stdout {{Keysym = %K Char =
> %A}}
>
> So...the %K tells me what keysyms were involved but how do I translate
> those keysyms into appropriate modifiers ?
You need to look at the state, the %s value. Here's a simple example:
proc keyBinding { entry sym state } {
global keybinding
# These come from /usr/include/X11/X.h but
# seem to be valid on windows systems as well.
set ShiftMask [expr 1<<0]
set LockMask [expr 1<<1]
set ControlMask [expr 1<<2]
set Mod1Mask [expr 1<<3]
set Mod2Mask [expr 1<<4]
set Mod3Mask [expr 1<<5]
set Mod4Mask [expr 1<<6]
set Mod5Mask [expr 1<<7]
set keybinding {}
if {[expr $state & $ControlMask]} { append keybinding {Control-} }
if {[expr $state & $LockMask]} { append keybinding {Lock-} }
if {[expr $state & $Mod1Mask]} { append keybinding {Mod1-} }
if {[expr $state & $Mod2Mask]} { append keybinding {Mod2-} }
if {[expr $state & $Mod3Mask]} { append keybinding {Mod3-} }
if {[expr $state & $Mod4Mask]} { append keybinding {Mod4-} }
if {[expr $state & $Mod5Mask]} { append keybinding {Mod5-} }
if {[expr $state & $ShiftMask]} { append keybinding {Shift-} }
append keybinding $sym
$entry delete 0 end
$entry insert 0 $keybinding
}
entry .e -width 40
pack .e
bind .e <Key> { keyBinding %W %K %s }
One problem with this example is that you'll get the key sym of the
modifier key displayed as well. If you were willing to restrict to only
alpha-numeric keys, you could weed those mostly out by using the %A
value. But if you want to allow something like Control-Delete, you have
to use keysyms. And of course, there are other problem keys as well,
such as Enter -- do you use the %A value (\r) or the keysym name?
Which is why this is just a simple example. HTH!
: jay
--
Using self-discipline, see http://www.eiffel.com/discipline
Sent via Deja.com http://www.deja.com/
Before you buy.
Last modified
2000-01-21
2000-01-21
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
