1mNAME0m
       bind - Arrange for X events to invoke Tcl scripts

1mSYNOPSIS0m
       1mbind 4m22mtag0m

       1mbind 4m22mtag24m 4msequence0m

       1mbind 4m22mtag24m 4msequence24m 4mscript0m

       1mbind 4m22mtag24m 4msequence24m 1m+4m22mscript0m


1mINTRODUCTION0m
       The  1mbind  22mcommand  associates Tcl scripts with X events.  If all three
       arguments are specified, 1mbind 22mwill arrange for 4mscript24m (a Tcl script) to
       be  evaluated whenever the event(s) given by 4msequence24m occur in the win-
       dow(s) identified by 4mtag24m.  If 4mscript24m is prefixed with a ``+'', then  it
       is  appended  to  any  existing binding for 4msequence24m;  otherwise 4mscript0m
       replaces any existing binding.  If 4mscript24m is an empty string  then  the
       current  binding  for  4msequence24m is destroyed, leaving 4msequence24m unbound.
       In all of the cases where a 4mscript24m argument is provided,  1mbind  22mreturns
       an empty string.

       If  4msequence24m  is  specified without a 4mscript24m, then the script currently
       bound to 4msequence24m is returned, or an empty string is returned if  there
       is  no  binding for 4msequence24m.  If neither 4msequence24m nor 4mscript24m is speci-
       fied, then the return value is  a  list  whose  elements  are  all  the
       sequences for which there exist bindings for 4mtag24m.

       The 4mtag24m argument determines which window(s) the binding applies to.  If
       4mtag24m begins with a dot, as in 1m.a.b.c22m, then it must be the path name  for
       a  window; otherwise it may be an arbitrary string.  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 1mbind-0m
       1mtags 22mcommand may be used to assign an arbitrary set of binding tags  to
       a window, the default binding tags provide the following behavior:

              If  a  tag is the name of an internal window the binding applies
              to that window.

              If the tag is the name of a toplevel window the binding  applies
              to the toplevel window and all its internal windows.

              If  the  tag  is the name of a class of widgets, such as 1mButton22m,
              the binding applies to all widgets in that class;

              If 4mtag24m has the value 1mall22m, the binding applies to all windows  in
              the application.


