bind.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:30k
- '"
- '" Copyright (c) 1990 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '" Copyright (c) 1998 by Scriptics Corporation.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: bind.n,v 1.7.2.2 2004/10/28 10:19:29 dkf Exp $
- '"
- .so man.macros
- .TH bind n 8.0 Tk "Tk Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- bind - Arrange for X events to invoke Tcl scripts
- .SH SYNOPSIS
- fBbindfI tagfR ?fIsequencefR? ?fB+fR??fIscriptfR?
- .BE
- .SH "INTRODUCTION"
- .PP
- The fBbindfR command associates Tcl scripts with X events.
- If all three arguments are specified, fBbindfR will
- arrange for fIscriptfR (a Tcl script) to be evaluated whenever
- the event(s) given by fIsequencefR occur in the window(s)
- identified by fItagfR.
- If fIscriptfR is prefixed with a ``+'', then it is appended to
- any existing binding for fIsequencefR; otherwise fIscriptfR replaces
- any existing binding.
- If fIscriptfR is an empty string then the current binding for
- fIsequencefR is destroyed, leaving fIsequencefR unbound.
- In all of the cases where a fIscriptfR argument is provided,
- fBbindfR returns an empty string.
- .PP
- If fIsequencefR is specified without a fIscriptfR, then the
- script currently bound to fIsequencefR is returned, or
- an empty string is returned if there is no binding for fIsequencefR.
- If neither fIsequencefR nor fIscriptfR is specified, then the
- return value is a list whose elements are all the sequences
- for which there exist bindings for fItagfR.
- .PP
- The fItagfR argument determines which window(s) the binding applies to.
- If fItagfR begins with a dot, as in fB.a.b.cfR, 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 fBbindtagsfR command may be used to assign an
- arbitrary set of binding tags to a window, the default binding
- tags provide the following behavior:
- .IP (bu 3
- If a tag is the name of an internal window the binding applies
- to that window.
- .IP (bu 3
- If the tag is the name of a toplevel window the binding applies
- to the toplevel window and all its internal windows.
- .IP (bu 3
- If the tag is the name of a class of widgets, such as fBButtonfR,
- the binding applies to all widgets in that class;
- .IP (bu 3
- If fItagfR has the value fBallfR,
- the binding applies to all windows in the application.
- .SH "EVENT PATTERNS"
- .PP
- The fIsequencefR argument specifies a sequence of one or more
- event patterns, with optional white space between the patterns. Each
- .VS
- event pattern may
- take one of three forms. In the simplest case it is a single
- .VE
- printing ASCII character, such as fBafR or fB[fR. The character
- may not be a space character or the character fB<fR. This form of
- pattern matches a fBKeyPressfR event for the particular
- character. The second form of pattern is longer but more general.
- It has the following syntax:
- .CS
- fB<fImodifier-modifier-type-detailfB>fR
- .CE
- 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 (fIdetailfR) identifying
- a particular button or keysym. Any of the fields may be omitted,
- as long as at least one of fItypefR and fIdetailfR is present.
- The fields must be separated by white space or dashes.
- .VS
- .PP
- The third form of pattern is used to specify a user-defined, named virtual
- event. It has the following syntax:
- .CS
- fB<<fInamefB>>fR
- .CE
- 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 fBShiftfR or fBControlfR, 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.
- .PP
- Some widgets (e.g. fBmenufR and fBtextfR) issue virtual events
- when their internal state is updated in some ways. Please see the
- manual page for each widget for details.
- .VE
- .SH "MODIFIERS"
- .PP
- Modifiers consist of any of the following values:
- .DS
- .ta 6c
- fBControlfR fBMod2, M2fR
- fBShiftfR fBMod3, M3fR
- fBLockfR fBMod4, M4fR
- fBButton1, B1fR fBMod5, M5fR
- fBButton2, B2fR fBMeta, MfR
- fBButton3, B3fR fBAltfR
- fBButton4, B4fR fBDoublefR
- fBButton5, B5fR fBTriplefR
- fBMod1, M1fR fBQuadruplefR
- .DE
- 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, fBButton1fR 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 fB<Control-Button-1>fR will match
- the event, but fB<Mod1-Button-1>fR will not.
- If no modifiers are specified, then any combination of modifiers may
- be present in the event.
- .PP
- fBMetafR and fBMfR refer to whichever of the
- fBM1fR through fBM5fR modifiers is associated with the Meta
- key(s) on the keyboard (keysyms fBMeta_RfR and fBMeta_LfR).
- If there are no Meta keys, or if they are not associated with any
- modifiers, then fBMetafR and fBMfR will not match any events.
- Similarly, the fBAltfR modifier refers to whichever modifier
- is associated with the alt key(s) on the keyboard (keysyms
- fBAlt_LfR and fBAlt_RfR).
- .PP
- The fBDoublefR, fBTriplefR and fBQuadruplefR modifiers are a
- convenience for specifying double mouse clicks and other repeated
- events. They cause a particular 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 fBDoublefR, fBTriplefR or fBQuadruplefR
- pattern, all of the events must occur close together in time and without
- substantial mouse motion in between. For example, fB<Double-Button-1>fR
- is equivalent to fB<Button-1><Button-1>fR with the extra time and space
- requirement.
- .SH "EVENT TYPES"
- .PP
- The fItypefR field may be any of the standard X event types, with a
- few extra abbreviations. The fItypefR 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.
- .DS
- .ta w'ButtonPress, Button 'u +w'KeyPress, Key 'u
- fBActivate Destroy Map
- ButtonPress, Button Enter MapRequest
- ButtonRelease Expose Motion
- Circulate FocusIn MouseWheel
- CirculateRequest FocusOut Property
- Colormap Gravity Reparent
- Configure KeyPress, Key ResizeRequest
- ConfigureRequest KeyRelease Unmap
- Create Leave Visibility
- DeactivatefR
- .DE
- .VS
- 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:
- .IP "fBActivatefR, fBDeactivatefR" 5
- 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 appearance than widgets in
- deactive windows. The fBActivatefR event is sent to all the
- sub-windows in a toplevel when it changes from being deactive to
- active. Likewise, the fBDeactivefR event is sent when the window's
- state changes from active to deactive. There are no useful percent
- substitutions you would make when binding to these events.
- .IP fBMouseWheelfR 5
- 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 fBMouseWheelfR events that the
- application can use to scroll. On Windows, the event is
- always routed to the window that currently has focus (like fBKeyfR
- events.) On Mac OS X,
- the event is routed to the window under the pointer. When the event
- is received you can use the fB%DfR substitution to get the
- fIdeltafR field for the event, which is a integer value describing how
- 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. On Mac OS X, the value is
- not scaled by 120, but a value of 1 corresponds to roughly one text line.
- The sign of the value determines which direction your widget should scroll.
- Positive values should scroll up and negative values should scroll down.
- .VE
- .IP "fBKeyPressfP, fBKeyReleasefP" 5
- The fBKeyPressfP and fBKeyReleasefP events are generated
- whenever a key is pressed or released. fBKeyPressfP and fBKeyReleasefP
- events are sent to the window which currently has the keyboard focus.
- .IP "fBButtonPressfP, fBButtonReleasefP, fBMotionfP" 5
- The fBButtonPressfP and fBButtonReleasefP events
- are generated when the user presses or releases a mouse button.
- fBMotionfP events are generated whenever the pointer is moved.
- fBButtonPressfP, fBButtonReleasefP, and fBMotionfP events are
- normally sent to the window containing the pointer.
- .RS
- .PP
- When a mouse button is pressed, the window containing the pointer
- automatically obtains a temporary pointer grab.
- Subsequent fBButtonPressfP, fBButtonReleasefP, and fBMotionfP
- events will be sent to that window,
- regardless of which window contains the pointer,
- until all buttons have been released.
- .RE
- .IP fBConfigurefP 5
- A fBConfigurefP event is sent to a window whenever its
- size, position, or border width changes, and sometimes
- when it has changed position in the stacking order.
- .IP "fBMapfP, fBUnmapfP" 5
- The fBMapfP and fBUnmapfP events are generated whenever the mapping
- state of a window changes.
- .RS
- .PP
- Windows are created in the unmapped state.
- Top-level windows become mapped when they transition to the
- fBnormalfP state, and are unmapped in the fBwithdrawnfP
- and fBiconicfP states.
- Other windows become mapped when they are placed under control
- of a geometry manager (for example fBpackfP or fBgridfP).
- .PP
- A window is fIviewablefP only if it and all of its ancestors are mapped.
- Note that geometry managers typically do not map their children until
- they have been mapped themselves, and unmap all children
- when they become unmapped; hence in Tk fBMapfP and fBUnmapfP
- events indicate whether or not a window is viewable.
- .RE
- .IP fBVisibilityfP 5
- A window is said to be fIobscuredfP when another window
- above it in the stacking order fully or partially overlaps it.
- fBVisibilityfP events are generated whenever a window's
- obscurity state changes; the fIstatefP field (fB%sfP)
- specifies the new state.
- .IP fBExposefP 5
- An fBExposefP event is generated whenever all or part of a
- window should be redrawn (for example, when a window is
- first mapped or if it becomes unobscured).
- It is normally not necessary for client applications to
- handle fBExposefP events, since Tk handles them internally.
- .IP fBDestroyfP 5
- A fBDestroyfP event is delivered to a window when
- it is destroyed.
- .RS
- .PP
- When the fBDestroyfP event is delivered
- to a widget, it is in a ``half-dead'' state: the widget still exists,
- but most operations on it will fail.
- .RE
- .IP "fBFocusInfP, fBFocusOutfP" 5
- The fBFocusInfP and fBFocusOutfP events are generated
- whenever the keyboard focus changes.
- A fBFocusOutfP event is sent to the old focus window,
- and a fBFocusInfP event is sent to the new one.
- .RS
- .PP
- In addition,
- if the old and new focus windows do not share a common parent,
- ``virtual crossing'' focus events are sent to the intermediate
- windows in the hierarchy.
- Thus a fBFocusInfP event indicates
- that the target window or one of its descendants has acquired the focus,
- and a fBFocusOutfP event indicates that the focus
- has been changed to a window outside the target window's hierarchy.
- .PP
- The keyboard focus may be changed explicitly by a call to fBfocusfP,
- or implicitly by the window manager.
- .RE
- .IP "fBEnterfP, fBLeavefP" 5
- An fBEnterfP event is sent to a window when the pointer
- enters that window, and a fBLeavefP event is sent when
- the pointer leaves it.
- .RS
- .PP
- If there is a pointer grab in effect, fBEnterfP and fBLeavefP
- events are only delivered to the window owning the grab.
- .PP
- In addition, when the pointer moves
- between two windows, fBEnterfP and fBLeavefP
- ``virtual crossing'' events are sent to intermediate windows
- in the hierarchy in the same manner as for fBFocusInfP and
- fBFocusOutfP events.
- .RE
- .IP fBPropertyfP
- A fBPropertyfP event is sent to a window whenever an X property
- belonging to that window is changed or deleted.
- fBPropertyfP events are not normally delivered to Tk applications as
- they are handled by the Tk core.
- .IP fBColormapfP
- A fBColormapfP event is generated whenever the colormap
- associated with a window has been changed, installed, or uninstalled.
- .RS
- .PP
- Widgets may be assigned a private colormap by
- specifying a fB-colormapfP option; the window manager
- is responsible for installing and uninstalling colormaps
- as necessary.
- .PP
- Note that Tk provides no useful details for this event type.
- .RE
- '" The following events were added in TIP#47
- .IP "fBMapRequestfP, fBCirculateRequestfP, fBResizeRequestfP, fBConfigureRequestfP, fBCreatefP" 5
- These events are not normally delivered to Tk applications.
- They are included for completeness, to make it possible to
- write X11 window managers in Tk.
- (These events are only delivered when a client has
- selected fBSubstructureRedirectMaskfP on a window;
- the Tk core does not use this mask.)
- .IP "fBGravityfP, fBReparentfP, fBCirculatefP" 5
- The events fBGravityfP and fBReparentfP
- are not normally delivered to Tk applications.
- They are included for completeness.
- .RS
- .PP
- A fBCirculatefP event indicates that the window has moved
- to the top or to the bottom of the stacking order as
- a result of an fBXCirculateSubwindowsfP protocol request.
- Note that the stacking order may be changed for other reasons
- which do not generate a fBCirculatefP event, and that
- Tk does not use fBXCirculateSubwindows()fP internally.
- This event type is included only for completeness;
- there is no reliable way to track changes to a window's
- position in the stacking order.
- .RE
- .SH "EVENT DETAILS"
- .PP
- The last part of a long event specification is fIdetailfR. In the
- case of a fBButtonPressfR or fBButtonReleasefR 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 fItypefR may be omitted: if will default
- to fBButtonPressfR. For example, the specifier fB<1>fR
- is equivalent to fB<ButtonPress-1>fR.
- .PP
- If the event type is fBKeyPressfR or fBKeyReleasefR, then
- fIdetailfR 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 keysym 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 fB%KfR notation described below
- to print out the keysym name for a particular key.
- If a keysym fIdetailfR is given, then the
- fItypefR field may be omitted; it will default to fBKeyPressfR.
- For example, fB<Control-comma>fR is equivalent to
- fB<Control-KeyPress-comma>fR.
- .SH "BINDING SCRIPTS AND SUBSTITUTIONS"
- .PP
- The fIscriptfR argument to fBbindfR is a Tcl script,
- which will be executed whenever the given event sequence occurs.
- fICommandfR will be executed in the same interpreter that the
- fBbindfR command was executed in, and it will run at global
- level (only global variables will be accessible).
- If fIscriptfR contains
- any fB%fR characters, then the script will not be
- executed directly. Instead, a new script will be
- generated by replacing each fB%fR, and the character following
- it, with information from the current event. The replacement
- depends on the character following the fB%fR, 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.
- .IP fB%%fR 5
- Replaced with a single percent.
- .IP fB%#fR 5
- The number of the last client request processed by the server
- (the fIserialfR field from the event). Valid for all event
- types.
- .IP fB%afR 5
- The fIabovefR field from the event,
- formatted as a hexadecimal number.
- Valid only for fBConfigurefR events.
- Indicates the sibling window immediately below the receiving window
- in the stacking order, or fB0fP if the receiving window is at the
- bottom.
- .IP fB%bfR 5
- The number of the button that was pressed or released. Valid only
- for fBButtonPressfR and fBButtonReleasefR events.
- .IP fB%cfR 5
- The fIcountfR field from the event. Valid only for fBExposefR events.
- Indicates that there are fIcountfP pending fBExposefP events which have not
- yet been delivered to the window.
- .IP fB%dfR 5
- The fIdetailfR field from the event. The fB%dfR is replaced by
- a string identifying the detail. For fBEnterfR,
- fBLeavefR, fBFocusInfR, and fBFocusOutfR events,
- the string will be one of the following:
- .RS
- .DS
- .ta 6c
- fBNotifyAncestor NotifyNonlinearVirtual
- NotifyDetailNone NotifyPointer
- NotifyInferior NotifyPointerRoot
- NotifyNonlinear NotifyVirtualfR
- .DE
- For fBConfigureRequestfR events, the string will be one of:
- .DS
- .ta 6c
- fBAbove Opposite
- Below None
- BottomIf TopIffR
- .DE
- For events other than these, the substituted string is undefined.
- .RE
- .IP fB%ffR 5
- The fIfocusfR field from the event (fB0fR or fB1fR). Valid only
- for fBEnterfR and fBLeavefR events. fB1fP if the receiving
- window is the focus window or a descendant of the focus window,
- fB0fP otherwise.
- .IP fB%hfR 5
- .VS
- The fIheightfR field from the event. Valid for the fBConfigurefR,
- fBConfigureRequestfR, fBCreatefR, fBResizeRequestfR, and
- fBExposefR events.
- Indicates the new or requested height of the window.
- .VE
- .IP fB%ifR 5
- The fIwindowfR field from the event, represented as a hexadecimal
- integer. Valid for all event types.
- .IP fB%kfR 5
- The fIkeycodefR field from the event. Valid only for fBKeyPressfR
- and fBKeyReleasefR events.
- .IP fB%mfR 5
- The fImodefR field from the event. The substituted string is one of
- fBNotifyNormalfR, fBNotifyGrabfR, fBNotifyUngrabfR, or
- .VS
- fBNotifyWhileGrabbedfR. Valid only for fBEnterfR,
- fBFocusInfR, fBFocusOutfR, and fBLeavefR events.
- .VE
- .IP fB%ofR 5
- The fIoverride_redirectfR field from the event. Valid only for
- fBMapfR, fBReparentfR, and fBConfigurefR events.
- .IP fB%pfR 5
- The fIplacefR field from the event, substituted as one of the
- strings fBPlaceOnTopfR or fBPlaceOnBottomfR. Valid only
- for fBCirculatefR and fBCirculateRequestfR events.
- .IP fB%sfR 5
- The fIstatefR field from the event. For fBButtonPressfR,
- fBButtonReleasefR, fBEnterfR, fBKeyPressfR, fBKeyReleasefR,
- fBLeavefR, and fBMotionfR events, a decimal string
- is substituted. For fBVisibilityfR, one of the strings
- fBVisibilityUnobscuredfR, fBVisibilityPartiallyObscuredfR,
- and fBVisibilityFullyObscuredfR is substituted.
- For fBPropertyfP events, substituted with
- either the string fBNewValuefP (indicating that the property
- has been created or modified) or fBDeletefP (indicating that
- the property has been removed).
- .IP fB%tfR 5
- The fItimefR field from the event.
- This is the X server timestamp (typically the time since
- the last server reset) in milliseconds, when the event occurred.
- Valid for most events.
- .IP fB%wfR 5
- The fIwidthfR field from the event.
- Indicates the new or requested width of the window.
- Valid only for
- .VS
- fBConfigurefR, fBConfigureRequestfR, fBCreatefR,
- fBResizeRequestfR, and fBExposefR events.
- .VE
- .IP "fB%xfR, fB%yfR" 5
- The fIxfR and fIyfR fields from the event.
- For fBButtonPressfP, fBButtonReleasefP, fBMotionfP,
- fBKeyPressfP, fBKeyReleasefP, and fBMouseWheelfP events,
- fB%xfP and fB%yfP indicate the position of the mouse pointer
- relative to the receiving window.
- For fBEnterfP and fBLeavefP events, the position where the
- mouse pointer crossed the window, relative to the receiving window.
- For fBConfigurefP and fBCreatefP requests, the fIxfP and fIyfP
- coordinates of the window relative to its parent window.
- .IP fB%AfR 5
- Substitutes the UNICODE character corresponding to the event, or
- the empty string if the event doesn't correspond to a UNICODE character
- (e.g. the shift key was pressed). fBXmbLookupStringfR (or
- fBXLookupStringfR when input method support is turned off) does all
- the work of translating from the event to a UNICODE character.
- Valid only for fBKeyPressfR and fBKeyReleasefR events.
- .IP fB%BfR 5
- The fIborder_widthfR field from the event. Valid only for
- fBConfigurefR, fBConfigureRequestfR, and fBCreatefR events.
- .IP fB%DfR 5
- .VS
- This reports the fIdeltafR value of a fBMouseWheelfR event. The
- fIdeltafR 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.
- .VE
- .IP fB%EfR 5
- The fIsend_eventfR field from the event. Valid for all event types.
- fB0fP indicates that this is a ``normal'' event, fB1fP indicates
- that it is a ``synthetic'' event generated by fBSendEventfP.
- .IP fB%KfR 5
- The keysym corresponding to the event, substituted as a textual
- string. Valid only for fBKeyPressfR and fBKeyReleasefR events.
- .IP fB%NfR 5
- The keysym corresponding to the event, substituted as a decimal
- number. Valid only for fBKeyPressfR and fBKeyReleasefR events.
- .IP fB%PfR 5
- The name of the property being updated or deleted (which
- may be converted to an XAtom using fBwinfo atomfR.) Valid
- only for fBPropertyfP events.
- .IP fB%RfR 5
- The fIrootfR window identifier from the event. Valid only for
- events containing a fIrootfR field.
- .IP fB%SfR 5
- The fIsubwindowfR window identifier from the event,
- formatted as a hexadecimal number.
- Valid only for events containing a fIsubwindowfR field.
- .IP fB%TfR 5
- The fItypefR field from the event. Valid for all event types.
- .IP fB%WfR 5
- The path name of the window to which the event was reported (the
- fIwindowfR field from the event). Valid for all event types.
- .IP fB%XfR 5
- The fIx_rootfR 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
- fBButtonPressfR, fBButtonReleasefR, fBKeyPressfR, fBKeyReleasefR,
- and fBMotionfR events.
- Same meaning as fB%xfP, except relative to the (virtual) root window.
- .IP fB%YfR 5
- The fIy_rootfR 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
- fBButtonPressfR, fBButtonReleasefR, fBKeyPressfR, fBKeyReleasefR,
- and fBMotionfR events.
- Same meaning as fB%yfP, except relative to the (virtual) root window.
- .LP
- 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 fB$fR and
- fB{fR may 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 fBAbovefR; for these replacements no special formatting
- is ever necessary.
- The most common case where reformatting occurs is for the fB%AfR
- substitution. For example, if fIscriptfR is
- .CS
- fBinsert %AfR
- .CE
- and the character typed is an open square bracket, then the script
- actually executed will be
- .CS
- fBinsert e[fR
- .CE
- This will cause the fBinsertfR to 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.
- .SH "MULTIPLE MATCHES"
- .PP
- It is possible for several bindings to match a given X event.
- If the bindings are associated with different fItagfR'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 fBallfR binding.
- The fBbindtagsfR command may be used to change this order for
- a particular window or to associate additional binding tags with
- the window.
- .PP
- The fBcontinuefR and fBbreakfR commands may be used inside a
- binding script to control the processing of matching scripts.
- If fBcontinuefR is invoked, then the current binding script
- is terminated but Tk will continue processing binding scripts
- associated with other fItagfR's.
- If the fBbreakfR command is invoked within a binding script,
- then that script terminates and no other scripts will be invoked
- for the event.
- .PP
- If more than one binding matches a particular event and they
- have the same fItagfR, 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 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.
- .PP
- 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.
- .PP
- 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:
- .CS
- event add <<Paste>> <Control-y>
- event add <<Paste>> <Button-2>
- event add <<Scroll>> <Button-2>
- fBbindfR Entry <<Paste>> {puts Paste}
- fBbindfR Entry <<Scroll>> {puts Scroll}
- .CE
- If the user types Control-y, the fB<<Paste>>fR binding
- will be invoked, but if the user presses button 2 then one of
- either the fB<<Paste>>fR or the fB<<Scroll>>fR bindings will
- be invoked, but exactly which one gets invoked is undefined.
- .PP
- 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.
- .SH "MULTI-EVENT SEQUENCES AND IGNORED EVENTS"
- .PP
- When a fIsequencefR specified in a fBbindfR command 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 repeatedly the sequence fB<Double-ButtonPress-1>fR 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 fBKeyPressfR or fBButtonPressfR events.
- For example, fB<Double-ButtonPress-1>fR will match a sequence of
- presses of button 1, even though there will be fBButtonReleasefR
- events (and possibly fBMotionfR events) between the
- fBButtonPressfR events.
- Furthermore, a fBKeyPressfR event may be preceded by any number
- of other fBKeyPressfR events for modifier keys without the
- modifier keys preventing a match.
- For example, the event sequence fBaBfR will match a press of the
- fBafR key, a release of the fBafR key, a press of the fBShiftfR
- key, and a press of the fBbfR key: the press of fBShiftfR is
- ignored because it is a modifier key.
- Finally, if several fBMotionfR events occur in a row, only
- the last one is used for purposes of matching binding sequences.
- .SH "ERRORS"
- .PP
- If an error occurs in executing the script for a binding then the
- fBbgerrorfR mechanism is used to report the error.
- The fBbgerrorfR command will be executed at global level
- (outside the context of any Tcl procedure).
- .SH "EXAMPLES"
- Arrange for a string describing the motion of the mouse to be printed
- out when the mouse is double-clicked:
- .CS
- fBbindfR . <Double-1> {
- puts "hi from (%x,%y)"
- }
- .CE
- .PP
- A little GUI that displays what the keysym name of the last key
- pressed is:
- .CS
- set keysym "Press any key"
- pack [label .l -textvariable keysym -padx 2m -pady 1m]
- fBbindfR . <Key> {
- set keysym "You pressed %K"
- }
- .CE
- .SH "SEE ALSO"
- bgerror(n), bindtags(n), event(n), focus(n), grab(n), keysyms(n)
- .SH KEYWORDS
- binding, event