| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html> |
| 3 |
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 |
<title>bind (GCL TK Manual)</title> |
| 7 |
|
| 8 |
<meta name="description" content="bind (GCL TK Manual)"> |
| 9 |
<meta name="keywords" content="bind (GCL TK Manual)"> |
| 10 |
<meta name="resource-type" content="document"> |
| 11 |
<meta name="distribution" content="global"> |
| 12 |
<meta name="Generator" content="makeinfo"> |
| 13 |
<link href="index.html" rel="start" title="Top"> |
| 14 |
<link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| 15 |
<link href="Control.html" rel="up" title="Control"> |
| 16 |
<link href="destroy.html" rel="next" title="destroy"> |
| 17 |
<link href="after.html" rel="prev" title="after"> |
| 18 |
<style type="text/css"> |
| 19 |
<!-- |
| 20 |
a.summary-letter {text-decoration: none} |
| 21 |
blockquote.indentedblock {margin-right: 0em} |
| 22 |
div.display {margin-left: 3.2em} |
| 23 |
div.example {margin-left: 3.2em} |
| 24 |
div.lisp {margin-left: 3.2em} |
| 25 |
kbd {font-style: oblique} |
| 26 |
pre.display {font-family: inherit} |
| 27 |
pre.format {font-family: inherit} |
| 28 |
pre.menu-comment {font-family: serif} |
| 29 |
pre.menu-preformatted {font-family: serif} |
| 30 |
span.nolinebreak {white-space: nowrap} |
| 31 |
span.roman {font-family: initial; font-weight: normal} |
| 32 |
span.sansserif {font-family: sans-serif; font-weight: normal} |
| 33 |
ul.no-bullet {list-style: none} |
| 34 |
--> |
| 35 |
</style> |
| 36 |
|
| 37 |
|
| 38 |
</head> |
| 39 |
|
| 40 |
<body lang="en"> |
| 41 |
<span id="bind"></span><div class="header"> |
| 42 |
<p> |
| 43 |
Next: <a href="destroy.html" accesskey="n" rel="next">destroy</a>, Previous: <a href="after.html" accesskey="p" rel="prev">after</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 44 |
</div> |
| 45 |
<hr> |
| 46 |
<span id="bind-1"></span><h3 class="section">3.2 bind</h3> |
| 47 |
|
| 48 |
<p>bind \- Arrange for X events to invoke Tcl commands |
| 49 |
</p><span id="Synopsis-16"></span><h4 class="unnumberedsubsec">Synopsis</h4> |
| 50 |
<br><p><b>bind</b><i> windowSpec</i><!-- /@w --><br> |
| 51 |
<br><b>bind</b><i> windowSpec sequence</i><!-- /@w --><br> |
| 52 |
<br><b>bind</b><i> windowSpec sequence command</i><!-- /@w --><br> |
| 53 |
<b>bind</b><i> windowSpec sequence </i><b>+</b><i>command</i> |
| 54 |
</p> |
| 55 |
<span id="Description-13"></span><h4 class="unnumberedsubsec">Description</h4> |
| 56 |
|
| 57 |
<p>If all three arguments are specified, <b>bind</b> will |
| 58 |
arrange for <i>command</i> (a Tcl |
| 59 |
command) to be executed whenever the sequence of events given |
| 60 |
by <i>sequence</i><span class="roman"> occurs in the window(s) identified by </span><i>windowSpec</i>. |
| 61 |
If <i>command</i> is prefixed with a “+”, then it is appended to |
| 62 |
any existing binding for <i>sequence</i><span class="roman">; otherwise </span><i>command</i> replaces |
| 63 |
the existing binding, if any. If <i>command</i> |
| 64 |
is an empty string then the current binding for <i>sequence</i> |
| 65 |
is destroyed, leaving <i>sequence</i> unbound. In all of the cases |
| 66 |
where a <i>command</i><span class="roman"> argument is provided, </span><b>bind</b> returns |
| 67 |
an empty string. |
| 68 |
</p> |
| 69 |
<p>If <i>sequence</i><span class="roman"> is specified without a </span><i>command</i>, then the |
| 70 |
command currently bound to <i>sequence</i> is returned, or |
| 71 |
an empty string if there is no binding for <i>sequence</i>. If |
| 72 |
neither <i>sequence</i><span class="roman"> nor </span><i>command</i> is specified, then the |
| 73 |
return value is a list whose elements are all the sequences |
| 74 |
for which there exist bindings for <i>windowSpec</i>. |
| 75 |
</p> |
| 76 |
<p>The <i>windowSpec</i> argument selects which window(s) the binding |
| 77 |
applies to. |
| 78 |
It may have one of three forms. |
| 79 |
If <i>windowSpec</i> is the path name for a window, then the binding |
| 80 |
applies to that particular window. |
| 81 |
If <i>windowSpec</i> is the name of a class of widgets, then the |
| 82 |
binding applies to all widgets in that class. |
| 83 |
Lastly, <i>windowSpec</i><span class="roman"> may have the value </span><b>all</b>, in which case |
| 84 |
the binding applies to all windows in the application. |
| 85 |
</p> |
| 86 |
<p>The <i>sequence</i> argument specifies a sequence of one or more |
| 87 |
event patterns, with optional white space between the patterns. Each |
| 88 |
event pattern may |
| 89 |
take either of two forms. In the simplest case it is a single |
| 90 |
printing ASCII character, such as <b>a</b><span class="roman"> or </span><b>[</b>. The character |
| 91 |
may not be a space character or the character <b><</b>. This form of |
| 92 |
pattern matches a <b>KeyPress</b> event for the particular |
| 93 |
character. The second form of pattern is longer but more general. |
| 94 |
It has the following syntax: |
| 95 |
</p> |
| 96 |
<div class="example"> |
| 97 |
<pre class="example"><b><</b><i>modifier-modifier-type-detail</i><b>></b> |
| 98 |
</pre></div> |
| 99 |
|
| 100 |
<p>The entire event pattern is surrounded by angle brackets. |
| 101 |
Inside the angle brackets are zero or more modifiers, an event |
| 102 |
type, and an extra piece of information (<i>detail</i>) identifying |
| 103 |
a particular button or keysym. Any of the fields may be omitted, |
| 104 |
as long as at least one of <i>type</i><span class="roman"> and </span><i>detail</i> is present. |
| 105 |
The fields must be separated by white space or dashes. |
| 106 |
</p> |
| 107 |
|
| 108 |
<p>Modifiers may consist of any of the values in the following list: |
| 109 |
</p> |
| 110 |
<div class="example"> |
| 111 |
<pre class="example">Control Any |
| 112 |
Shift Double |
| 113 |
Lock Triple |
| 114 |
Button1, B1 Mod1, M1, Meta, M |
| 115 |
Button2, B2 Mod2, M2, Alt |
| 116 |
Button3, B3 Mod3, M3 |
| 117 |
Button4, B4 Mod4, M4 |
| 118 |
Button5, B5 Mod5, M5 |
| 119 |
</pre></div> |
| 120 |
|
| 121 |
<p>Where more than one value is listed, separated by commas, the values |
| 122 |
are equivalent. All of the modifiers except <b>Any</b>, |
| 123 |
<b>Double</b><span class="roman">, and </span><b>Triple</b> have |
| 124 |
the obvious X meanings. For example, <b>Button1</b> requires that |
| 125 |
button 1 be depressed when the event occurs. Under normal conditions |
| 126 |
the button and modifier state at the time of the event must |
| 127 |
match exactly those specified in the <b>bind</b> command. If |
| 128 |
no modifiers are specified, then events will match only if no modifiers |
| 129 |
are present. If the <b>Any</b> modifier is specified, then additional |
| 130 |
modifiers may be present besides those specified explicitly. For |
| 131 |
example, if button 1 is pressed while the shift and control keys |
| 132 |
are down, the specifier <b><Any-Control-Button-1></b> will match |
| 133 |
the event, but the specifier <b><Control-Button-1></b> will not. |
| 134 |
</p> |
| 135 |
|
| 136 |
<p>The <b>Double</b><span class="roman"> and </span><b>Triple</b> modifiers are a convenience |
| 137 |
for specifying double mouse clicks and other repeated |
| 138 |
events. They cause a particular event pattern to be |
| 139 |
repeated 2 or 3 times, and also place a time and space requirement |
| 140 |
on the sequence: for a sequence of events to match a <b>Double</b> |
| 141 |
or <b>Triple</b> pattern, all of the events must occur close together |
| 142 |
in time and without substantial mouse motion in between. |
| 143 |
For example, <b><Double-Button-1></b> |
| 144 |
is equivalent to <b><Button-1><Button-1></b> with the extra |
| 145 |
time and space requirement. |
| 146 |
</p> |
| 147 |
|
| 148 |
<p>The <i>type</i> field may be any of the standard X event types, with a |
| 149 |
few extra abbreviations. Below is a list of all the valid types; |
| 150 |
where two name appear together, they are synonyms. |
| 151 |
</p> |
| 152 |
<div class="example"> |
| 153 |
<pre class="example">ButtonPress, Button Expose Leave |
| 154 |
ButtonRelease FocusIn Map |
| 155 |
Circulate FocusOut Property |
| 156 |
CirculateRequest Gravity Reparent |
| 157 |
Colormap Keymap ResizeRequest |
| 158 |
Configure KeyPress, Key Unmap |
| 159 |
ConfigureRequest KeyRelease Visibility |
| 160 |
Destroy MapRequest |
| 161 |
Enter Motion |
| 162 |
</pre></div> |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
<p>The last part of a long event specification is <i>detail</i>. In the |
| 167 |
case of a <b>ButtonPress</b><span class="roman"> or </span><b>ButtonRelease</b> event, it is the |
| 168 |
number of a button (1-5). If a button number is given, then only an |
| 169 |
event on that particular button will match; if no button number is |
| 170 |
given, then an event on any button will match. Note: giving a |
| 171 |
specific button number is different than specifying a button modifier; |
| 172 |
in the first case, it refers to a button being pressed or released, |
| 173 |
while in the second it refers to some other button that is already |
| 174 |
depressed when the matching event occurs. If a button |
| 175 |
number is given then <i>type</i> may be omitted: if will default |
| 176 |
to <b>ButtonPress</b><span class="roman">. For example, the specifier </span><b><1></b> |
| 177 |
is equivalent to <b><ButtonPress-1></b>. |
| 178 |
</p> |
| 179 |
|
| 180 |
<p>If the event type is <b>KeyPress</b><span class="roman"> or </span><b>KeyRelease</b>, then |
| 181 |
<i>detail</i> may be specified in the form of an X keysym. Keysyms |
| 182 |
are textual specifications for particular keys on the keyboard; |
| 183 |
they include all the alphanumeric ASCII characters (e.g. “a” is |
| 184 |
the keysym for the ASCII character “a”), plus descriptions for |
| 185 |
non-alphanumeric characters (“comma” is the keysym for the comma |
| 186 |
character), plus descriptions for all the non-ASCII keys on the |
| 187 |
keyboard (“Shift_L” is the keysm for the left shift key, and |
| 188 |
“F1” is the keysym for the F1 function key, if it exists). The |
| 189 |
complete list of keysyms is not presented here; it should be |
| 190 |
available in other X documentation. If necessary, you can use the |
| 191 |
<b>%K</b> notation described below to print out the keysym name for |
| 192 |
an arbitrary key. If a keysym <i>detail</i> is given, then the |
| 193 |
<i>type</i><span class="roman"> field may be omitted; it will default to </span><b>KeyPress</b>. |
| 194 |
For example, <b><Control-comma></b> is equivalent to |
| 195 |
<b><Control-KeyPress-comma></b><span class="roman">. If a keysym </span><i>detail</i> is specified |
| 196 |
then the <b>Shift</b> modifier need not be specified and will be |
| 197 |
ignored if specified: each keysym already implies a particular |
| 198 |
state for the shift key. |
| 199 |
</p> |
| 200 |
|
| 201 |
<p>The <i>command</i><span class="roman"> argument to </span><b>bind</b> is a Tcl command string, |
| 202 |
which will be executed whenever the given event sequence occurs. |
| 203 |
<i>Command</i> will be executed in the same interpreter that the |
| 204 |
<b>bind</b><span class="roman"> command was executed in. If </span><i>command</i> contains |
| 205 |
any <b>%</b> characters, then the command string will not be |
| 206 |
executed directly. Instead, a new command string will be |
| 207 |
generated by replacing each <b>%</b>, and the character following |
| 208 |
it, with information from the current event. The replacement |
| 209 |
depends on the character following the <b>%</b>, as defined in the |
| 210 |
list below. Unless otherwise indicated, the |
| 211 |
replacement string is the decimal value of the given field from |
| 212 |
the current event. |
| 213 |
Some of the substitutions are only valid for |
| 214 |
certain types of events; if they are used for other types of events |
| 215 |
the value substituted is undefined. |
| 216 |
</p> |
| 217 |
<dl compact="compact"> |
| 218 |
<dt><b>%%</b></dt> |
| 219 |
<dd><p>Replaced with a single percent. |
| 220 |
</p></dd> |
| 221 |
<dt><b>|%#|</b></dt> |
| 222 |
<dd><p>The number of the last client request processed by the server |
| 223 |
(the <i>serial</i> field from the event). Valid for all event |
| 224 |
types. |
| 225 |
</p></dd> |
| 226 |
<dt><b>|%a|</b></dt> |
| 227 |
<dd><p>The <i>above</i> field from the event. |
| 228 |
Valid only for <b>ConfigureNotify</b> events. |
| 229 |
</p></dd> |
| 230 |
<dt><b>|%b|</b></dt> |
| 231 |
<dd><p>The number of the button that was pressed or released. Valid only |
| 232 |
for <b>ButtonPress</b><span class="roman"> and </span><b>ButtonRelease</b> events. |
| 233 |
</p></dd> |
| 234 |
<dt><b>|%c|</b></dt> |
| 235 |
<dd><p>The <i>count</i><span class="roman"> field from the event. Valid only for </span><b>Expose</b>, |
| 236 |
<b>GraphicsExpose</b><span class="roman">, and </span><b>MappingNotify</b> events. |
| 237 |
</p></dd> |
| 238 |
<dt><b>|%d|</b></dt> |
| 239 |
<dd><p>The <i>detail</i><span class="roman"> field from the event. The </span><b>|%d|</b> is replaced by |
| 240 |
a string identifying the detail. For <b>EnterNotify</b>, |
| 241 |
<b>LeaveNotify</b><span class="roman">, </span><b>FocusIn</b><span class="roman">, and </span><b>FocusOut</b> events, |
| 242 |
the string will be one of the following: |
| 243 |
</p> |
| 244 |
<div class="example"> |
| 245 |
<pre class="example">NotifyAncestor NotifyNonlinearVirtual |
| 246 |
NotifyDetailNone NotifyPointer |
| 247 |
NotifyInferior NotifyPointerRoot |
| 248 |
NotifyNonlinear NotifyVirtual |
| 249 |
</pre></div> |
| 250 |
|
| 251 |
<p>For <b>ConfigureRequest</b> events, the substituted string will be |
| 252 |
one of the following: |
| 253 |
</p> |
| 254 |
<div class="example"> |
| 255 |
<pre class="example">Above Opposite |
| 256 |
Below TopIf |
| 257 |
BottomIf |
| 258 |
</pre></div> |
| 259 |
|
| 260 |
<p>For events other than these, the substituted string is undefined. |
| 261 |
.RE |
| 262 |
</p></dd> |
| 263 |
<dt><b>|%f|</b></dt> |
| 264 |
<dd><p>The <i>focus</i><span class="roman"> field from the event (</span><b>0</b><span class="roman"> or </span><b>1</b>). Valid only |
| 265 |
for <b>EnterNotify</b><span class="roman"> and </span><b>LeaveNotify</b> events. |
| 266 |
</p></dd> |
| 267 |
<dt><b>|%h|</b></dt> |
| 268 |
<dd><p>The <i>height</i><span class="roman"> field from the event. Valid only for </span><b>Configure</b>, |
| 269 |
<b>ConfigureNotify</b><span class="roman">, </span><b>Expose</b><span class="roman">, </span><b>GraphicsExpose</b>, and |
| 270 |
<b>ResizeRequest</b> events. |
| 271 |
</p></dd> |
| 272 |
<dt><b>|%k|</b></dt> |
| 273 |
<dd><p>The <i>keycode</i><span class="roman"> field from the event. Valid only for </span><b>KeyPress</b> |
| 274 |
and <b>KeyRelease</b> events. |
| 275 |
</p></dd> |
| 276 |
<dt><b>|%m|</b></dt> |
| 277 |
<dd><p>The <i>mode</i> field from the event. The substituted string is one of |
| 278 |
<b>NotifyNormal</b><span class="roman">, </span><b>NotifyGrab</b><span class="roman">, </span><b>NotifyUngrab</b>, or |
| 279 |
<b>NotifyWhileGrabbed</b><span class="roman">. Valid only for </span><b>EnterWindow</b>, |
| 280 |
<b>FocusIn</b><span class="roman">, </span><b>FocusOut</b><span class="roman">, and </span><b>LeaveWindow</b> events. |
| 281 |
</p></dd> |
| 282 |
<dt><b>|%o|</b></dt> |
| 283 |
<dd><p>The <i>override_redirect</i> field from the event. Valid only for |
| 284 |
<b>CreateNotify</b><span class="roman">, </span><b>MapNotify</b><span class="roman">, </span><b>ReparentNotify</b>, |
| 285 |
and <b>ConfigureNotify</b> events. |
| 286 |
</p></dd> |
| 287 |
<dt><b>|%p|</b></dt> |
| 288 |
<dd><p>The <i>place</i> field from the event, substituted as one of the |
| 289 |
strings <b>PlaceOnTop</b><span class="roman"> or </span><b>PlaceOnBottom</b>. Valid only |
| 290 |
for <b>CirculateNotify</b><span class="roman"> and </span><b>CirculateRequest</b> events. |
| 291 |
</p></dd> |
| 292 |
<dt><b>|%s|</b></dt> |
| 293 |
<dd><p>The <i>state</i><span class="roman"> field from the event. For </span><b>ButtonPress</b>, |
| 294 |
<b>ButtonRelease</b><span class="roman">, </span><b>EnterNotify</b><span class="roman">, </span><b>KeyPress</b><span class="roman">, </span><b>KeyRelease</b>, |
| 295 |
<b>LeaveNotify</b><span class="roman">, and </span><b>MotionNotify</b> events, |
| 296 |
a decimal string |
| 297 |
is substituted. For <b>VisibilityNotify</b>, one of the strings |
| 298 |
<b>VisibilityUnobscured</b><span class="roman">, </span><b>VisibilityPartiallyObscured</b>, |
| 299 |
and <b>VisibilityFullyObscured</b> is substituted. |
| 300 |
</p></dd> |
| 301 |
<dt><b>|%t|</b></dt> |
| 302 |
<dd><p>The <i>time</i> field from the event. Valid only for events that |
| 303 |
contain a <i>time</i> field. |
| 304 |
</p></dd> |
| 305 |
<dt><b>|%v|</b></dt> |
| 306 |
<dd><p>The <i>value_mask</i> field from the event. Valid only for |
| 307 |
<b>ConfigureRequest</b> events. |
| 308 |
</p></dd> |
| 309 |
<dt><b>|%w|</b></dt> |
| 310 |
<dd><p>The <i>width</i> field from the event. Valid only for |
| 311 |
<b>Configure</b><span class="roman">, </span><b>ConfigureRequest</b><span class="roman">, </span><b>Expose</b>, |
| 312 |
<b>GraphicsExpose</b><span class="roman">, and </span><b>ResizeRequest</b> events. |
| 313 |
</p></dd> |
| 314 |
<dt><b>|%x|</b></dt> |
| 315 |
<dd><p>The <i>x</i> field from the event. Valid only for events containing |
| 316 |
an <i>x</i> field. |
| 317 |
</p></dd> |
| 318 |
<dt><b>|%y|</b></dt> |
| 319 |
<dd><p>The <i>y</i> field from the event. Valid only for events containing |
| 320 |
a <i>y</i> field. |
| 321 |
</p></dd> |
| 322 |
<dt><b>%A</b></dt> |
| 323 |
<dd><p>Substitutes the ASCII character corresponding to the event, or |
| 324 |
the empty string if the event doesn’t correspond to an ASCII character |
| 325 |
(e.g. the shift key was pressed). <b>XLookupString</b> does all the |
| 326 |
work of translating from the event to an ASCII character. |
| 327 |
Valid only for <b>KeyPress</b><span class="roman"> and </span><b>KeyRelease</b> events. |
| 328 |
</p></dd> |
| 329 |
<dt><b>%B</b></dt> |
| 330 |
<dd><p>The <i>border_width</i> field from the event. Valid only for |
| 331 |
<b>ConfigureNotify</b><span class="roman"> and </span><b>CreateWindow</b> events. |
| 332 |
</p></dd> |
| 333 |
<dt><b>%D</b></dt> |
| 334 |
<dd><p>The <i>display</i> field from the event. Valid for all event types. |
| 335 |
</p></dd> |
| 336 |
<dt><b>%E</b></dt> |
| 337 |
<dd><p>The <i>send_event</i> field from the event. Valid for all event types. |
| 338 |
</p></dd> |
| 339 |
<dt><b>%K</b></dt> |
| 340 |
<dd><p>The keysym corresponding to the event, substituted as a textual |
| 341 |
string. Valid only for <b>KeyPress</b><span class="roman"> and </span><b>KeyRelease</b> events. |
| 342 |
</p></dd> |
| 343 |
<dt><b>%N</b></dt> |
| 344 |
<dd><p>The keysym corresponding to the event, substituted as |
| 345 |
a decimal |
| 346 |
number. Valid only for <b>KeyPress</b><span class="roman"> and </span><b>KeyRelease</b> events. |
| 347 |
</p></dd> |
| 348 |
<dt><b>%R</b></dt> |
| 349 |
<dd><p>The <i>root</i> window identifier from the event. Valid only for |
| 350 |
events containing a <i>root</i> field. |
| 351 |
</p></dd> |
| 352 |
<dt><b>%S</b></dt> |
| 353 |
<dd><p>The <i>subwindow</i> window identifier from the event. Valid only for |
| 354 |
events containing a <i>subwindow</i> field. |
| 355 |
</p></dd> |
| 356 |
<dt><b>%T</b></dt> |
| 357 |
<dd><p>The <i>type</i> field from the event. Valid for all event types. |
| 358 |
</p></dd> |
| 359 |
<dt><b>%W</b></dt> |
| 360 |
<dd><p>The path name of the window to which the event was reported (the |
| 361 |
<i>window</i> field from the event). Valid for all event types. |
| 362 |
</p></dd> |
| 363 |
<dt><b>%X</b></dt> |
| 364 |
<dd><p>The <i>x_root</i> field from the event. |
| 365 |
If a virtual-root window manager is being used then the substituted |
| 366 |
value is the corresponding x-coordinate in the virtual root. |
| 367 |
Valid only for |
| 368 |
<b>ButtonPress</b><span class="roman">, </span><b>ButtonRelease</b><span class="roman">, </span><b>KeyPress</b><span class="roman">, </span><b>KeyRelease</b>, |
| 369 |
and <b>MotionNotify</b> events. |
| 370 |
</p></dd> |
| 371 |
<dt><b>%Y</b></dt> |
| 372 |
<dd><p>The <i>y_root</i> field from the event. |
| 373 |
If a virtual-root window manager is being used then the substituted |
| 374 |
value is the corresponding y-coordinate in the virtual root. |
| 375 |
Valid only for |
| 376 |
<b>ButtonPress</b><span class="roman">, </span><b>ButtonRelease</b><span class="roman">, </span><b>KeyPress</b><span class="roman">, </span><b>KeyRelease</b>, |
| 377 |
and <b>MotionNotify</b> events. |
| 378 |
</p></dd> |
| 379 |
</dl> |
| 380 |
|
| 381 |
|
| 382 |
<p>If the replacement string |
| 383 |
for a %-replacement contains characters that are interpreted |
| 384 |
specially by the Tcl parser (such as backslashes or square |
| 385 |
brackets or spaces) additional backslashes are added |
| 386 |
during replacement so that the result after parsing is the original |
| 387 |
replacement string. |
| 388 |
For example, if <i>command</i> is |
| 389 |
</p> |
| 390 |
<div class="example"> |
| 391 |
<pre class="example">insert %A |
| 392 |
</pre></div> |
| 393 |
|
| 394 |
<p>and the character typed is an open square bracket, then the command |
| 395 |
actually executed will be |
| 396 |
</p> |
| 397 |
<div class="example"> |
| 398 |
<pre class="example">insert \e[ |
| 399 |
</pre></div> |
| 400 |
|
| 401 |
<p>This will cause the <b>insert</b> to receive the original replacement |
| 402 |
string (open square bracket) as its first argument. |
| 403 |
If the extra backslash hadn’t been added, Tcl would not have been |
| 404 |
able to parse the command correctly. |
| 405 |
</p> |
| 406 |
|
| 407 |
<p>At most one binding will trigger for any given X event. |
| 408 |
If several bindings match the recent events, the most specific binding |
| 409 |
is chosen and its command will be executed. |
| 410 |
The following tests are applied, in order, to determine which of |
| 411 |
several matching sequences is more specific: |
| 412 |
(a) a binding whose <i>windowSpec</i> names a particular window is |
| 413 |
more specific than a binding for a class, |
| 414 |
which is more specific than a binding whose <i>windowSpec</i> is |
| 415 |
<b>all</b>; |
| 416 |
(b) a longer sequence (in terms of number |
| 417 |
of events matched) is more specific than a shorter sequence; |
| 418 |
(c) an event pattern that specifies a specific button or key is more specific |
| 419 |
than one that doesn’t; (e) an event pattern that requires a particular |
| 420 |
modifier is more specific than one that doesn’t require the modifier; |
| 421 |
(e) an event pattern specifying the <b>Any</b> modifier is less specific |
| 422 |
than one that doesn’t. If the matching sequences contain more than |
| 423 |
one event, then tests (c)-(e) are applied in order from the most |
| 424 |
recent event to the least recent event in the sequences. If these |
| 425 |
tests fail to determine a winner, then the most recently registered |
| 426 |
sequence is the winner. |
| 427 |
</p> |
| 428 |
|
| 429 |
<p>If an X event does not match any of the existing bindings, then the |
| 430 |
event is ignored (an unbound event is not considered to be an error). |
| 431 |
</p> |
| 432 |
|
| 433 |
<p>When a <i>sequence</i><span class="roman"> specified in a </span><b>bind</b> command contains |
| 434 |
more than one event pattern, then its command is executed whenever |
| 435 |
the recent events (leading up to and including the current event) |
| 436 |
match the given sequence. This means, for example, that if button 1 is |
| 437 |
clicked repeatedly the sequence <b><Double-ButtonPress-1></b> will match |
| 438 |
each button press but the first. |
| 439 |
If extraneous events that would prevent a match occur in the middle |
| 440 |
of an event sequence then the extraneous events are |
| 441 |
ignored unless they are <b>KeyPress</b><span class="roman"> or </span><b>ButtonPress</b> events. |
| 442 |
For example, <b><Double-ButtonPress-1></b> will match a sequence of |
| 443 |
presses of button 1, even though there will be <b>ButtonRelease</b> |
| 444 |
events (and possibly <b>MotionNotify</b> events) between the |
| 445 |
<b>ButtonPress</b> events. |
| 446 |
Furthermore, a <b>KeyPress</b> event may be preceded by any number |
| 447 |
of other <b>KeyPress</b> events for modifier keys without the |
| 448 |
modifier keys preventing a match. |
| 449 |
For example, the event sequence <b>aB</b> will match a press of the |
| 450 |
<b>a</b><span class="roman"> key, a release of the </span><b>a</b><span class="roman"> key, a press of the </span><b>Shift</b> |
| 451 |
key, and a press of the <b>b</b><span class="roman"> key: the press of </span><b>Shift</b> is |
| 452 |
ignored because it is a modifier key. |
| 453 |
Finally, if several <b>MotionNotify</b> events occur in a row, only |
| 454 |
the last one is used for purposes of matching binding sequences. |
| 455 |
</p> |
| 456 |
|
| 457 |
<p>If an error occurs in executing the command for a binding then the |
| 458 |
<b>tkerror</b> mechanism is used to report the error. |
| 459 |
The command will be executed at global level (outside the context |
| 460 |
of any Tcl procedure). |
| 461 |
</p> |
| 462 |
<p>See <a href="tkerror.html">tkerror</a>. |
| 463 |
</p> |
| 464 |
<span id="Keywords-16"></span><h4 class="unnumberedsubsec">Keywords</h4> |
| 465 |
<p>form, manual |
| 466 |
</p><hr> |
| 467 |
<div class="header"> |
| 468 |
<p> |
| 469 |
Next: <a href="destroy.html" accesskey="n" rel="next">destroy</a>, Previous: <a href="after.html" accesskey="p" rel="prev">after</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 470 |
</div> |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
</body> |
| 475 |
</html> |