1mEVENT PATTERNS0m
       The  4msequence24m  argument  specifies a sequence of one or more event pat-
       terns, with optional white space between the patterns.  Each event pat-
       tern  may take one of three forms.  In the simplest case it is a single
       printing ASCII character, such as 1ma 22mor 1m[22m.  The character may not  be  a
       space  character  or  the  character 1m<22m.  This form of pattern matches a
       1mKeyPress 22mevent for the particular character.  The second form  of  pat-
       tern is longer but more general.  It has the following syntax:
              1m<4m22mmodifier-modifier-type-detail24m1m>0m
       The  entire  event pattern is surrounded by angle brackets.  Inside the
       angle brackets are zero or more modifiers, an event type, and an  extra
       piece  of  information  (4mdetail24m)  identifying  a  particular  button or
       keysym.  Any of the fields may be omitted, as long as at least  one  of
       4mtype24m  and  4mdetail24m  is  present.   The fields must be separated by white
       space or dashes.

       The third form of pattern is used to specify a user-defined, named vir-
       tual event.  It has the following syntax:
              1m<<4m22mname24m1m>>0m
       The  entire  virtual event pattern is surrounded by double angle brack-
       ets.  Inside the angle brackets is the user-defined name of the virtual
       event.  Modifiers, such as 1mShift 22mor 1mControl22m, 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.

1mMODIFIERS0m
       Modifiers consist of any of the following values:

              1mControl                 Mod2, M20m
              1mShift                   Mod3, M30m
              1mLock                    Mod4, M40m
              1mButton1, B1             Mod5, M50m
              1mButton2, B2             Meta, M0m
              1mButton3, B3             Alt0m
              1mButton4, B4             Double0m
              1mButton5, B5             Triple0m
              1mMod1, M1                Quadruple0m

       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, 1mButton1 22mrequires 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  bind-
       ing.   For  example, if button 1 is pressed while the shift and control
       keys are down, the pattern 1m<Control-Button-1> 22mwill match the event, but
       1m<Mod1-Button-1> 22mwill not.  If no modifiers are specified, then any com-
       bination of modifiers may be present in the event.

       1mMeta 22mand 1mM 22mrefer to whichever of the 1mM1 22mthrough 1mM5 22mmodifiers is associ-
       ated  with the meta key(s) on the keyboard (keysyms 1mMeta_R 22mand 1mMeta_L22m).
       If there are no meta keys, or if they are not associated with any modi-
       fiers,  then  1mMeta 22mand 1mM 22mwill not match any events.  Similarly, the 1mAlt0m
       modifier refers to whichever modifier is associated with the alt key(s)
       on the keyboard (keysyms 1mAlt_L 22mand 1mAlt_R22m).

       The 1mDouble22m, 1mTriple 22mand 1mQuadruple 22mmodifiers are a convenience for speci-
       fying double mouse clicks and other repeated events. They cause a  par-
       ticular  event pattern to be repeated 2, 3 or 4 times, and also place a
       time and space requirement on the sequence: for a sequence of events to
       match  a  1mDouble22m,  1mTriple  22mor 1mQuadruple 22mpattern, all of the events must
       occur close together in time and without substantial  mouse  motion  in
       between.    For  example,  1m<Double-Button-1>  22mis  equivalent  to  1m<But-0m
       1mton-1><Button-1> 22mwith the extra time and space requirement.


1mEVENT TYPES0m
       The 4mtype24m field may be any of the standard X event  types,  with  a  few
       extra  abbreviations.   The  4mtype24m  field will also accept a couple non-
       standard X event types that were added to better support the  Macintosh
       and  Windows  platforms.  Below is a list of all the valid types; where
       two names appear together, they are synonyms.

              1mActivate            Enter              Map0m
              1mButtonPress, Button Expose             Motion0m
              1mButtonRelease       FocusIn            MouseWheel0m
              1mCirculate           FocusOut           Property0m
              1mColormap            Gravity            Reparent0m
              1mConfigure           KeyPress, Key      Unmap0m
              1mDeactivate          KeyRelease         Visibility0m
              1mDestroy             Leave0m


       Most of the above events have the same fields and behaviors  as  events
       in  the X Windowing system.  You can find more detailed descriptions of
       these events in any X window programming book.  A couple of the  events
       are  extensions to the X event system to support features unique to the
       Macintosh and Windows platforms.  We provide a little  more  detail  on
       these events here.  These include:

       1mActivate0m

       1mDeactivate0m
            These  two  events are sent to every sub-window of a toplevel when
            they change state.  In addition to the focus Window, the Macintosh
            platform  and  Windows platforms have a notion of an active window
            (which often has but is not required to have the focus).   On  the
            Macintosh,  widgets  in the active window have a different appear-
            ance than widgets in deactive windows.  The 1mActivate 22mevent is sent
            to  all  the  sub-windows in a toplevel when it changes from being
            deactive to active.  Likewise, the 1mDeactive 22mevent is sent when the
            window's state changes from active to deactive.  There are no use-
            ful percent substitutions you would make  when  binding  to  these
            events.

       1mMouseWheel0m
            Some  mice  on the Windows platform support a mouse wheel which is
            used for scrolling documents without  using  the  scrollbars.   By
            rolling the wheel, the system will generate 1mMouseWheel 22mevents that
            the application can use to scroll.  Like 1mKey 22mevents the  event  is
            always  routed  to  the  window that currently has focus. When the
            event is received you can use the 1m%D 22msubstitution to get the 4mdelta0m
            field  for  the  event which is a integer value of motion that the
            mouse wheel has moved.  The smallest value for  which  the  system
            will  report  is  defined  by the OS.  On Windows 95 & 98 machines
            this value is at least 120 before it is reported.  However, higher
            resolution  devices  may  be available in the future.  The sign of
            the value determines which direction your  widget  should  scroll.
            Positive values should scroll up and negative values should scroll
            down.

       The last part of a long event specification is 4mdetail24m.  In the case  of
       a  1mButtonPress  22mor  1mButtonRelease  22mevent,  it is the number of a button
       (1-5).  If a button number is given, then only an event on that partic-
       ular button will match;  if no button number is given, then an event on
       any button will match.  Note:  giving a specific button number is  dif-
       ferent  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 4mtype24m may be omitted:  if will
       default  to  1mButtonPress22m.  For example, the specifier 1m<1> 22mis equivalent
       to 1m<ButtonPress-1>22m.

       If the event type is 1mKeyPress 22mor 1mKeyRelease22m, then 4mdetail24m may be  speci-
       fied  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 neces-
       sary, you can use the 1m%K 22mnotation described  below  to  print  out  the
       keysym  name  for  a particular key.  If a keysym 4mdetail24m is given, then
       the 4mtype24m field may be omitted;  it will default to 1mKeyPress22m.  For exam-
       ple, 1m<Control-comma> 22mis equivalent to 1m<Control-KeyPress-comma>22m.


1mBINDING SCRIPTS AND SUBSTITUTIONS0m
       The  4mscript24m  argument  to  1mbind 22mis a Tcl script, which will be executed
       whenever the given event sequence occurs.  4mCommand24m will be executed  in
       the same interpreter that the 1mbind 22mcommand was executed in, and it will
       run at global level (only global variables  will  be  accessible).   If
       4mscript24m  contains any 1m% 22mcharacters, then the script will not be executed
       directly.  Instead, a new script will be generated by replacing each 1m%22m,
       and  the  character  following  it,  with  information from the current
       event.  The replacement depends on the character following  the  1m%22m,  as
       defined in the list below.  Unless otherwise indicated, the replacement
       string is the decimal value of the given field from the current  event.
       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.

       1m%%   22mReplaced with a single percent.

       1m%#   22mThe number of the last client request processed by the server (the
            4mserial24m field from the event).  Valid for all event types.

       1m%a   22mThe 4mabove24m field from the event, formatted as a hexadecimal number.
            Valid only for 1mConfigure 22mevents.

       1m%b   22mThe number of the button that was pressed or released.  Valid only
            for 1mButtonPress 22mand 1mButtonRelease 22mevents.

       1m%c   22mThe 4mcount24m field from the event.  Valid only for 1mExpose 22mevents.

       1m%d   22mThe 4mdetail24m field from the event.  The 1m%d 22mis replaced by  a  string
            identifying  the  detail.  For 1mEnter22m, 1mLeave22m, 1mFocusIn22m, and 1mFocusOut0m
            events, the string will be one of the following:

                   1mNotifyAncestor          NotifyNonlinearVirtual0m
                   1mNotifyDetailNone        NotifyPointer0m
                   1mNotifyInferior          NotifyPointerRoot0m
                   1mNotifyNonlinear         NotifyVirtual0m

            For events other than these, the substituted string is  undefined.

       1m%f   22mThe 4mfocus24m field from the event (1m0 22mor 1m122m).  Valid only for 1mEnter 22mand
            1mLeave 22mevents.

       1m%h   22mThe 4mheight24m field from the event.   Valid  for  the  1mConfigure  22mand
            1mExpose 22mevents.

       1m%k   22mThe  4mkeycode24m  field  from  the event.  Valid only for 1mKeyPress 22mand
            1mKeyRelease 22mevents.

       1m%m   22mThe 4mmode24m field from the event.  The substituted string is  one  of
            1mNotifyNormal22m,  1mNotifyGrab22m,  1mNotifyUngrab22m,  or  1mNotifyWhileGrabbed22m.
            Valid only for 1mEnter22m, 1mFocusIn22m, 1mFocusOut22m, and 1mLeave 22mevents.

       1m%o   22mThe 4moverride_redirect24m field from the event.  Valid only  for  1mMap22m,
            1mReparent22m, and 1mConfigure 22mevents.

       1m%p   22mThe  4mplace24m field from the event, substituted as one of the strings
            1mPlaceOnTop 22mor 1mPlaceOnBottom22m.  Valid only for 1mCirculate 22mevents.

       1m%s   22mThe 4mstate24m field from the event.  For  1mButtonPress22m,  1mButtonRelease22m,
            1mEnter22m,  1mKeyPress22m,  1mKeyRelease22m, 1mLeave22m, and 1mMotion 22mevents, a decimal
            string is substituted.  For 1mVisibility22m, one of the  strings  1mVisi-0m
            1mbilityUnobscured22m,  1mVisibilityPartiallyObscured22m, and 1mVisibilityFul-0m
            1mlyObscured 22mis substituted.

       1m%t   22mThe 4mtime24m field from the event.  Valid only for events that contain
            a 4mtime24m field.

       1m%w   22mThe  4mwidth24m  field  from  the  event.  Valid only for 1mConfigure 22mand
            1mExpose 22mevents.

       1m%x   22mThe 4mx24m field from the event.  Valid only for events containing an 4mx0m
            field.

       1m%y   22mThe  4my24m field from the event.  Valid only for events containing a 4my0m
            field.

       1m%A   22mSubstitutes 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).  1mXLookupString 22mdoes all the work
            of  translating  from the event to an ASCII character.  Valid only
            for 1mKeyPress 22mand 1mKeyRelease 22mevents.

       1m%B   22mThe 4mborder_width24m field from the event.  Valid only  for  1mConfigure0m
            events.

       1m%D   22mThis  reports  the  4mdelta24m  value of a 1mMouseWheel 22mevent.  The 4mdelta0m
            value represents the rotation  units  the  mouse  wheel  has  been
            moved.   On  Windows  95  &  98 systems the smallest value for the
            delta is 120.  Future systems may support higher resolution values
            for the delta.  The sign of the value represents the direction the
            mouse wheel was scrolled.

       1m%E   22mThe 4msend_event24m field from the event.  Valid for all event types.

       1m%K   22mThe keysym corresponding to the event, substituted  as  a  textual
            string.  Valid only for 1mKeyPress 22mand 1mKeyRelease 22mevents.

       1m%N   22mThe  keysym  corresponding  to the event, substituted as a decimal
            number.  Valid only for 1mKeyPress 22mand 1mKeyRelease 22mevents.

       1m%R   22mThe 4mroot24m window identifier from the event.  Valid only for  events
            containing a 4mroot24m field.

       1m%S   22mThe  4msubwindow24m  window  identifier  from the event, formatted as a
            hexadecimal number.  Valid only for events containing a  4msubwindow0m
            field.

       1m%T   22mThe 4mtype24m field from the event.  Valid for all event types.

       1m%W   22mThe  path  name of the window to which the event was reported (the
            4mwindow24m field from the event).  Valid for all event types.

       1m%X   22mThe 4mx_root24m 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 1mButtonPress22m,  1mBut-0m
            1mtonRelease22m, 1mKeyPress22m, 1mKeyRelease22m, and 1mMotion 22mevents.

       1m%Y   22mThe 4my_root24m 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 1mButtonPress22m, 1mBut-0m
            1mtonRelease22m, 1mKeyPress22m, 1mKeyRelease22m, and 1mMotion 22mevents.

       The replacement string for a %-replacement is formatted as a proper Tcl
       list  element.  This means that it will be surrounded with braces if it
       contains spaces, or special characters such as 1m$ 22mand 1m{ 22mmay be  preceded
       by backslashes.  This guarantees that the string will be passed through
       the Tcl parser when the binding script is evaluated.  Most replacements
       are  numbers or well-defined strings such as 1mAbove22m;  for these replace-
       ments no special formatting is ever necessary.  The  most  common  case
       where  reformatting occurs is for the 1m%A 22msubstitution.  For example, if
       4mscript24m is
              1minsert %A0m
       and the character typed is an open  square  bracket,  then  the  script
       actually executed will be
              1minsert \[0m
       This  will  cause the 1minsert 22mto receive the original replacement string
       (open square bracket) as its first argument.  If  the  extra  backslash
       hadn't  been  added,  Tcl  would not have been able to parse the script
       correctly.


1mMULTIPLE MATCHES0m
       It is possible for several bindings to match a given X event.   If  the
       bindings are associated with different 4mtag24m's, then each of the bindings
       will be executed, in order.  By default, a binding for the widget  will
       be  executed  first,  followed  by  a  class binding, a binding for its
       toplevel, and an 1mall 22mbinding.  The 1mbindtags  22mcommand  may  be  used  to
       change  this  order  for a particular window or to associate additional
       binding tags with the window.

       The 1mcontinue 22mand 1mbreak 22mcommands may be used inside a binding script  to
       control  the  processing  of matching scripts.  If 1mcontinue 22mis invoked,
       then the current binding script is terminated but Tk will continue pro-
       cessing binding scripts associated with other 4mtag24m's.  If the 1mbreak 22mcom-
       mand is invoked within a binding script, then  that  script  terminates
       and no other scripts will be invoked for the event.

       If  more  than one binding matches a particular event and they have the
       same 4mtag24m, then the most specific binding is chosen and  its  script  is
       evaluated.   The  following  tests  are applied, in order, to determine
       which of several matching sequences is more specific: (a) an event pat-
       tern  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  pat-
       tern,  then  the  pattern  with more modifiers is more specific.  (d) a
       virtual event whose physical pattern matches the sequence is less  spe-
       cific than the same physical pattern that is not associated with a vir-
       tual 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.

       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 win-
       ner, then the most recently registered sequence is the winner.

       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:
              event add <<Paste>> <Control-y>
              event add <<Paste>> <Button-2>
              event add <<Scroll>> <Button-2>
              bind Entry <<Paste>> {puts Paste}
              bind Entry <<Scroll>> {puts Scroll}
       If the user types Control-y, the 1m<<Paste>> 22mbinding will be invoked, but
       if  the  user  presses button 2 then one of either the 1m<<Paste>> 22mor the
       1m<<Scroll>> 22mbindings will be invoked, but exactly which one gets invoked
       is undefined.

       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.


1mMULTI-EVENT SEQUENCES AND IGNORED EVENTS0m
       When a 4msequence24m specified in a 1mbind  22mcommand  contains  more  than  one
       event  pattern,  then its script 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 repeat-
       edly the sequence 1m<Double-ButtonPress-1> 22mwill 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 1mKeyPress 22mor 1mButtonPress 22mevents.  For example,
       1m<Double-ButtonPress-1> 22mwill match a sequence of presses  of  button  1,
       even  though  there  will  be 1mButtonRelease 22mevents (and possibly 1mMotion0m
       events) between the 1mButtonPress 22mevents.  Furthermore, a 1mKeyPress  22mevent
       may  be  preceded  by  any number of other 1mKeyPress 22mevents for modifier
       keys without the modifier keys preventing a match.   For  example,  the
       event  sequence  1maB 22mwill match a press of the 1ma 22mkey, a release of the 1ma0m
       key, a press of the 1mShift 22mkey, and a press of the 1mb 22mkey:  the press  of
       1mShift  22mis  ignored  because  it is a modifier key.  Finally, if several
       1mMotion 22mevents occur in a row, only the last one is used for purposes of
       matching binding sequences.


1mERRORS0m
       If an error occurs in executing the script for a binding then the 1mbger-0m
       1mror 22mmechanism is used to report the error.  The 1mbgerror 22mcommand will be
       executed at global level (outside the context of any Tcl procedure).


1mSEE ALSO0m
       bgerror, keysyms


1mKEYWORDS0m
