home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _8b48178f6b64ba6fd0e7370dde83e75c < prev    next >
Text File  |  2000-03-23  |  27KB  |  527 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Tk::bind - Arrange for X events to invoke callbacks</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Tk::bind - Arrange for X events to invoke callbacks</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#event patterns">EVENT PATTERNS</A></LI>
  26.     <LI><A HREF="#modifiers">MODIFIERS</A></LI>
  27.     <LI><A HREF="#event types">EVENT TYPES</A></LI>
  28.     <LI><A HREF="#binding callbacks and substitutions">BINDING CALLBACKS AND SUBSTITUTIONS</A></LI>
  29.     <LI><A HREF="#multiple matches">MULTIPLE MATCHES</A></LI>
  30.     <LI><A HREF="#multievent sequences and ignored events">MULTI-EVENT SEQUENCES AND IGNORED EVENTS</A></LI>
  31.     <LI><A HREF="#errors">ERRORS</A></LI>
  32.     <LI><A HREF="#caveats">CAVEATS</A></LI>
  33.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  34.     <LI><A HREF="#keywords">KEYWORDS</A></LI>
  35. </UL>
  36. <!-- INDEX END -->
  37.  
  38. <HR>
  39. <P>
  40. <H1><A NAME="name">NAME</A></H1>
  41. <P>Tk::bind - Arrange for X events to invoke callbacks</P>
  42. <P>
  43. <HR>
  44. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  45. <UL>
  46. <LI>Linux</LI>
  47. <LI>Solaris</LI>
  48. <LI>Windows</LI>
  49. </UL>
  50. <HR>
  51. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  52. <P>Retrieve bindings:</P>
  53. <P>    <EM>$widget</EM>-><STRONG>bind</STRONG></P>
  54. <P>    <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>tag</EM>)</P>
  55. <P>    <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>sequence</EM>)</P>
  56. <P>    <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>tag</EM>,<EM>sequence</EM>)</P>
  57. <P>Associate and destroy bindings:</P>
  58. <P>    <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>sequence</EM>,<EM>callback</EM>)</P>
  59. <P>    <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>tag</EM>,<EM>sequence</EM>,<EM>callback</EM>)</P>
  60. <P>
  61. <HR>
  62. <H1><A NAME="description">DESCRIPTION</A></H1>
  63. <P>The <STRONG>bind</STRONG> method associates callbacks with X events.
  64. If <EM>callback</EM> is specified, <STRONG>bind</STRONG> will
  65. arrange for <EM>callback</EM> to be evaluated whenever
  66. the <CODE>event(s)</CODE> given by <EM>sequence</EM> occur in the <CODE>window(s)</CODE>
  67. identified by <EM>$widget</EM> or <EM>tag</EM>.
  68. If <EM>callback</EM> is an empty string then the current binding for
  69. <EM>sequence</EM> is destroyed, leaving <EM>sequence</EM> unbound.
  70. In all of the cases where a <EM>callback</EM> argument is provided,
  71. <STRONG>bind</STRONG> returns an empty string.</P>
  72. <P>If <EM>sequence</EM> is specified without a <EM>callback</EM>, then the
  73. callback currently bound to <EM>sequence</EM> is returned, or
  74. <STRONG>undef</STRONG> is returned if there is no binding for <EM>sequence</EM>.
  75. If neither <EM>sequence</EM> nor <EM>callback</EM> is specified, then the
  76. return value is a list whose elements are all the sequences
  77. for which there exist bindings for <EM>tag</EM>.</P>
  78. <P>If no <EM>tag</EM> is specified then the <STRONG>bind</STRONG> refers to <EM>$widget</EM>.
  79. If <EM>tag</EM> is specified then it is typically a class name and the <STRONG>bind</STRONG>
  80. refers to all instances of the class on the <STRONG>MainWindow</STRONG> associated
  81. with <EM>$widget</EM>. (It is possible for <EM>tag</EM> to be another ``widget object''
  82. but this practice is deprecated.) Perl's <STRONG>ref</STRONG>(<EM>$object</EM>) can be used
  83. to get the class name of any object.
  84. Each window has an associated list of tags, and a binding applies
  85. to a particular window if its tag is among those specified for
  86. the window.
  87. Although the <STRONG>bindtags</STRONG> method may be used to assign an
  88. arbitrary set of binding tags to a window, the default binding
  89. tags provide the following behavior:</P>
  90. <P>If a tag is the name of an internal window the binding applies
  91. to that window.</P>
  92. <P>If the tag is the name of a toplevel window the binding applies
  93. to the toplevel window and all its internal windows.</P>
  94. <P>If the tag is the name of a class of widgets, such as <STRONG>Tk::Button</STRONG>,
  95. the binding applies to all widgets in that class;</P>
  96. <P>If <EM>tag</EM> has the value <STRONG>all</STRONG>,
  97. the binding applies to all windows descended from the MainWindow
  98. of the application.</P>
  99. <P>
  100. <HR>
  101. <H1><A NAME="event patterns">EVENT PATTERNS</A></H1>
  102. <P>The <EM>sequence</EM> argument specifies a sequence of one or more
  103. event patterns, with optional white space between the patterns.  Each
  104. event pattern has the following syntax:</P>
  105. <P>    '<modifier-modifier-type-detail>'</P>
  106. <P>The entire event pattern is surrounded by angle brackets, and normally
  107. needs to be quoted, as angle brackets are special to perl.
  108. Inside the angle brackets are zero or more modifiers, an event
  109. type, and an extra piece of information (<EM>detail</EM>) identifying
  110. a particular button or keysym.  Any of the fields may be omitted,
  111. as long as at least one of <EM>type</EM> and <EM>detail</EM> is present.
  112. The fields must be separated by white space or dashes.</P>
  113. <P>A second form of pattern is used to specify a user-defined, named virtual
  114. event; see <A HREF="../../../site/lib/Tk/event.html">the Tk::event manpage</A> for details.  It has the following syntax:</P>
  115. <P>    <<name>></P>
  116. <P>The entire virtual event pattern is surrounded by double angle brackets.
  117. Inside the angle brackets is the user-defined name of the virtual event.
  118. Modifiers, such as <STRONG>Shift</STRONG> or <STRONG>Control</STRONG>, may not be combined with a
  119. virtual event to modify it.  Bindings on a virtual event may be created
  120. before the virtual event is defined, and if the definition of a virtual
  121. event changes dynamically, all windows bound to that virtual event will
  122. respond immediately to the new definition.</P>
  123. <P>
  124. <HR>
  125. <H1><A NAME="modifiers">MODIFIERS</A></H1>
  126. <P>Modifiers consist of any of the following values:</P>
  127. <PRE>
  128.  Control        Mod2, M2
  129.  Shift          Mod3, M3
  130.  Lock           Mod4, M4
  131.  Button1, B1    Mod5, M5
  132.  Button2, B2    Meta, M
  133.  Button3, B3    Alt
  134.  Button4, B4    Double
  135.  Button5, B5    Triple
  136.  Mod1,    M1</PRE>
  137. <P>Where more than one value is listed, separated by commas, the values
  138. are equivalent.
  139. Most of the modifiers have the obvious X meanings.
  140. For example, <STRONG>Button1</STRONG> requires that
  141. button 1 be depressed when the event occurs.
  142. For a binding to match a given event, the modifiers in the event
  143. must include all of those specified in the event pattern.
  144. An event may also contain additional modifiers not specified in
  145. the binding.
  146. For example, if button 1 is pressed while the shift and control keys
  147. are down, the pattern <STRONG><Control-Button-1></STRONG> will match
  148. the event, but <STRONG><Mod1-Button-1></STRONG> will not.
  149. If no modifiers are specified, then any combination of modifiers may
  150. be present in the event.</P>
  151. <P><STRONG>Meta</STRONG> and <STRONG>M</STRONG> refer to whichever of the
  152. <STRONG>M1</STRONG> through <STRONG>M5</STRONG> modifiers is associated with the meta
  153. <CODE>key(s)</CODE> on the keyboard (keysyms <STRONG>Meta_R</STRONG> and <STRONG>Meta_L</STRONG>).
  154. If there are no meta keys, or if they are not associated with any
  155. modifiers, then <STRONG>Meta</STRONG> and <STRONG>M</STRONG> will not match any events.
  156. Similarly, the <STRONG>Alt</STRONG> modifier refers to whichever modifier
  157. is associated with the alt <CODE>key(s)</CODE> on the keyboard (keysyms
  158. <STRONG>Alt_L</STRONG> and <STRONG>Alt_R</STRONG>).</P>
  159. <P>The <STRONG>Double</STRONG> and <STRONG>Triple</STRONG> modifiers are a convenience
  160. for specifying double mouse clicks and other repeated
  161. events. They cause a particular event pattern to be
  162. repeated 2 or 3 times, and also place a time and space requirement
  163. on the sequence:  for a sequence of events to match a <STRONG>Double</STRONG>
  164. or <STRONG>Triple</STRONG> pattern, all of the events must occur close together
  165. in time and without substantial mouse motion in between.
  166. For example, <STRONG><Double-Button-1></STRONG>
  167. is equivalent to <STRONG><Button-1><Button-1></STRONG> with the extra
  168. time and space requirement.</P>
  169. <P>
  170. <HR>
  171. <H1><A NAME="event types">EVENT TYPES</A></H1>
  172. <P>The <EM>type</EM> field may be any of the standard X event types, with a
  173. few extra abbreviations.  Below is a list of all the valid types;
  174. where two names appear together, they are synonyms.</P>
  175. <PRE>
  176.  ButtonPress, Button    Expose  Map
  177.  ButtonRelease  FocusIn Motion
  178.  Circulate      FocusOut        Property
  179.  Colormap       Gravity Reparent
  180.  Configure      KeyPress, Key   Unmap
  181.  Destroy        KeyRelease      Visibility
  182.  Enter  Leave   Activate
  183.  Deactivate</PRE>
  184. <P>The last part of a long event specification is <EM>detail</EM>.  In the
  185. case of a <STRONG>ButtonPress</STRONG> or <STRONG>ButtonRelease</STRONG> event, it is the
  186. number of a button (1-5).  If a button number is given, then only an
  187. event on that particular button will match;  if no button number is
  188. given, then an event on any button will match.  Note:  giving a
  189. specific button number is different than specifying a button modifier;
  190. in the first case, it refers to a button being pressed or released,
  191. while in the second it refers to some other button that is already
  192. depressed when the matching event occurs.  If a button
  193. number is given then <EM>type</EM> may be omitted:  if will default
  194. to <STRONG>ButtonPress</STRONG>.  For example, the specifier <STRONG><1></STRONG>
  195. is equivalent to <STRONG><ButtonPress-1></STRONG>.</P>
  196. <P>If the event type is <STRONG>KeyPress</STRONG> or <STRONG>KeyRelease</STRONG>, then
  197. <EM>detail</EM> may be specified in the form of an X keysym.  Keysyms
  198. are textual specifications for particular keys on the keyboard;
  199. they include all the alphanumeric ASCII characters (e.g. ``a'' is
  200. the keysym for the ASCII character ``a''), plus descriptions for
  201. non-alphanumeric characters (``comma'' is the keysym for the comma
  202. character), plus descriptions for all the non-ASCII keys on the
  203. keyboard (``Shift_L'' is the keysm for the left shift key, and
  204. ``F1'' is the keysym for the F1 function key, if it exists).  The
  205. complete list of keysyms is not presented here;  it is
  206. available in other X documentation and may vary from system to
  207. system.
  208. If necessary, you can use the <STRONG>'K'</STRONG> notation described below
  209. to print out the keysym name for a particular key.
  210. If a keysym <EM>detail</EM> is given, then the
  211. <EM>type</EM> field may be omitted;  it will default to <STRONG>KeyPress</STRONG>.
  212. For example, <STRONG><Control-comma></STRONG> is equivalent to
  213. <STRONG><Control-KeyPress-comma></STRONG>.</P>
  214. <P>
  215. <HR>
  216. <H1><A NAME="binding callbacks and substitutions">BINDING CALLBACKS AND SUBSTITUTIONS</A></H1>
  217. <P>The <EM>callback</EM> argument to <STRONG>bind</STRONG> is a perl/Tk callback.
  218. which will be executed whenever the given event sequence occurs.
  219. (See <A HREF="../../../site/lib/Tk/callbacks.html">the Tk::callbacks manpage</A> for description of the possible forms.)
  220. <EM>Callback</EM> will be associated with the same <STRONG>MainWindow</STRONG>
  221. that is associated with the <EM>$widget</EM> that was used to invoke
  222. the <STRONG>bind</STRONG> method, and it will run as though called from <STRONG>MainLoop</STRONG>.
  223. If <EM>callback</EM> contains
  224. any <STRONG>Ev</STRONG>(<EM>%</EM>) calls, then each ``nested'' <STRONG>Ev</STRONG>(<EM>%</EM>)
  225. ``callback'' will be evaluated when the event occurs to form arguments
  226. to be passed to the main <EM>callback</EM>.
  227. The replacement
  228. depends on the character <EM>%</EM>, as defined in the
  229. list below.  Unless otherwise indicated, the
  230. replacement string is the numeric (decimal) value of the given field from
  231. the current event. Perl/Tk has enhanced this mechanism slightly compared
  232. to the comparable Tcl/Tk mechanism. The enhancements are not yet all
  233. reflected in the list below.
  234. Some of the substitutions are only valid for
  235. certain types of events;  if they are used for other types of events
  236. the value substituted is undefined (not the same as <STRONG>undef</STRONG>!).</P>
  237. <DL>
  238. <DT><STRONG><A NAME="item_%27%23%27"><STRONG>'#'</STRONG></A></STRONG><BR>
  239. <DD>
  240. The number of the last client request processed by the server
  241. (the <EM>serial</EM> field from the event).  Valid for all event
  242. types.
  243. <P></P>
  244. <DT><STRONG><A NAME="item_%27a%27"><STRONG>'a'</STRONG></A></STRONG><BR>
  245. <DD>
  246. The <EM>above</EM> field from the event,
  247. formatted as a hexadecimal number.
  248. Valid only for <STRONG>Configure</STRONG> events.
  249. <P></P>
  250. <DT><STRONG><A NAME="item_%27b%27"><STRONG>'b'</STRONG></A></STRONG><BR>
  251. <DD>
  252. The number of the button that was pressed or released.  Valid only
  253. for <STRONG>ButtonPress</STRONG> and <STRONG>ButtonRelease</STRONG> events.
  254. <P></P>
  255. <DT><STRONG><A NAME="item_%27c%27"><STRONG>'c'</STRONG></A></STRONG><BR>
  256. <DD>
  257. The <EM>count</EM> field from the event.  Valid only for <STRONG>Expose</STRONG> events.
  258. <P></P>
  259. <DT><STRONG><A NAME="item_%27d%27"><STRONG>'d'</STRONG></A></STRONG><BR>
  260. <DD>
  261. The <EM>detail</EM> field from the event.  The <STRONG>'d'</STRONG> is replaced by
  262. a string identifying the detail.  For <STRONG>Enter</STRONG>,
  263. <STRONG>Leave</STRONG>, <STRONG>FocusIn</STRONG>, and <STRONG>FocusOut</STRONG> events,
  264. the string will be one of the following:
  265. <PRE>
  266.  NotifyAncestor NotifyNonlinearVirtual
  267.  NotifyDetailNone       NotifyPointer
  268.  NotifyInferior NotifyPointerRoot
  269.  NotifyNonlinear        NotifyVirtual</PRE>
  270. <P>For events other than these, the substituted string is undefined.
  271. (Note that this is <EM>not</EM> the same as Detail part of sequence
  272. use to specify the event.)</P>
  273. <DT><STRONG><A NAME="item_%27f%27"><STRONG>'f'</STRONG></A></STRONG><BR>
  274. <DD>
  275. The <EM>focus</EM> field from the event (<STRONG>0</STRONG> or <STRONG>1</STRONG>).  Valid only
  276. for <STRONG>Enter</STRONG> and <STRONG>Leave</STRONG> events.
  277. <P></P>
  278. <DT><STRONG><A NAME="item_%27h%27"><STRONG>'h'</STRONG></A></STRONG><BR>
  279. <DD>
  280. The <EM>height</EM> field from the event.  Valid only for <STRONG>Configure</STRONG>,
  281. <STRONG>Expose</STRONG>, and <STRONG>GraphicsExpose</STRONG> events.
  282. <P></P>
  283. <DT><STRONG><A NAME="item_%27k%27"><STRONG>'k'</STRONG></A></STRONG><BR>
  284. <DD>
  285. The <EM>keycode</EM> field from the event.  Valid only for <STRONG>KeyPress</STRONG>
  286. and <STRONG>KeyRelease</STRONG> events.
  287. <P></P>
  288. <DT><STRONG><A NAME="item_%27m%27"><STRONG>'m'</STRONG></A></STRONG><BR>
  289. <DD>
  290. The <EM>mode</EM> field from the event.  The substituted string is one of
  291. <STRONG>NotifyNormal</STRONG>, <STRONG>NotifyGrab</STRONG>, <STRONG>NotifyUngrab</STRONG>, or
  292. <STRONG>NotifyWhileGrabbed</STRONG>.  Valid only for <STRONG>EnterWindow</STRONG>,
  293. <STRONG>FocusIn</STRONG>, <STRONG>FocusOut</STRONG>, and <STRONG>LeaveWindow</STRONG> events.
  294. <P></P>
  295. <DT><STRONG><A NAME="item_%27o%27"><STRONG>'o'</STRONG></A></STRONG><BR>
  296. <DD>
  297. The <EM>override_redirect</EM> field from the event.  Valid only for
  298. <STRONG>Map</STRONG>, <STRONG>Reparent</STRONG>, and <STRONG>Configure</STRONG> events.
  299. <P></P>
  300. <DT><STRONG><A NAME="item_%27p%27"><STRONG>'p'</STRONG></A></STRONG><BR>
  301. <DD>
  302. The <EM>place</EM> field from the event, substituted as one of the
  303. strings <STRONG>PlaceOnTop</STRONG> or <STRONG>PlaceOnBottom</STRONG>.  Valid only
  304. for <STRONG>Circulate</STRONG> events.
  305. <P></P>
  306. <DT><STRONG><A NAME="item_%27s%27"><STRONG>'s'</STRONG></A></STRONG><BR>
  307. <DD>
  308. The <EM>state</EM> field from the event.  For <STRONG>ButtonPress</STRONG>,
  309. <STRONG>ButtonRelease</STRONG>, <STRONG>Enter</STRONG>, <STRONG>KeyPress</STRONG>, <STRONG>KeyRelease</STRONG>,
  310. <STRONG>Leave</STRONG>, and <STRONG>Motion</STRONG> events, a decimal string
  311. is substituted.  For <STRONG>Visibility</STRONG>, one of the strings
  312. <STRONG>VisibilityUnobscured</STRONG>, <STRONG>VisibilityPartiallyObscured</STRONG>,
  313. and <STRONG>VisibilityFullyObscured</STRONG> is substituted.
  314. <P></P>
  315. <DT><STRONG><A NAME="item_%27t%27"><STRONG>'t'</STRONG></A></STRONG><BR>
  316. <DD>
  317. The <EM>time</EM> field from the event.  Valid only for events that
  318. contain a <EM>time</EM> field.
  319. <P></P>
  320. <DT><STRONG><A NAME="item_%27w%27"><STRONG>'w'</STRONG></A></STRONG><BR>
  321. <DD>
  322. The <EM>width</EM> field from the event.  Valid only for
  323. <STRONG>Configure</STRONG>, <STRONG>Expose</STRONG>, and <STRONG>GraphicsExpose</STRONG> events.
  324. <P></P>
  325. <DT><STRONG><A NAME="item_%27x%27"><STRONG>'x'</STRONG></A></STRONG><BR>
  326. <DD>
  327. The <EM>x</EM> field from the event.  Valid only for events containing
  328. an <EM>x</EM> field.
  329. <P></P>
  330. <DT><STRONG><A NAME="item_%27y%27"><STRONG>'y'</STRONG></A></STRONG><BR>
  331. <DD>
  332. The <EM>y</EM> field from the event.  Valid only for events containing
  333. a <EM>y</EM> field.
  334. <P></P>
  335. <DT><STRONG><A NAME="item_%27%40%27"><STRONG>'@'</STRONG></A></STRONG><BR>
  336. <DD>
  337. The string ``@<EM>x,y</EM>'' where <EM>x</EM> and <EM>y</EM> are as above.
  338. Valid only for events containing <EM>x</EM> and <EM>y</EM> fields.
  339. This format is used my methods of <STRONG>Tk::Text</STRONG> and similar widgets.
  340. <P></P>
  341. <DT><STRONG><A NAME="item_%27A%27"><STRONG>'A'</STRONG></A></STRONG><BR>
  342. <DD>
  343. Substitutes the ASCII character corresponding to the event, or
  344. the empty string if the event doesn't correspond to an ASCII character
  345. (e.g. the shift key was pressed).  <STRONG>XLookupString</STRONG> does all the
  346. work of translating from the event to an ASCII character.
  347. Valid only for <STRONG>KeyPress</STRONG> and <STRONG>KeyRelease</STRONG> events.
  348. <P></P>
  349. <DT><STRONG><A NAME="item_%27B%27"><STRONG>'B'</STRONG></A></STRONG><BR>
  350. <DD>
  351. The <EM>border_width</EM> field from the event.  Valid only for
  352. <STRONG>Configure</STRONG> events.
  353. <P></P>
  354. <DT><STRONG><A NAME="item_%27E%27"><STRONG>'E'</STRONG></A></STRONG><BR>
  355. <DD>
  356. The <EM>send_event</EM> field from the event.  Valid for all event types.
  357. <P></P>
  358. <DT><STRONG><A NAME="item_%27K%27"><STRONG>'K'</STRONG></A></STRONG><BR>
  359. <DD>
  360. The keysym corresponding to the event, substituted as a textual
  361. string.  Valid only for <STRONG>KeyPress</STRONG> and <STRONG>KeyRelease</STRONG> events.
  362. <P></P>
  363. <DT><STRONG><A NAME="item_%27N%27"><STRONG>'N'</STRONG></A></STRONG><BR>
  364. <DD>
  365. The keysym corresponding to the event, substituted as
  366. a decimal
  367. number.  Valid only for <STRONG>KeyPress</STRONG> and <STRONG>KeyRelease</STRONG> events.
  368. <P></P>
  369. <DT><STRONG><A NAME="item_%27R%27"><STRONG>'R'</STRONG></A></STRONG><BR>
  370. <DD>
  371. The <EM>root</EM> window identifier from the event.  Valid only for
  372. events containing a <EM>root</EM> field.
  373. <P></P>
  374. <DT><STRONG><A NAME="item_%27S%27"><STRONG>'S'</STRONG></A></STRONG><BR>
  375. <DD>
  376. The <EM>subwindow</EM> window identifier from the event,
  377. as an object if it is one otherwise as a hexadecimal number.
  378. Valid only for events containing a <EM>subwindow</EM> field.
  379. <P></P>
  380. <DT><STRONG><A NAME="item_%27T%27"><STRONG>'T'</STRONG></A></STRONG><BR>
  381. <DD>
  382. The <EM>type</EM> field from the event.  Valid for all event types.
  383. <P></P>
  384. <DT><STRONG><A NAME="item_%27W%27"><STRONG>'W'</STRONG></A></STRONG><BR>
  385. <DD>
  386. The window to which the event was reported (the
  387. $widget field from the event) - as an perl/Tk object.
  388. Valid for all event types.
  389. <P></P>
  390. <DT><STRONG><A NAME="item_%27X%27"><STRONG>'X'</STRONG></A></STRONG><BR>
  391. <DD>
  392. The <EM>x_root</EM> field from the event.
  393. If a virtual-root window manager is being used then the substituted
  394. value is the corresponding x-coordinate in the virtual root.
  395. Valid only for
  396. <STRONG>ButtonPress</STRONG>, <STRONG>ButtonRelease</STRONG>, <STRONG>KeyPress</STRONG>, <STRONG>KeyRelease</STRONG>,
  397. and <STRONG>Motion</STRONG> events.
  398. <P></P>
  399. <DT><STRONG><A NAME="item_%27Y%27"><STRONG>'Y'</STRONG></A></STRONG><BR>
  400. <DD>
  401. The <EM>y_root</EM> field from the event.
  402. If a virtual-root window manager is being used then the substituted
  403. value is the corresponding y-coordinate in the virtual root.
  404. Valid only for
  405. <STRONG>ButtonPress</STRONG>, <STRONG>ButtonRelease</STRONG>, <STRONG>KeyPress</STRONG>, <STRONG>KeyRelease</STRONG>,
  406. and <STRONG>Motion</STRONG> events.
  407. <P></P></DL>
  408. <P>
  409. <HR>
  410. <H1><A NAME="multiple matches">MULTIPLE MATCHES</A></H1>
  411. <P>It is possible for several bindings to match a given X event.
  412. If the bindings are associated with different <EM>tag</EM>'s,
  413. then each of the bindings will be executed, in order.
  414. By default, a class binding will be executed first, followed
  415. by a binding for the widget, a binding for its toplevel, and
  416. an <STRONG>all</STRONG> binding.
  417. The <STRONG>bindtags</STRONG> method may be used to change this order for
  418. a particular window or to associate additional binding tags with
  419. the window.</P>
  420. <P><STRONG>return</STRONG> and <STRONG>Tk->break</STRONG> may be used inside a
  421. callback to control the processing of matching callbacks.
  422. If <STRONG>return</STRONG> is invoked, then the current callback
  423. is terminated but Tk will continue processing callbacks
  424. associated with other <EM>tag</EM>'s.
  425. If <STRONG>Tk->break</STRONG> is invoked within a callback,
  426. then that callback terminates and no other callbacks will be invoked
  427. for the event.
  428. (<STRONG>Tk->break</STRONG> is implemented via perl's <STRONG>die</STRONG> with a special value
  429. which is ``caught'' by the perl/Tk ``glue'' code.)</P>
  430. <P>If more than one binding matches a particular event and they
  431. have the same <EM>tag</EM>, then the most specific binding
  432. is chosen and its callback is evaluated.
  433. The following tests are applied, in order, to determine which of
  434. several matching sequences is more specific:
  435. (a) an event pattern that specifies a specific button or key is more specific
  436. than one that doesn't;
  437. (b) a longer sequence (in terms of number
  438. of events matched) is more specific than a shorter sequence;
  439. (c) if the modifiers specified in one pattern are a subset of the
  440. modifiers in another pattern, then the pattern with more modifiers
  441. is more specific.
  442. (d) a virtual event whose physical pattern matches the sequence is less
  443. specific than the same physical pattern that is not associated with a
  444. virtual event.
  445. (e) given a sequence that matches two or more virtual events, one
  446. of the virtual events will be chosen, but the order is undefined.</P>
  447. <P>If the matching sequences contain more than one event, then tests
  448. (c)-(e) are applied in order from the most recent event to the least recent
  449. event in the sequences.  If these tests fail to determine a winner, then the
  450. most recently registered sequence is the winner.</P>
  451. <P>If there are two (or more) virtual events that are both triggered by the
  452. same sequence, and both of those virtual events are bound to the same window
  453. tag, then only one of the virtual events will be triggered, and it will
  454. be picked at random:</P>
  455. <PRE>
  456.  $widget->eventAdd('<<Paste>>' => '<Control-y>');
  457.  $widget->eventAdd('<<Paste>>' => '<Button-2>');
  458.  $widget->eventAdd <<Scroll>>' => '<Button-2>');
  459.  $widget->bind('Tk::Entry','<<Paste>>',sub { print 'Paste'});
  460.  $widget->bind('Tk::Entry','<<Scroll>>', sub {print 'Scroll'});</PRE>
  461. <P>If the user types Control-y, the <STRONG><<Paste>></STRONG> binding
  462. will be invoked, but if the user presses button 2 then one of
  463. either the <STRONG><<Paste>></STRONG> or the <STRONG><<Scroll>></STRONG> bindings will
  464. be invoked, but exactly which one gets invoked is undefined.</P>
  465. <P>If an X event does not match any of the existing bindings, then the
  466. event is ignored.
  467. An unbound event is not considered to be an error.</P>
  468. <P>
  469. <HR>
  470. <H1><A NAME="multievent sequences and ignored events">MULTI-EVENT SEQUENCES AND IGNORED EVENTS</A></H1>
  471. <P>When a <EM>sequence</EM> specified in a <STRONG>bind</STRONG> method contains
  472. more than one event pattern, then its callback is executed whenever
  473. the recent events (leading up to and including the current event)
  474. match the given sequence.  This means, for example, that if button 1 is
  475. clicked repeatedly the sequence <STRONG><Double-ButtonPress-1></STRONG> will match
  476. each button press but the first.
  477. If extraneous events that would prevent a match occur in the middle
  478. of an event sequence then the extraneous events are
  479. ignored unless they are <STRONG>KeyPress</STRONG> or <STRONG>ButtonPress</STRONG> events.
  480. For example, <STRONG><Double-ButtonPress-1></STRONG> will match a sequence of
  481. presses of button 1, even though there will be <STRONG>ButtonRelease</STRONG>
  482. events (and possibly <STRONG>Motion</STRONG> events) between the
  483. <STRONG>ButtonPress</STRONG> events.
  484. Furthermore, a <STRONG>KeyPress</STRONG> event may be preceded by any number
  485. of other <STRONG>KeyPress</STRONG> events for modifier keys without the
  486. modifier keys preventing a match.
  487. For example, the event sequence <STRONG>aB</STRONG> will match a press of the
  488. <STRONG>a</STRONG> key, a release of the <STRONG>a</STRONG> key, a press of the <STRONG>Shift</STRONG>
  489. key, and a press of the <STRONG>b</STRONG> key:  the press of <STRONG>Shift</STRONG> is
  490. ignored because it is a modifier key.
  491. Finally, if several <STRONG>Motion</STRONG> events occur in a row, only
  492. the last one is used for purposes of matching binding sequences.</P>
  493. <P>
  494. <HR>
  495. <H1><A NAME="errors">ERRORS</A></H1>
  496. <P>If an error occurs in executing the callback for a binding then the
  497. <STRONG>Tk::Error</STRONG> mechanism is used to report the error.
  498. The <STRONG>Tk::Error</STRONG> mechanism will be executed at same call level,
  499. and associated with the same <STRONG>MainWindow</STRONG> as
  500. as the callback was invoked.</P>
  501. <P>
  502. <HR>
  503. <H1><A NAME="caveats">CAVEATS</A></H1>
  504. <P>Note that for the <STRONG>Canvas</STRONG> widget, the call to <STRONG>bind</STRONG> has to be
  505. fully qualified. This is because there is already a bind method for
  506. the <STRONG>Canvas</STRONG> widget, which binds individual canvas tags.</P>
  507. <P>    <EM>$canvas</EM>-><STRONG>Tk::bind</STRONG></P>
  508. <P>
  509. <HR>
  510. <H1><A NAME="see also">SEE ALSO</A></H1>
  511. <P><A HREF="../../../site/lib/Tk/Error.html">Tk::Error</A>
  512. <A HREF="../../../site/lib/Tk/callbacks.html">Tk::callbacks</A>
  513. <A HREF="../../../site/lib/Tk/bindtags.html">Tk::bindtags</A></P>
  514. <P>
  515. <HR>
  516. <H1><A NAME="keywords">KEYWORDS</A></H1>
  517. <P>Event, binding</P>
  518. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  519. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  520. <STRONG><P CLASS=block> Tk::bind - Arrange for X events to invoke callbacks</P></STRONG>
  521. </TD></TR>
  522. </TABLE>
  523.  
  524. </BODY>
  525.  
  526. </HTML>
  527.