# a port of Plan 9's character input mechanism (keyboard(7)) to Tcl/Tk # latin1.tcl has been converted by a script # from plan9ports src/cmd/devdraw/latin1.h # # © 2010 by Michael Teichgräber # Put under the same license as Plan 9 # # call # devdrawkbd::Bind tag # to make it available to widgets, with # tag being e.g. Text, Entry, or a widget path namespace eval devdrawkbd { variable alting 0 variable keys {} variable keypressed 0 variable latin1tab # source latin1.tcl proc Bind {tag} { set cb [namespace code { if {"%K" == "Alt_L"} { incr alting set keys {} set keypressed {} } }] bind $tag "$cb; [bind $tag ]" bind $tag "if { \[devdrawkbd::keypress %W %A press \] == -1} { [bind $tag ] }" bind $tag "if { \[devdrawkbd::keypress %W %A release \] == -1} { [bind $tag ] }" } proc keypress {path key action} { variable alting variable keys variable keypressed if {! $alting} { return -1 } if {$key == {}} { return -1 } if {$action == "release"} { # # On Windows, if Alt has been pressed (and probably released), # the next key press won't cause an event, but releasing # the key will. Therefore we will check whether this is a release # event which has no corresponding key press event, in which # case it is treated as if it was a key press. if {$key == $keypressed} { set keypressed {} return -1 } set keypressed {} } else { set keypressed $key } switch $key { "\"" { set key "\\\"" } \{ { set key {\\\{} } } set keys [concat $keys $key] set c [latin1 "$keys"] if { $c == -1 } { set alting 0 return -1 } elseif { $c >= 0 } { $path insert insert $c set alting 0 } return 0 } proc unicode {keys} { set c {} foreach k [lreplace $keys 0 0] { if { "0"<=$k && $k<="9" || "a"<=$k && $k<="f" || "A"<=$k && $k<="F"} { set c "$c$k" } else { return -1 } } puts $c puts \u$c eval set c "\\u$c" } proc ld1search {what} { variable latin1tab lsearch -exact $latin1tab(ld) $what } proc ld1index {i args} { variable latin1tab lindex $latin1tab($i) $args } proc latin1 {k} { set k0 [lindex $k 0] set n [llength $k] if { $k0 == "X" } { if {$n == 5} { return [unicode $k] } else { return -5 } } switch $n { 1 { if {[ld1search $k0] == -1 } { return -1 } return -2 } 2 { set k1 [lindex $k 1] if { [ld1search $k0$k1] == -1 } { set i [ld1search $k0] } else { return -3 } set j [string first $k1 [ld1index si $i]] if { $j == -1 } { return -1 } return [ld1index so $i $j] } 3 { set i [ld1search $k0[lindex $k 1]] set j [string first [lindex $k 2] [ld1index si $i]] if { $j == -1 } { return -1 } return [ld1index so $i $j] } } } set latin1tab(ld) { " " "!~" "!" "\"*" "\"" "$*" "$" "%" "\'\"" "\'" "*" "+" "," "-*" "-" "." "/" "1" "2" "3" "4" "5" "7" ":" "!" ">" "?" "@\'" "@@" "@C" "@E" "@K" "@S" "@T" "@Y" "@Z" "@c" "@e" "@k" "@s" "@t" "@y" "@z" "@" "A" "C" "Dv" "D" "G" "H" "I" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "V" "Y" "Z" "^" "_\"" "_," "_." "_" "`\"" "`" "a" "b" "c" "dv" "d" "e" "f" "g" "h" "i" "l" "m" "n" "o" "p" "r" "s" "t" "u" "v\"" "v" "w" "x" "y" "z" "|" "~!" "~" } set latin1tab(si) { " i" "-=~" "!<=>?bmp" "IUiu" "\"AEIOUYaeiouy" "fhk" "BEFHILMRVaefglopv" "0" "Uu" "\'ACEILNORSUYZacegilnorsuyz" "*ABCDEFGHIKLMNOPQRSTUWXYZabcdefghiklmnopqrstuwxyz" "-O" ",ACEGIKLNORSTUacegiklnorstu" "l" "+-2:>DGHILOTZbdghiltuz~" ".CEGILOZceglz" "Oo" ".234568" "-.35" ".458" "5" "68" "8" "()-=" "=~" "-<=>~" ":<=>OV" "=~" "<=>~" "!?" "\'" "\'EKSTYZekstyz" "Hh" "Hh" "Hh" "CHch" "Ss" "AEOUaeou" "Hh" "h" "h" "h" "ch" "s" "aeou" "h" "ABDFGIJLMNOPRUVXabdfgijlmnopruvx" "E" "ACU" "Zz" "-e" "-" "-H" "-J" "&-Jj|" "#48bs" "JNj" "*+-./=EIcoprx" "P" "Q" "R" "123S" "-u" "=" "R" "-ACSZ" "ACEGHIJOSUWYaceghijosuwy" "AUau" "Oo" "Aa" "AEIOU_aeiou" "Uu" "AEIOUaeiou" "ben" "\"\'()+-0123456789=bknpqru" "$Oagu" "z" "-adegz" "$lmns" "a" "$-r" "-v" "-bfjps" "\"$&\'-jz|" "iou" "jo" "AOUaeiu" "Odgrt" "\"\'O" "()+-0123456789=abinoprstu" "-efmsu" "-AEGIOUaegiou" "Uu" "ACDEGIKLNORSTUZacdegijklnorstuz" "bknpqr" "O" "$" "-" "Pp|" "=" "-=AINOUainou~" } set latin1tab(so) { { \u2423 \u0131 } { \u2244 \u2247 \u2249 } { \u00a1 \u226e \u2260 \u226f \u203d \u2284 \u2209 \u2285 } { \u03aa \u03ab \u03ca \u03cb } { \u00a8 \u00c4 \u00cb \u00cf \u00d6 \u00dc \u0178 \u00e4 \u00eb \u00ef \u00f6 \u00fc \u00ff } { \u03d5 \u03d1 \u03f0 } { \u212c \u2130 \u2131 \u210b \u2110 \u2112 \u2133 \u211b \u01b2 \u0251 \u212f \u0192 \u210a \u2113 \u2134 \u2118 \u028b } { \u2030 } { \u01d7 \u01d8 } { \u00b4 \u00c1 \u0106 \u00c9 \u00cd \u0139 \u0143 \u00d3 \u0154 \u015a \u00da \u00dd \u0179 \u00e1 \u0107 \u00e9 \u0123 \u00ed \u013a \u0144 \u00f3 \u0155 \u015b \u00fa \u00fd \u017a } { \u2217 \u0391 \u0392 \u039e \u0394 \u0395 \u03a6 \u0393 \u0398 \u0399 \u039a \u039b \u039c \u039d \u039f \u03a0 \u03a8 \u03a1 \u03a3 \u03a4 \u03a5 \u03a9 \u03a7 \u0397 \u0396 \u03b1 \u03b2 \u03be \u03b4 \u03b5 \u03c6 \u03b3 \u03b8 \u03b9 \u03ba \u03bb \u03bc \u03bd \u03bf \u03c0 \u03c8 \u03c1 \u03c3 \u03c4 \u03c5 \u03c9 \u03c7 \u03b7 \u03b6 } { \u00b1 \u2295 } { \u00b8 \u0104 \u00c7 \u0118 \u0122 \u012e \u0136 \u013b \u0145 \u01ea \u0156 \u015e \u0162 \u0172 \u0105 \u00e7 \u0119 \u0123 \u012f \u0137 \u013c \u0146 \u01eb \u0157 \u015f \u0163 \u0173 } { \u019b } { \u2213 \u00ad \u01bb \u00f7 \u2192 \u00d0 \u01e4 \u0126 \u0197 \u0141 \u2296 \u0166 \u01b5 \u0180 \u00f0 \u01e5 \u210f \u0268 \u0142 \u0167 \u0289 \u01b6 \u2242 } { \u00b7 \u010a \u0116 \u0120 \u0130 \u013f \u2299 \u017b \u010b \u0117 \u0121 \u0140 \u017c } { \u00d8 \u00f8 } { \u2024 \u00bd \u2153 \u00bc \u2155 \u2159 \u215b } { \u01bb \u2025 \u2154 \u2156 } { \u2026 \u00be \u2157 \u215c } { \u2158 } { \u215a \u215d } { \u215e } { \u2639 \u263a \u00f7 \u2254 } { \u2268 \u22e6 } { \u2190 \u00ab \u2264 \u2276 \u2272 } { \u2255 \u22dc \u2261 \u22dd \u229c \u21d2 } { \u2269 \u22e7 } { \u2277 \u2265 \u00bb \u2273 } { \u203d \u00bf } { \u044a } { \u044c \u0415 \u041a \u0421 \u0422 \u042b \u0417 \u0435 \u043a \u0441 \u0442 \u044b \u0437 } { \u0427 \u0427 } { \u042d \u042d } { \u0425 \u0425 } { \u0429 \u0428 \u0429 \u0428 } { \u0426 \u0426 } { \u042f \u0415 \u0401 \u042e \u042f \u0415 \u0401 \u042e } { \u0416 \u0416 } { \u0447 } { \u044d } { \u0445 } { \u0449 \u0448 } { \u0446 } { \u044f \u0435 \u0451 \u044e } { \u0436 } { \u0410 \u0411 \u0414 \u0424 \u0413 \u0418 \u0419 \u041b \u041c \u041d \u041e \u041f \u0420 \u0423 \u0412 \u0425 \u0430 \u0431 \u0434 \u0444 \u0433 \u0438 \u0439 \u043b \u043c \u043d \u043e \u043f \u0440 \u0443 \u0432 \u0445 } { \u00c6 } { \u22c2 \u2102 \u22c3 } { \u01c4 \u01c5 } { \u00d0 \u2206 } { \u01e4 } { \u0126 \u210d } { \u0197 \u0132 } { \u22c0 \u0141 \u01c7 \u01c8 \u22c1 } { \u266e \u2669 \u266a \u266d \u266f } { \u01ca \u2115 \u01cb } { \u229b \u2295 \u2296 \u2299 \u2298 \u229c \u0152 \u01a2 \u00a9 \u229a \u2117 \u00ae \u2297 } { \u2119 } { \u211a } { \u211d } { \u00b9 \u00b2 \u00b3 \u00a7 } { \u0166 \u22a8 } { \u21d0 } { \u01a6 } { \u01b5 \uf015 \uf017 \uf016 \u2124 } { \u00c2 \u0108 \u00ca \u011c \u0124 \u00ce \u0134 \u00d4 \u015c \u00db \u0174 \u0176 \u00e2 \u0109 \u00ea \u011d \u0125 \u00ee \u0135 \u00f4 \u015d \u00fb \u0175 \u0177 } { \u01de \u01d5 \u01df \u01d6 } { \u01ec \u01ed } { \u01e0 \u01e1 } { \u0100 \u0112 \u012a \u014c \u016a \u00af \u0101 \u0113 \u012b \u014d \u016b } { \u01db \u01dc } { \u00c0 \u00c8 \u00cc \u00d2 \u00d9 \u00e0 \u00e8 \u00ec \u00f2 \u00f9 } { \u2194 \u00e6 \u2220 } { \u201e \u201a \u208d \u208e \u208a \u208b \u2080 \u2081 \u2082 \u2083 \u2084 \u2085 \u2086 \u2087 \u2088 \u2089 \u208c \u265d \u265a \u265e \u265f \u265b \u265c \u2022 } { \u00a2 \u00a9 \u2229 \u2245 \u222a } { \u01c6 } { \u00f0 \u2193 \u2021 \u00b0 \u2020 \u02a3 } { \u20ac \u22ef \u2014 \u2013 \u2205 } { \u2200 } { \u00a4 \u01e5 \u2207 } { \u210f \u0195 } { \u0268 \u2286 \u221e \u0133 \u2287 \u222b } { \u201c \u00a3 \u2227 \u2018 \u0142 \u01c9 \u22c4 \u2228 } { \u00b5 \u2208 \u00d7 } { \u01cc \u00ac } { \u00c5 \u229a \u016e \u00e5 \u0153 \u01a3 \u016f } { \u2117 \u2202 \u00b6 \u220f \u221d } { \u201d \u2019 \u00ae } { \u207d \u207e \u207a \u207b \u2070 \u00b9 \u00b2 \u00b3 \u2074 \u2075 \u2076 \u2077 \u2078 \u2079 \u207c \u00aa \u2282 \u2071 \u207f \u00ba \u2283 \u221a \u00df \u220d \u2211 } { \u0167 \u2203 \u2234 \u2122 \u03c2 \u22a2 } { \u0289 \u0102 \u0114 \u011e \u012c \u014e \u016c \u2191 \u0115 \u011f \u012d \u014f \u016d } { \u01d9 \u01da } { \u01cd \u010c \u010e \u011a \u01e6 \u01cf \u01e8 \u013d \u0147 \u01d1 \u0158 \u0160 \u0164 \u01d3 \u017d \u01ce \u010d \u010f \u011b \u01e7 \u01d0 \u01f0 \u01e9 \u013e \u0148 \u01d2 \u0159 \u0161 \u0165 \u01d4 \u017e } { \u2657 \u2654 \u2658 \u2659 \u2655 \u2656 } { \u2297 } { \u00a5 } { \u01b6 } { \u00de \u00fe \u00a6 } { \u2246 } { \u2243 \u2245 \u00c3 \u0128 \u00d1 \u00d5 \u0168 \u00e3 \u0129 \u00f1 \u00f5 \u0169 \u2248 } } }