home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Tk::bind - Arrange for X events to invoke callbacks</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tk::bind - Arrange for X events to invoke callbacks</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#event patterns">EVENT PATTERNS</A></LI>
- <LI><A HREF="#modifiers">MODIFIERS</A></LI>
- <LI><A HREF="#event types">EVENT TYPES</A></LI>
- <LI><A HREF="#binding callbacks and substitutions">BINDING CALLBACKS AND SUBSTITUTIONS</A></LI>
- <LI><A HREF="#multiple matches">MULTIPLE MATCHES</A></LI>
- <LI><A HREF="#multievent sequences and ignored events">MULTI-EVENT SEQUENCES AND IGNORED EVENTS</A></LI>
- <LI><A HREF="#errors">ERRORS</A></LI>
- <LI><A HREF="#caveats">CAVEATS</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#keywords">KEYWORDS</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Tk::bind - Arrange for X events to invoke callbacks</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <P>Retrieve bindings:</P>
- <P> <EM>$widget</EM>-><STRONG>bind</STRONG></P>
- <P> <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>tag</EM>)</P>
- <P> <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>sequence</EM>)</P>
- <P> <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>tag</EM>,<EM>sequence</EM>)</P>
- <P>Associate and destroy bindings:</P>
- <P> <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>sequence</EM>,<EM>callback</EM>)</P>
- <P> <EM>$widget</EM>-><STRONG>bind</STRONG>(<EM>tag</EM>,<EM>sequence</EM>,<EM>callback</EM>)</P>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>The <STRONG>bind</STRONG> method associates callbacks with X events.
- If <EM>callback</EM> is specified, <STRONG>bind</STRONG> will
- arrange for <EM>callback</EM> to be evaluated whenever
- the <CODE>event(s)</CODE> given by <EM>sequence</EM> occur in the <CODE>window(s)</CODE>
- identified by <EM>$widget</EM> or <EM>tag</EM>.
- If <EM>callback</EM> is an empty string then the current binding for
- <EM>sequence</EM> is destroyed, leaving <EM>sequence</EM> unbound.
- In all of the cases where a <EM>callback</EM> argument is provided,
- <STRONG>bind</STRONG> returns an empty string.</P>
- <P>If <EM>sequence</EM> is specified without a <EM>callback</EM>, then the
- callback currently bound to <EM>sequence</EM> is returned, or
- <STRONG>undef</STRONG> is returned if there is no binding for <EM>sequence</EM>.
- If neither <EM>sequence</EM> nor <EM>callback</EM> is specified, then the
- return value is a list whose elements are all the sequences
- for which there exist bindings for <EM>tag</EM>.</P>
- <P>If no <EM>tag</EM> is specified then the <STRONG>bind</STRONG> refers to <EM>$widget</EM>.
- If <EM>tag</EM> is specified then it is typically a class name and the <STRONG>bind</STRONG>
- refers to all instances of the class on the <STRONG>MainWindow</STRONG> associated
- with <EM>$widget</EM>. (It is possible for <EM>tag</EM> to be another ``widget object''
- but this practice is deprecated.) Perl's <STRONG>ref</STRONG>(<EM>$object</EM>) can be used
- to get the class name of any object.
- Each window has an associated list of tags, and a binding applies
- to a particular window if its tag is among those specified for
- the window.
- Although the <STRONG>bindtags</STRONG> method may be used to assign an
- arbitrary set of binding tags to a window, the default binding
- tags provide the following behavior:</P>
- <P>If a tag is the name of an internal window the binding applies
- to that window.</P>
- <P>If the tag is the name of a toplevel window the binding applies
- to the toplevel window and all its internal windows.</P>
- <P>If the tag is the name of a class of widgets, such as <STRONG>Tk::Button</STRONG>,
- the binding applies to all widgets in that class;</P>
- <P>If <EM>tag</EM> has the value <STRONG>all</STRONG>,
- the binding applies to all windows descended from the MainWindow
- of the application.</P>
- <P>
- <HR>
- <H1><A NAME="event patterns">EVENT PATTERNS</A></H1>
- <P>The <EM>sequence</EM> argument specifies a sequence of one or more
- event patterns, with optional white space between the patterns. Each
- event pattern has the following syntax:</P>
- <P> '<modifier-modifier-type-detail>'</P>
- <P>The entire event pattern is surrounded by angle brackets, and normally
- needs to be quoted, as angle brackets are special to perl.
- Inside the angle brackets are zero or more modifiers, an event
- type, and an extra piece of information (<EM>detail</EM>) identifying
- a particular button or keysym. Any of the fields may be omitted,
- as long as at least one of <EM>type</EM> and <EM>detail</EM> is present.
- The fields must be separated by white space or dashes.</P>
- <P>A second form of pattern is used to specify a user-defined, named virtual
- event; see <A HREF="../../../site/lib/Tk/event.html">the Tk::event manpage</A> for details. It has the following syntax:</P>
- <P> <<name>></P>
- <P>The entire virtual event pattern is surrounded by double angle brackets.
- Inside the angle brackets is the user-defined name of the virtual event.
- Modifiers, such as <STRONG>Shift</STRONG> or <STRONG>Control</STRONG>, may not be combined with a
- virtual event to modify it. Bindings on a virtual event may be created
- before the virtual event is defined, and if the definition of a virtual
- event changes dynamically, all windows bound to that virtual event will
- respond immediately to the new definition.</P>
- <P>
- <HR>
- <H1><A NAME="modifiers">MODIFIERS</A></H1>
- <P>Modifiers consist of any of the following values:</P>
- <PRE>
- Control Mod2, M2
- Shift Mod3, M3
- Lock Mod4, M4
- Button1, B1 Mod5, M5
- Button2, B2 Meta, M
- Button3, B3 Alt
- Button4, B4 Double
- Button5, B5 Triple
- Mod1, M1</PRE>
- <P>Where more than one value is listed, separated by commas, the values
- are equivalent.
- Most of the modifiers have the obvious X meanings.
- For example, <STRONG>Button1</STRONG> requires that
- button 1 be depressed when the event occurs.
- For a binding to match a given event, the modifiers in the event
- must include all of those specified in the event pattern.
- An event may also contain additional modifiers not specified in
- the binding.
- For example, if button 1 is pressed while the shift and control keys
- are down, the pattern <STRONG><Control-Button-1></STRONG> will match
- the event, but <STRONG><Mod1-Button-1></STRONG> will not.
- If no modifiers are specified, then any combination of modifiers may
- be present in the event.</P>
- <P><STRONG>Meta</STRONG> and <STRONG>M</STRONG> refer to whichever of the
- <STRONG>M1</STRONG> through <STRONG>M5</STRONG> modifiers is associated with the meta
- <CODE>key(s)</CODE> on the keyboard (keysyms <STRONG>Meta_R</STRONG> and <STRONG>Meta_L</STRONG>).
- If there are no meta keys, or if they are not associated with any
- modifiers, then <STRONG>Meta</STRONG> and <STRONG>M</STRONG> will not match any events.
- Similarly, the <STRONG>Alt</STRONG> modifier refers to whichever modifier
- is associated with the alt <CODE>key(s)</CODE> on the keyboard (keysyms
- <STRONG>Alt_L</STRONG> and <STRONG>Alt_R</STRONG>).</P>
- <P>The <STRONG>Double</STRONG> and <STRONG>Triple</STRONG> modifiers are a convenience
- for specifying double mouse clicks and other repeated
- events. They cause a particular event pattern to be
- repeated 2 or 3 times, and also place a time and space requirement
- on the sequence: for a sequence of events to match a <STRONG>Double</STRONG>
- or <STRONG>Triple</STRONG> pattern, all of the events must occur close together
- in time and without substantial mouse motion in between.
- For example, <STRONG><Double-Button-1></STRONG>
- is equivalent to <STRONG><Button-1><Button-1></STRONG> with the extra
- time and space requirement.</P>
- <P>
- <HR>
- <H1><A NAME="event types">EVENT TYPES</A></H1>
- <P>The <EM>type</EM> field may be any of the standard X event types, with a
- few extra abbreviations. Below is a list of all the valid types;
- where two names appear together, they are synonyms.</P>
- <PRE>
- ButtonPress, Button Expose Map
- ButtonRelease FocusIn Motion
- Circulate FocusOut Property
- Colormap Gravity Reparent
- Configure KeyPress, Key Unmap
- Destroy KeyRelease Visibility
- Enter Leave Activate
- Deactivate</PRE>
- <P>The last part of a long event specification is <EM>detail</EM>. In the
- case of a <STRONG>ButtonPress</STRONG> or <STRONG>ButtonRelease</STRONG> event, it is the
- number of a button (1-5). If a button number is given, then only an
- event on that particular button will match; if no button number is
- given, then an event on any button will match. Note: giving a
- specific button number is different than specifying a button modifier;
- in the first case, it refers to a button being pressed or released,
- while in the second it refers to some other button that is already
- depressed when the matching event occurs. If a button
- number is given then <EM>type</EM> may be omitted: if will default
- to <STRONG>ButtonPress</STRONG>. For example, the specifier <STRONG><1></STRONG>
- is equivalent to <STRONG><ButtonPress-1></STRONG>.</P>
- <P>If the event type is <STRONG>KeyPress</STRONG> or <STRONG>KeyRelease</STRONG>, then
- <EM>detail</EM> may be specified in the form of an X keysym. Keysyms
- are textual specifications for particular keys on the keyboard;
- they include all the alphanumeric ASCII characters (e.g. ``a'' is
- the keysym for the ASCII character ``a''), plus descriptions for
- non-alphanumeric characters (``comma'' is the keysym for the comma
- character), plus descriptions for all the non-ASCII keys on the
- keyboard (``Shift_L'' is the keysm for the left shift key, and
- ``F1'' is the keysym for the F1 function key, if it exists). The
- complete list of keysyms is not presented here; it is
- available in other X documentation and may vary from system to
- system.
- If necessary, you can use the <STRONG>'K'</STRONG> notation described below
- to print out the keysym name for a particular key.
- If a keysym <EM>detail</EM> is given, then the
- <EM>type</EM> field may be omitted; it will default to <STRONG>KeyPress</STRONG>.
- For example, <STRONG><Control-comma></STRONG> is equivalent to
- <STRONG><Control-KeyPress-comma></STRONG>.</P>
- <P>
- <HR>
- <H1><A NAME="binding callbacks and substitutions">BINDING CALLBACKS AND SUBSTITUTIONS</A></H1>
- <P>The <EM>callback</EM> argument to <STRONG>bind</STRONG> is a perl/Tk callback.
- which will be executed whenever the given event sequence occurs.
- (See <A HREF="../../../site/lib/Tk/callbacks.html">the Tk::callbacks manpage</A> for description of the possible forms.)
- <EM>Callback</EM> will be associated with the same <STRONG>MainWindow</STRONG>
- that is associated with the <EM>$widget</EM> that was used to invoke
- the <STRONG>bind</STRONG> method, and it will run as though called from <STRONG>MainLoop</STRONG>.
- If <EM>callback</EM> contains
- any <STRONG>Ev</STRONG>(<EM>%</EM>) calls, then each ``nested'' <STRONG>Ev</STRONG>(<EM>%</EM>)
- ``callback'' will be evaluated when the event occurs to form arguments
- to be passed to the main <EM>callback</EM>.
- The replacement
- depends on the character <EM>%</EM>, as defined in the
- list below. Unless otherwise indicated, the
- replacement string is the numeric (decimal) value of the given field from
- the current event. Perl/Tk has enhanced this mechanism slightly compared
- to the comparable Tcl/Tk mechanism. The enhancements are not yet all
- reflected in the list below.
- Some of the substitutions are only valid for
- certain types of events; if they are used for other types of events
- the value substituted is undefined (not the same as <STRONG>undef</STRONG>!).</P>
- <DL>
- <DT><STRONG><A NAME="item_%27%23%27"><STRONG>'#'</STRONG></A></STRONG><BR>
- <DD>
- The number of the last client request processed by the server
- (the <EM>serial</EM> field from the event). Valid for all event
- types.
- <P></P>
- <DT><STRONG><A NAME="item_%27a%27"><STRONG>'a'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>above</EM> field from the event,
- formatted as a hexadecimal number.
- Valid only for <STRONG>Configure</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27b%27"><STRONG>'b'</STRONG></A></STRONG><BR>
- <DD>
- The number of the button that was pressed or released. Valid only
- for <STRONG>ButtonPress</STRONG> and <STRONG>ButtonRelease</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27c%27"><STRONG>'c'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>count</EM> field from the event. Valid only for <STRONG>Expose</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27d%27"><STRONG>'d'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>detail</EM> field from the event. The <STRONG>'d'</STRONG> is replaced by
- a string identifying the detail. For <STRONG>Enter</STRONG>,
- <STRONG>Leave</STRONG>, <STRONG>FocusIn</STRONG>, and <STRONG>FocusOut</STRONG> events,
- the string will be one of the following:
- <PRE>
- NotifyAncestor NotifyNonlinearVirtual
- NotifyDetailNone NotifyPointer
- NotifyInferior NotifyPointerRoot
- NotifyNonlinear NotifyVirtual</PRE>
- <P>For events other than these, the substituted string is undefined.
- (Note that this is <EM>not</EM> the same as Detail part of sequence
- use to specify the event.)</P>
- <DT><STRONG><A NAME="item_%27f%27"><STRONG>'f'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>focus</EM> field from the event (<STRONG>0</STRONG> or <STRONG>1</STRONG>). Valid only
- for <STRONG>Enter</STRONG> and <STRONG>Leave</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27h%27"><STRONG>'h'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>height</EM> field from the event. Valid only for <STRONG>Configure</STRONG>,
- <STRONG>Expose</STRONG>, and <STRONG>GraphicsExpose</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27k%27"><STRONG>'k'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>keycode</EM> field from the event. Valid only for <STRONG>KeyPress</STRONG>
- and <STRONG>KeyRelease</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27m%27"><STRONG>'m'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>mode</EM> field from the event. The substituted string is one of
- <STRONG>NotifyNormal</STRONG>, <STRONG>NotifyGrab</STRONG>, <STRONG>NotifyUngrab</STRONG>, or
- <STRONG>NotifyWhileGrabbed</STRONG>. Valid only for <STRONG>EnterWindow</STRONG>,
- <STRONG>FocusIn</STRONG>, <STRONG>FocusOut</STRONG>, and <STRONG>LeaveWindow</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27o%27"><STRONG>'o'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>override_redirect</EM> field from the event. Valid only for
- <STRONG>Map</STRONG>, <STRONG>Reparent</STRONG>, and <STRONG>Configure</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27p%27"><STRONG>'p'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>place</EM> field from the event, substituted as one of the
- strings <STRONG>PlaceOnTop</STRONG> or <STRONG>PlaceOnBottom</STRONG>. Valid only
- for <STRONG>Circulate</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27s%27"><STRONG>'s'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>state</EM> field from the event. For <STRONG>ButtonPress</STRONG>,
- <STRONG>ButtonRelease</STRONG>, <STRONG>Enter</STRONG>, <STRONG>KeyPress</STRONG>, <STRONG>KeyRelease</STRONG>,
- <STRONG>Leave</STRONG>, and <STRONG>Motion</STRONG> events, a decimal string
- is substituted. For <STRONG>Visibility</STRONG>, one of the strings
- <STRONG>VisibilityUnobscured</STRONG>, <STRONG>VisibilityPartiallyObscured</STRONG>,
- and <STRONG>VisibilityFullyObscured</STRONG> is substituted.
- <P></P>
- <DT><STRONG><A NAME="item_%27t%27"><STRONG>'t'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>time</EM> field from the event. Valid only for events that
- contain a <EM>time</EM> field.
- <P></P>
- <DT><STRONG><A NAME="item_%27w%27"><STRONG>'w'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>width</EM> field from the event. Valid only for
- <STRONG>Configure</STRONG>, <STRONG>Expose</STRONG>, and <STRONG>GraphicsExpose</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27x%27"><STRONG>'x'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>x</EM> field from the event. Valid only for events containing
- an <EM>x</EM> field.
- <P></P>
- <DT><STRONG><A NAME="item_%27y%27"><STRONG>'y'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>y</EM> field from the event. Valid only for events containing
- a <EM>y</EM> field.
- <P></P>
- <DT><STRONG><A NAME="item_%27%40%27"><STRONG>'@'</STRONG></A></STRONG><BR>
- <DD>
- The string ``@<EM>x,y</EM>'' where <EM>x</EM> and <EM>y</EM> are as above.
- Valid only for events containing <EM>x</EM> and <EM>y</EM> fields.
- This format is used my methods of <STRONG>Tk::Text</STRONG> and similar widgets.
- <P></P>
- <DT><STRONG><A NAME="item_%27A%27"><STRONG>'A'</STRONG></A></STRONG><BR>
- <DD>
- Substitutes the ASCII character corresponding to the event, or
- the empty string if the event doesn't correspond to an ASCII character
- (e.g. the shift key was pressed). <STRONG>XLookupString</STRONG> does all the
- work of translating from the event to an ASCII character.
- Valid only for <STRONG>KeyPress</STRONG> and <STRONG>KeyRelease</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27B%27"><STRONG>'B'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>border_width</EM> field from the event. Valid only for
- <STRONG>Configure</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27E%27"><STRONG>'E'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>send_event</EM> field from the event. Valid for all event types.
- <P></P>
- <DT><STRONG><A NAME="item_%27K%27"><STRONG>'K'</STRONG></A></STRONG><BR>
- <DD>
- The keysym corresponding to the event, substituted as a textual
- string. Valid only for <STRONG>KeyPress</STRONG> and <STRONG>KeyRelease</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27N%27"><STRONG>'N'</STRONG></A></STRONG><BR>
- <DD>
- The keysym corresponding to the event, substituted as
- a decimal
- number. Valid only for <STRONG>KeyPress</STRONG> and <STRONG>KeyRelease</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27R%27"><STRONG>'R'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>root</EM> window identifier from the event. Valid only for
- events containing a <EM>root</EM> field.
- <P></P>
- <DT><STRONG><A NAME="item_%27S%27"><STRONG>'S'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>subwindow</EM> window identifier from the event,
- as an object if it is one otherwise as a hexadecimal number.
- Valid only for events containing a <EM>subwindow</EM> field.
- <P></P>
- <DT><STRONG><A NAME="item_%27T%27"><STRONG>'T'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>type</EM> field from the event. Valid for all event types.
- <P></P>
- <DT><STRONG><A NAME="item_%27W%27"><STRONG>'W'</STRONG></A></STRONG><BR>
- <DD>
- The window to which the event was reported (the
- $widget field from the event) - as an perl/Tk object.
- Valid for all event types.
- <P></P>
- <DT><STRONG><A NAME="item_%27X%27"><STRONG>'X'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>x_root</EM> field from the event.
- If a virtual-root window manager is being used then the substituted
- value is the corresponding x-coordinate in the virtual root.
- Valid only for
- <STRONG>ButtonPress</STRONG>, <STRONG>ButtonRelease</STRONG>, <STRONG>KeyPress</STRONG>, <STRONG>KeyRelease</STRONG>,
- and <STRONG>Motion</STRONG> events.
- <P></P>
- <DT><STRONG><A NAME="item_%27Y%27"><STRONG>'Y'</STRONG></A></STRONG><BR>
- <DD>
- The <EM>y_root</EM> field from the event.
- If a virtual-root window manager is being used then the substituted
- value is the corresponding y-coordinate in the virtual root.
- Valid only for
- <STRONG>ButtonPress</STRONG>, <STRONG>ButtonRelease</STRONG>, <STRONG>KeyPress</STRONG>, <STRONG>KeyRelease</STRONG>,
- and <STRONG>Motion</STRONG> events.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="multiple matches">MULTIPLE MATCHES</A></H1>
- <P>It is possible for several bindings to match a given X event.
- If the bindings are associated with different <EM>tag</EM>'s,
- then each of the bindings will be executed, in order.
- By default, a class binding will be executed first, followed
- by a binding for the widget, a binding for its toplevel, and
- an <STRONG>all</STRONG> binding.
- The <STRONG>bindtags</STRONG> method may be used to change this order for
- a particular window or to associate additional binding tags with
- the window.</P>
- <P><STRONG>return</STRONG> and <STRONG>Tk->break</STRONG> may be used inside a
- callback to control the processing of matching callbacks.
- If <STRONG>return</STRONG> is invoked, then the current callback
- is terminated but Tk will continue processing callbacks
- associated with other <EM>tag</EM>'s.
- If <STRONG>Tk->break</STRONG> is invoked within a callback,
- then that callback terminates and no other callbacks will be invoked
- for the event.
- (<STRONG>Tk->break</STRONG> is implemented via perl's <STRONG>die</STRONG> with a special value
- which is ``caught'' by the perl/Tk ``glue'' code.)</P>
- <P>If more than one binding matches a particular event and they
- have the same <EM>tag</EM>, then the most specific binding
- is chosen and its callback is evaluated.
- The following tests are applied, in order, to determine which of
- several matching sequences is more specific:
- (a) an event pattern that specifies a specific button or key is more specific
- than one that doesn't;
- (b) a longer sequence (in terms of number
- of events matched) is more specific than a shorter sequence;
- (c) if the modifiers specified in one pattern are a subset of the
- modifiers in another pattern, then the pattern with more modifiers
- is more specific.
- (d) a virtual event whose physical pattern matches the sequence is less
- specific than the same physical pattern that is not associated with a
- virtual event.
- (e) given a sequence that matches two or more virtual events, one
- of the virtual events will be chosen, but the order is undefined.</P>
- <P>If the matching sequences contain more than one event, then tests
- (c)-(e) are applied in order from the most recent event to the least recent
- event in the sequences. If these tests fail to determine a winner, then the
- most recently registered sequence is the winner.</P>
- <P>If there are two (or more) virtual events that are both triggered by the
- same sequence, and both of those virtual events are bound to the same window
- tag, then only one of the virtual events will be triggered, and it will
- be picked at random:</P>
- <PRE>
- $widget->eventAdd('<<Paste>>' => '<Control-y>');
- $widget->eventAdd('<<Paste>>' => '<Button-2>');
- $widget->eventAdd <<Scroll>>' => '<Button-2>');
- $widget->bind('Tk::Entry','<<Paste>>',sub { print 'Paste'});
- $widget->bind('Tk::Entry','<<Scroll>>', sub {print 'Scroll'});</PRE>
- <P>If the user types Control-y, the <STRONG><<Paste>></STRONG> binding
- will be invoked, but if the user presses button 2 then one of
- either the <STRONG><<Paste>></STRONG> or the <STRONG><<Scroll>></STRONG> bindings will
- be invoked, but exactly which one gets invoked is undefined.</P>
- <P>If an X event does not match any of the existing bindings, then the
- event is ignored.
- An unbound event is not considered to be an error.</P>
- <P>
- <HR>
- <H1><A NAME="multievent sequences and ignored events">MULTI-EVENT SEQUENCES AND IGNORED EVENTS</A></H1>
- <P>When a <EM>sequence</EM> specified in a <STRONG>bind</STRONG> method contains
- more than one event pattern, then its callback is executed whenever
- the recent events (leading up to and including the current event)
- match the given sequence. This means, for example, that if button 1 is
- clicked repeatedly the sequence <STRONG><Double-ButtonPress-1></STRONG> will match
- each button press but the first.
- If extraneous events that would prevent a match occur in the middle
- of an event sequence then the extraneous events are
- ignored unless they are <STRONG>KeyPress</STRONG> or <STRONG>ButtonPress</STRONG> events.
- For example, <STRONG><Double-ButtonPress-1></STRONG> will match a sequence of
- presses of button 1, even though there will be <STRONG>ButtonRelease</STRONG>
- events (and possibly <STRONG>Motion</STRONG> events) between the
- <STRONG>ButtonPress</STRONG> events.
- Furthermore, a <STRONG>KeyPress</STRONG> event may be preceded by any number
- of other <STRONG>KeyPress</STRONG> events for modifier keys without the
- modifier keys preventing a match.
- For example, the event sequence <STRONG>aB</STRONG> will match a press of the
- <STRONG>a</STRONG> key, a release of the <STRONG>a</STRONG> key, a press of the <STRONG>Shift</STRONG>
- key, and a press of the <STRONG>b</STRONG> key: the press of <STRONG>Shift</STRONG> is
- ignored because it is a modifier key.
- Finally, if several <STRONG>Motion</STRONG> events occur in a row, only
- the last one is used for purposes of matching binding sequences.</P>
- <P>
- <HR>
- <H1><A NAME="errors">ERRORS</A></H1>
- <P>If an error occurs in executing the callback for a binding then the
- <STRONG>Tk::Error</STRONG> mechanism is used to report the error.
- The <STRONG>Tk::Error</STRONG> mechanism will be executed at same call level,
- and associated with the same <STRONG>MainWindow</STRONG> as
- as the callback was invoked.</P>
- <P>
- <HR>
- <H1><A NAME="caveats">CAVEATS</A></H1>
- <P>Note that for the <STRONG>Canvas</STRONG> widget, the call to <STRONG>bind</STRONG> has to be
- fully qualified. This is because there is already a bind method for
- the <STRONG>Canvas</STRONG> widget, which binds individual canvas tags.</P>
- <P> <EM>$canvas</EM>-><STRONG>Tk::bind</STRONG></P>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><A HREF="../../../site/lib/Tk/Error.html">Tk::Error</A>
- <A HREF="../../../site/lib/Tk/callbacks.html">Tk::callbacks</A>
- <A HREF="../../../site/lib/Tk/bindtags.html">Tk::bindtags</A></P>
- <P>
- <HR>
- <H1><A NAME="keywords">KEYWORDS</A></H1>
- <P>Event, binding</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tk::bind - Arrange for X events to invoke callbacks</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-