| BIND(9) | Kernel Developer's Manual | BIND(9) |
bind - Arrange for events to invoke Tk scripts
bind tag sequence script
bind tag sequence +script
The bind command associates Tk scripts with window events. If all three arguments are specified, bind will arrange for script (a Tk script) to be evaluated whenever the event(s) given by sequence occur in the window(s) identified by tag. If script is prefixed with a ``+'', then it is appended to any existing binding for sequence; otherwise script replaces any existing binding. If script is an empty string then the current binding for sequence is destroyed, leaving sequence unbound. In all of the cases where a script argument is provided, bind returns an empty string. If script is prefixed with a ``-'', then any existing binding for sequence, whose script is exactly the same as script, is removed. The tag argument gives the pathname of the window to which sequence is bound.
The sequence argument specifies a sequence of one or more event patterns, with optional white space between the patterns. Each event pattern may take one of two forms. In the simplest case it is a single printing ASCII character, such as a or [. The character may not be a space character or the character <. This form of pattern matches a KeyPress event for the particular character. The second form of pattern is longer but more general. It has the following syntax:
<event-event-...-event>
The following events are accepted:
The event sequence can contain any combination of the above events. They are treated independently, and if any of the events occur, the sequence matches. You cannot combine key presses of more than one key. Events will not be combined on delivery, except that Motion events may be combined with button presses (possibly doubled).
The script argument to bind is a Tk script, which will be executed whenever the given event sequence occurs. If script contains any % characters, then the script will not be executed directly. Instead, a new script will be generated by replacing each %, and the character following it, with information from the current event. The replacement depends on the character following the %, 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.
The replacement string for a %-replacement is formatted as a proper Tk list element. This means that it will be surrounded with braces if it contains spaces, or special characters such as $ and { may be preceded by backslashes. This guarantees that the string will be passed through the Tk parser when the binding script is evaluated.
The above scheme is not ideal, and will probably be fixed in the future. Quoting is a mess - in particular, the quoting provided for the %A substitution does not work correctly when a quoted character is re-interpreted by Tk.
The length of binding scripts is limited to 128 characters.