home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tk3.3b1 / doc / bind.n < prev    next >
Encoding:
Text File  |  1993-04-01  |  17.0 KB  |  446 lines

  1. '\"
  2. '\" Copyright (c) 1990 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/wish/man/RCS/bind.n,v 1.19 93/04/01 09:52:30 ouster Exp $ SPRITE (Berkeley)
  22. '/" 
  23. .so man.macros
  24. .HS bind tk
  25. .BS
  26. '\" Note:  do not modify the .SH NAME line immediately below!
  27. .SH NAME
  28. bind \- Arrange for X events to invoke Tcl commands
  29. .SH SYNOPSIS
  30. \fBbind\fI windowSpec\fR
  31. .br
  32. \fBbind\fI windowSpec sequence\fR
  33. .br
  34. \fBbind\fI windowSpec sequence command\fR
  35. .br
  36. \fBbind\fI windowSpec sequence \fB+\fIcommand\fR
  37. .BE
  38.  
  39. .SH DESCRIPTION
  40. .PP
  41. If all three arguments are specified, \fBbind\fR will
  42. arrange for \fIcommand\fR (a Tcl
  43. command) to be executed whenever the sequence of events given
  44. .VS
  45. by \fIsequence\fR occurs in the window(s) identified by \fIwindowSpec\fR.
  46. .VE
  47. If \fIcommand\fR is prefixed with a ``+'', then it is appended to
  48. any existing binding for \fIsequence\fR;  otherwise \fIcommand\fR replaces
  49. the existing binding, if any.  If \fIcommand\fR
  50. is an empty string then the current binding for \fIsequence\fR
  51. is destroyed, leaving \fIsequence\fR unbound.  In all of the cases
  52. where a \fIcommand\fR argument is provided, \fBbind\fR returns
  53. an empty string.
  54. .PP
  55. If \fIsequence\fR is specified without a \fIcommand\fR, then the
  56. command currently bound to \fIsequence\fR is returned, or
  57. an empty string if there is no binding for \fIsequence\fR.  If
  58. neither \fIsequence\fR nor \fIcommand\fR is specified, then the
  59. return value is a list whose elements are all the sequences
  60. .VS
  61. for which there exist bindings for \fIwindowSpec\fR.
  62. .PP
  63. The \fIwindowSpec\fR argument selects which window(s) the binding
  64. applies to.
  65. It may have one of three forms.
  66. If \fIwindowSpec\fR is the path name for a window, then the binding
  67. applies to that particular window.
  68. If \fIwindowSpec\fR is the name of a class of widgets, then the
  69. binding applies to all widgets in that class.
  70. Lastly, \fIwindowSpec\fR may have the value \fBall\fR, in which case
  71. the binding applies to all windows in the application.
  72. .VE
  73. .PP
  74. The \fIsequence\fR argument specifies a sequence of one or more
  75. event patterns, with optional white space between the patterns.  Each
  76. event pattern may
  77. take either of two forms.  In the simplest case it is a single
  78. printing ASCII character, such as \fBa\fR or \fB[\fR.  The character
  79. may not be a space character or the character \fB<\fR.  This form of
  80. pattern matches a \fBKeyPress\fR event for the particular
  81. character.  The second form of pattern is longer but more general.
  82. It has the following syntax:
  83. .DS C
  84. \fB<\fImodifier-modifier-type-detail\fB>\fR
  85. .DE
  86. The entire event pattern is surrounded by angle brackets.
  87. Inside the angle brackets are zero or more modifiers, an event
  88. type, and an extra piece of information (\fIdetail\fR) identifying
  89. a particular button or keysym.  Any of the fields may be omitted,
  90. as long as at least one of \fItype\fR and \fIdetail\fR is present.
  91. The fields must be separated by white space or dashes.
  92. .LP
  93. Modifiers may consist of any of the values in the following list:
  94. .DS
  95. .ta 6c
  96. \fBControl\fR    \fBAny\fR
  97. \fBShift\fR    \fBDouble\fR    
  98. \fBLock\fR    \fBTriple\fR
  99. .VS
  100. \fBButton1, B1\fR    \fBMod1, M1, Meta, M\fR    
  101. \fBButton2, B2\fR    \fBMod2, M2, Alt\fR
  102. .VE
  103. \fBButton3, B3\fR    \fBMod3, M3\fR
  104. \fBButton4, B4\fR    \fBMod4, M4\fR
  105. \fBButton5, B5\fR    \fBMod5, M5\fR
  106. .DE
  107. Where more than one value is listed, separated by commas, the values
  108. are equivalent.   All of the modifiers except \fBAny\fR,
  109. \fBDouble\fR, and \fBTriple\fR have
  110. the obvious X meanings.  For example, \fBButton1\fR requires that
  111. button 1 be depressed when the event occurs.  Under normal conditions
  112. the button and modifier state at the time of the event must
  113. match exactly those specified in the \fBbind\fR command.  If
  114. no modifiers are specified, then events will match only if no modifiers
  115. are present.  If the \fBAny\fR modifier is specified, then additional
  116. modifiers may be present besides those specified explicitly.  For
  117. example, if button 1 is pressed while the shift and control keys
  118. are down, the specifier \fB<Any-Control-Button-1>\fR will match
  119. the event, but the specifier \fB<Control-Button-1>\fR will not.
  120. .LP
  121. The \fBDouble\fR and \fBTriple\fR modifiers are a convenience
  122. for specifying double mouse clicks and other repeated
  123. events. They cause a particular event pattern to be
  124. repeated 2 or 3 times, and also place a time and space requirement
  125. on the sequence:  for a sequence of events to match a \fBDouble\fR
  126. or \fBTriple\fR pattern, all of the events must occur close together
  127. in time and without substantial mouse motion in between.
  128. For example, \fB<Double-Button-1>\fR
  129. is equivalent to \fB<Button-1><Button-1>\fR with the extra
  130. time and space requirement.
  131. .LP
  132. The \fItype\fR field may be any of the standard X event types, with a
  133. few extra abbreviations.  Below is a list of all the valid types;
  134. where two name appear together, they are synonyms.
  135. .DS C
  136. .ta 5c 10c
  137. \fBButtonPress, Button    Expose    Leave
  138. ButtonRelease    FocusIn    Map
  139. Circulate    FocusOut    Property
  140. CirculateRequest    Gravity    Reparent
  141. Colormap    Keymap    ResizeRequest
  142. Configure    KeyPress, Key    Unmap
  143. .VS
  144. .VE
  145. ConfigureRequest    KeyRelease    Visibility
  146. Destroy    MapRequest
  147. Enter    Motion\fR
  148. .DE
  149. .LP
  150. The last part of a long event specification is \fIdetail\fR.  In the
  151. case of a \fBButtonPress\fR or \fBButtonRelease\fR event, it is the
  152. number of a button (1-5).  If a button number is given, then only an
  153. event on that particular button will match;  if no button number is
  154. given, then an event on any button will match.  Note:  giving a
  155. specific button number is different than specifying a button modifier;
  156. in the first case, it refers to a button being pressed or released,
  157. while in the second it refers to some other button that is already
  158. depressed when the matching event occurs.  If a button
  159. number is given then \fItype\fR may be omitted:  if will default
  160. to \fBButtonPress\fR.  For example, the specifier \fB<1>\fR
  161. is equivalent to \fB<ButtonPress-1>\fR.
  162. .LP
  163. If the event type is \fBKeyPress\fR or \fBKeyRelease\fR, then
  164. \fIdetail\fR may be specified in the form of an X keysym.  Keysyms
  165. are textual specifications for particular keys on the keyboard;
  166. they include all the alphanumeric ASCII characters (e.g. ``a'' is
  167. the keysym for the ASCII character ``a''), plus descriptions for
  168. non-alphanumeric characters (``comma'' is the keysym for the comma
  169. character), plus descriptions for all the non-ASCII keys on the
  170. keyboard (``Shift_L'' is the keysm for the left shift key, and
  171. ``F1'' is the keysym for the F1 function key, if it exists).  The
  172. complete list of keysyms is not presented here;  it should be
  173. available in other X documentation.  If necessary, you can use the
  174. \fB%K\fR notation described below to print out the keysym name for
  175. an arbitrary key.  If a keysym \fIdetail\fR is given, then the
  176. \fItype\fR field may be omitted;  it will default to \fBKeyPress\fR.
  177. For example, \fB<Control-comma>\fR is equivalent to
  178. \fB<Control-KeyPress-comma>\fR.  If a keysym \fIdetail\fR is specified
  179. then the \fBShift\fR modifier need not be specified and will be
  180. ignored if specified:  each keysym already implies a particular
  181. state for the shift key.
  182. .LP
  183. The \fIcommand\fR argument to \fBbind\fR is a Tcl command string,
  184. which will be executed whenever the given event sequence occurs.
  185. \fICommand\fR will be executed in the same interpreter that the
  186. \fBbind\fR command was executed in.  If \fIcommand\fR contains
  187. any \fB%\fR characters, then the command string will not be
  188. executed directly.  Instead, a new command string will be
  189. generated by replacing each \fB%\fR, and the character following
  190. it, with information from the current event.  The replacement
  191. depends on the character following the \fB%\fR, as defined in the
  192. list below.  Unless otherwise indicated, the
  193. .VS
  194. replacement string is the decimal value of the given field from
  195. the current event.
  196. .VE
  197. Some of the substitutions are only valid for
  198. certain types of events;  if they are used for other types of events
  199. the value substituted is undefined.
  200. .TP
  201. \fB%%\fR
  202. Replaced with a single percent.
  203. .TP
  204. \fB%#\fR
  205. The number of the last client request processed by the server
  206. (the \fIserial\fR field from the event).  Valid for all event
  207. types.
  208. .TP
  209. \fB%a\fR
  210. The \fIabove\fR field from the event.
  211. Valid only for \fBConfigureNotify\fR events.
  212. .TP
  213. \fB%b\fR
  214. The number of the button that was pressed or released.  Valid only
  215. for \fBButtonPress\fR and \fBButtonRelease\fR events.
  216. .TP
  217. \fB%c\fR
  218. The \fIcount\fR field from the event.  Valid only for \fBExpose\fR,
  219. \fBGraphicsExpose\fR, and \fBMappingNotify\fR events.
  220. .TP
  221. \fB%d\fR
  222. The \fIdetail\fR field from the event.  The \fB%d\fR is replaced by
  223. a string identifying the detail.  For \fBEnterNotify\fR,
  224. \fBLeaveNotify\fR, \fBFocusIn\fR, and \fBFocusOut\fR events,
  225. the string will be one of the following:
  226. .RS
  227. .DS
  228. .ta 6c
  229. \fBNotifyAncestor    NotifyNonlinearVirtual
  230. NotifyDetailNone    NotifyPointer
  231. NotifyInferior    NotifyPointerRoot
  232. NotifyNonlinear    NotifyVirtual\fR
  233. .DE
  234. For \fBConfigureRequest\fR events, the substituted string will be
  235. one of the following:
  236. .DS
  237. .ta 6c
  238. \fBAbove    Opposite
  239. Below    TopIf
  240. BottomIf\fR
  241. .DE
  242. For events other than these, the substituted string is undefined.
  243. .RE
  244. .TP
  245. \fB%f\fR
  246. The \fIfocus\fR field from the event (\fB0\fR or \fB1\fR).  Valid only
  247. for \fBEnterNotify\fR and \fBLeaveNotify\fR events.
  248. .TP
  249. \fB%h\fR
  250. The \fIheight\fR field from the event.  Valid only for \fBConfigure\fR,
  251. \fBConfigureNotify\fR, \fBExpose\fR, \fBGraphicsExpose\fR, and
  252. \fBResizeRequest\fR events.
  253. .TP
  254. \fB%k\fR
  255. The \fIkeycode\fR field from the event.  Valid only for \fBKeyPress\fR
  256. and \fBKeyRelease\fR events.
  257. .TP
  258. \fB%m\fR
  259. The \fImode\fR field from the event.  The substituted string is one of
  260. \fBNotifyNormal\fR, \fBNotifyGrab\fR, \fBNotifyUngrab\fR, or
  261. \fBNotifyWhileGrabbed\fR.  Valid only for \fBEnterWindow\fR,
  262. \fBFocusIn\fR, \fBFocusOut\fR, and \fBLeaveWindow\fR events.
  263. .TP
  264. \fB%o\fR
  265. The \fIoverride_redirect\fR field from the event.  Valid only for
  266. \fBCreateNotify\fR, \fBMapNotify\fR, \fBReparentNotify\fR,
  267. and \fBConfigureNotify\fR events.
  268. .TP
  269. \fB%p\fR
  270. The \fIplace\fR field from the event, substituted as one of the
  271. strings \fBPlaceOnTop\fR or \fBPlaceOnBottom\fR.  Valid only
  272. for \fBCirculateNotify\fR and \fBCirculateRequest\fR events.
  273. .TP
  274. \fB%s\fR
  275. The \fIstate\fR field from the event.  For \fBButtonPress\fR,
  276. \fBButtonRelease\fR, \fBEnterNotify\fR, \fBKeyPress\fR, \fBKeyRelease\fR,
  277. \fBLeaveNotify\fR, and \fBMotionNotify\fR events,
  278. .VS
  279. a decimal string
  280. .VE
  281. is substituted.  For \fBVisibilityNotify\fR, one of the strings
  282. \fBVisibilityUnobscured\fR, \fBVisibilityPartiallyObscured\fR,
  283. and \fBVisibilityFullyObscured\fR is substituted.
  284. .TP
  285. \fB%t\fR
  286. The \fItime\fR field from the event.  Valid only for events that
  287. contain a \fItime\fR field.
  288. .TP
  289. \fB%v\fR
  290. The \fIvalue_mask\fR field from the event.  Valid only for
  291. \fBConfigureRequest\fR events.
  292. .TP
  293. \fB%w\fR
  294. The \fIwidth\fR field from the event.  Valid only for
  295. \fBConfigure\fR, \fBConfigureRequest\fR, \fBExpose\fR,
  296. \fBGraphicsExpose\fR, and \fBResizeRequest\fR events.
  297. .TP
  298. \fB%x\fR
  299. The \fIx\fR field from the event.  Valid only for events containing
  300. an \fIx\fR field.
  301. .TP
  302. \fB%y\fR
  303. The \fIy\fR field from the event.  Valid only for events containing
  304. a \fIy\fR field.
  305. .TP
  306. \fB%A\fR
  307. Substitutes the ASCII character corresponding to the event, or
  308. the empty string if the event doesn't correspond to an ASCII character
  309. (e.g. the shift key was pressed).  \fBXLookupString\fR does all the
  310. work of translating from the event to an ASCII character.
  311. Valid only for \fBKeyPress\fR and \fBKeyRelease\fR events.
  312. .TP
  313. \fB%B\fR
  314. The \fIborder_width\fR field from the event.  Valid only for
  315. \fBConfigureNotify\fR and \fBCreateWindow\fR events.
  316. .TP
  317. \fB%D\fR
  318. The \fIdisplay\fR field from the event.  Valid for all event types.
  319. .TP
  320. \fB%E\fR
  321. The \fIsend_event\fR field from the event.  Valid for all event types.
  322. .TP
  323. \fB%K\fR
  324. The keysym corresponding to the event, substituted as a textual
  325. string.  Valid only for \fBKeyPress\fR and \fBKeyRelease\fR events.
  326. .TP
  327. \fB%N\fR
  328. The keysym corresponding to the event, substituted as
  329. .VS
  330. a decimal
  331. .VE
  332. number.  Valid only for \fBKeyPress\fR and \fBKeyRelease\fR events.
  333. .TP
  334. \fB%R\fR
  335. The \fIroot\fR window identifier from the event.  Valid only for
  336. events containing a \fIroot\fR field.
  337. .TP
  338. \fB%S\fR
  339. The \fIsubwindow\fR window identifier from the event.  Valid only for
  340. events containing a \fIsubwindow\fR field.
  341. .TP
  342. \fB%T\fR
  343. The \fItype\fR field from the event.  Valid for all event types.
  344. .TP
  345. \fB%W\fR
  346. The path name of the window to which the event was reported (the
  347. \fIwindow\fR field from the event).  Valid for all event types.
  348. .TP
  349. \fB%X\fR
  350. The \fIx_root\fR field from the event.
  351. .VS
  352. If a virtual-root window manager is being used then the substituted
  353. value is the corresponding x-coordinate in the virtual root.
  354. .VE
  355. Valid only for
  356. \fBButtonPress\fR, \fBButtonRelease\fR, \fBKeyPress\fR, \fBKeyRelease\fR,
  357. and \fBMotionNotify\fR events.
  358. .TP
  359. \fB%Y\fR
  360. The \fIy_root\fR field from the event.
  361. .VS
  362. If a virtual-root window manager is being used then the substituted
  363. value is the corresponding y-coordinate in the virtual root.
  364. .VE
  365. Valid only for
  366. \fBButtonPress\fR, \fBButtonRelease\fR, \fBKeyPress\fR, \fBKeyRelease\fR,
  367. and \fBMotionNotify\fR events.
  368. .LP
  369. If the replacement string
  370. .VS
  371. for a %-replacement contains characters that are interpreted
  372. specially by the Tcl parser (such as backslashes or square
  373. brackets or spaces) additional backslashes are added
  374. during replacement so that the result after parsing is the original
  375. replacement string.
  376. For example, if \fIcommand\fR is
  377. .DS
  378. \fBinsert\0%A\fR
  379. .DE
  380. and the character typed is an open square bracket, then the command
  381. actually executed will be
  382. .DS
  383. \fBinsert\0\e[\fR
  384. .DE
  385. This will cause the \fBinsert\fR to receive the original replacement
  386. string (open square bracket) as its first argument.
  387. If the extra backslash hadn't been added, Tcl would not have been
  388. able to parse the command correctly.
  389. .VE
  390. .LP
  391. At most one binding will trigger for any given X event.
  392. If several bindings match the recent events, the most specific binding
  393. is chosen and its command will be executed.
  394. The following tests are applied, in order, to determine which of
  395. several matching sequences is more specific:
  396. .VS
  397. (a) a binding whose \fIwindowSpec\fR names a particular window is
  398. more specific than a binding for a class,
  399. which is more specific than a binding whose \fIwindowSpec\fR is
  400. \fBall\fR;
  401. .VE
  402. (b) a longer sequence (in terms of number
  403. of events matched) is more specific than a shorter sequence;
  404. (c) an event pattern that specifies a specific button or key is more specific
  405. than one that doesn't;  (e) an event pattern that requires a particular
  406. modifier is more specific than one that doesn't require the modifier;
  407. (e) an event pattern specifying the \fBAny\fR modifier is less specific
  408. than one that doesn't.  If the matching sequences contain more than
  409. one event, then tests (c)-(e) are applied in order from the most
  410. recent event to the least recent event in the sequences.  If these
  411. tests fail to determine a winner, then the most recently registered
  412. sequence is the winner.
  413. .LP
  414. If an X event does not match any of the existing bindings, then the
  415. event is ignored (an unbound event is not considered to be an error).
  416. .LP
  417. When a \fIsequence\fR specified in a \fBbind\fR command contains
  418. more than one event pattern, then its command is executed whenever
  419. the recent events (leading up to and including the current event)
  420. match the given sequence.  This means, for example, that if button 1 is
  421. clicked repeatedly the sequence \fB<Double-ButtonPress-1>\fR will match
  422. each button press but the first.  Extraneous \fBButtonRelease\fR,
  423. .VS
  424. \fBKeyRelease\fR, \fBMotionNotify\fR, \fBGraphicsExpose\fR, and
  425. \fBNoExpose\fR events are ignored if they
  426. .VE
  427. would otherwise prevent a binding from matching recent events.  Thus,
  428. \fB<Double-ButtonPress-1>\fR will match a sequence of presses of button 1,
  429. even though there will be \fBButtonRelease\fR events (and possibly
  430. \fBMotionNotify\fR events) between the \fBButtonPress\fR events.
  431. In addition, if several \fBMotionNotify\fR events occur in a row, only
  432. the last one is used for purposes of matching binding sequences.
  433. .LP
  434. If an error occurs in executing the command for a binding then the
  435. \fBtkerror\fR mechanism is used to report the error.
  436. .VS
  437. The command will be executed at global level (outside the context
  438. of any Tcl procedure).
  439. .VE
  440.  
  441. .SH "SEE ALSO"
  442. tkerror
  443.  
  444. .SH KEYWORDS
  445. form, manual
  446.