📄 event.n
字号:
'\"'\" Copyright (c) 1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) event.n 1.6 97/10/31 12:58:54'\" .so man.macros.TH event n 4.4 Tk "Tk Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEevent \- Miscellaneous event facilities: define virtual events and generate events.SH SYNOPSIS\fBevent\fI option \fR?\fIarg arg ...\fR?.BE.SH DESCRIPTION.PPThe \fBevent\fR command provides several facilities for dealing withwindow system events, such as defining virtual events and synthesizingevents. The command has several different forms, determined by thefirst argument. The following forms are currently supported:.TP\fBevent add <<\fIvirtual\fB>>\fI sequence \fR?\fIsequence ...\fR?Associates the virtual event \fIvirtual\fR with the physicalevent sequence(s) given by the \fIsequence\fR arguments, so thatthe virtual event will trigger whenever any one of the \fIsequence\fRsoccurs.\fIVirtual\fR may be any string value and \fIsequence\fR may haveany of the values allowed for the \fIsequence\fR argument to the\fBbind\fR command.If \fIvirtual\fR is already defined, the new physical event sequencesadd to the existing sequences for the event..TP\fBevent delete <<\fIvirtual\fB>> \fR?\fIsequence\fR \fIsequence ...\fR?Deletes each of the \fIsequence\fRs from those associated withthe virtual event given by \fIvirtual\fR.\fIVirtual\fR may be any string value and \fIsequence\fR may haveany of the values allowed for the \fIsequence\fR argument to the\fBbind\fR command.Any \fIsequence\fRs not currently associated with \fIvirtual\fRare ignored.If no \fIsequence\fR argument is provided, all physical event sequencesare removed for \fIvirtual\fR, so that the virtual event will nottrigger anymore..TP\fBevent generate \fIwindow event \fR?\fIoption value option value ...\fR?Generates a window event and arranges for it to be processed just as ifit had come from the window system.\fIWindow\fR gives the path name of the window for which the event.VSwill be generated; it may also be an identifier (such as returned by\fBwinfo id\fR) as long as it is for a window in the current application..VE\fIEvent\fR provides a basic description ofthe event, such as \fB<Shift-Button-2>\fR or \fB<<Paste>>\fR.\fIEvent\fR may have any of the forms allowed for the \fIsequence\fRargument of the \fBbind\fR command except that it must consistof a single event pattern, not a sequence.\fIOption-value\fR pairs may be used to specify additionalattributes of the event, such as the x and y mouse position; seeEVENT FIELDS below. If the \fB\-when\fR option is not specified, theevent is processed immediately: all of the handlers for the eventwill complete before the \fBevent generate\fR command returns.If the \fB\-when\fR option is specified then it determines when theevent is processed..TP\fBevent info \fR?<<\fIvirtual\fB>>\fR?Returns information about virtual events.If the \fB<<\fIvirtual\fB>>\fR argument is omitted, the return valueis a list of all the virtual events that are currently defined.If \fB<<\fIvirtual\fB>>\fR is specified then the return value isa list whose elements are the physical event sequences currentlydefined for the given virtual event; if the virtual event isnot defined then an empty string is returned..SH "EVENT FIELDS".PPThe following options are supported for the \fBevent generate\fRcommand. These correspond to the ``%'' expansionsallowed in binding scripts for the \fBbind\fR command..TP\fB\-above\fI window\fR\fIWindow\fR specifies the \fIabove\fR field for the event,either as a window path name or as an integer window id.Valid for \fBConfigure\fR events.Corresponds to the \fB%a\fR substitution for binding scripts..TP\fB\-borderwidth\fI size\fR\fISize\fR must be a screen distance; it specifies the\fIborder_width\fR field for the event.Valid for \fBConfigure\fR events.Corresponds to the \fB%B\fR substitution for binding scripts..TP\fB\-button\fI number\fR\fINumber\fR must be an integer; it specifies the \fIdetail\fR fieldfor a \fBButtonPress\fR or \fBButtonRelease\fR event, overridingany button number provided in the base \fIevent\fR argument.Corresponds to the \fB%b\fR substitution for binding scripts..TP\fB\-count\fI number\fR\fINumber\fR must be an integer; it specifies the \fIcount\fR fieldfor the event. Valid for \fBExpose\fR events.Corresponds to the \fB%c\fR substitution for binding scripts..TP\fB\-detail\fI detail\fR\fIDetail\fR specifies the \fIdetail\fR field for the eventand must be one of the following:.RS.DS.ta 6c\fBNotifyAncestor NotifyNonlinearVirtualNotifyDetailNone NotifyPointerNotifyInferior NotifyPointerRootNotifyNonlinear NotifyVirtual\fR.DEValid for \fBEnter\fR, \fBLeave\fR, \fBFocusIn\fR and\fBFocusOut\fR events.Corresponds to the \fB%d\fR substitution for binding scripts..RE.TP\fB\-focus\fI boolean\fR\fIBoolean\fR must be a boolean value; it specifies the \fIfocus\fRfield for the event.Valid for \fBEnter\fR and \fBLeave\fR events.Corresponds to the \fB%f\fR substitution for binding scripts..TP\fB\-height\fI size\fR\fISize\fR must be a screen distance; it specifies the \fIheight\fRfield for the event. Valid for \fBConfigure\fR events.Corresponds to the \fB%h\fR substitution for binding scripts..TP\fB\-keycode\fI number\fR\fINumber\fR must be an integer; it specifies the \fIkeycode\fRfield for the event.Valid for \fBKeyPress\fR and \fBKeyRelease\fR events.Corresponds to the \fB%k\fR substitution for binding scripts..TP\fB\-keysym\fI name\fR\fIName\fR must be the name of a valid keysym, such as \fBg\fR,\fBspace\fR, or \fBReturn\fR; its correspondingkeycode value is used as the \fIkeycode\fR field for event, overridingany detail specified in the base \fIevent\fR argument.Valid for \fBKeyPress\fR and \fBKeyRelease\fR events.Corresponds to the \fB%K\fR substitution for binding scripts..TP\fB\-mode\fI notify\fR\fINotify\fR specifies the \fImode\fR field for the event and must beone of \fBNotifyNormal\fR, \fBNotifyGrab\fR, \fBNotifyUngrab\fR, or\fBNotifyWhileGrabbed\fR.Valid for \fBEnter\fR, \fBLeave\fR, \fBFocusIn\fR, and\fBFocusOut\fR events.Corresponds to the \fB%m\fR substitution for binding scripts. .TP\fB\-override\fI boolean\fR\fIBoolean\fR must be a boolean value; it specifies the\fIoverride_redirect\fR field for the event.Valid for \fBMap\fR, \fBReparent\fR, and \fBConfigure\fR events.Corresponds to the \fB%o\fR substitution for binding scripts..TP\fB\-place\fI where\fR\fIWhere\fR specifies the \fIplace\fR field for the event; it must beeither \fBPlaceOnTop\fR or \fBPlaceOnBottom\fR.Valid for \fBCirculate\fR events.Corresponds to the \fB%p\fR substitution for binding scripts..TP\fB\-root\fI window\fR\fIWindow\fR must be either a window path name or an integer windowidentifier; it specifies the \fIroot\fR field for the event.Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fRevents.Corresponds to the \fB%R\fR substitution for binding scripts..TP\fB\-rootx\fI coord\fR\fICoord\fR must be a screen distance; it specifies the \fIx_root\fRfield for the event.Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fRevents. Corresponds to the \fB%X\fR substitution for binding scripts..TP\fB\-rooty\fI coord\fR\fICoord\fR must be a screen distance; it specifies th \fIy_root\fRfield for the event.Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fRevents.Corresponds to the \fB%Y\fR substitution for binding scripts..TP\fB\-sendevent\fI boolean\fR\fBBoolean\fR must be a boolean value; it specifies the \fIsend_event\fRfield for the event. Valid for all events. Corresponds to the\fB%E\fR substitution for binding scripts..TP\fB\-serial\fI number\fR\fINumber\fR must be an integer; it specifies the \fIserial\fR fieldfor the event. Valid for all events.Corresponds to the \fB%#\fR substitution for binding scripts..TP\fB\-state\fI state\fR\fIState\fR specifies the \fIstate\fR field for the event.For \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fR eventsit must be an integer value.For \fBVisibility\fR events it must be one of \fBVisibilityUnobscured\fR, \fBVisibilityPartiallyObscured\fR, or \fBVisibilityFullyObscured\fR.This option overrides any modifiers such as \fBMeta\fR or \fBControl\fRspecified in the base \fIevent\fR.Corresponds to the \fB%s\fR substitution for binding scripts..TP\fB\-subwindow\fI window\fR\fIWindow\fR specifies the \fIsubwindow\fR field for the event, eitheras a path name for a Tk widget or as an integer window identifier.Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, and \fBMotion\fR events.Similar to \fB%S\fR substitution for binding scripts..TP\fB\-time\fI integer\fR\fIInteger\fR must be an integer value; it specifies the \fItime\fR fieldfor the event.Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBEnter\fR, \fBLeave\fR, \fBMotion\fR,and \fBProperty\fR events.Corresponds to the \fB%t\fR substitution for binding scripts..TP\fB\-width\fI size\fR\fISize\fR must be a screen distance; it specifies the \fIwidth\fR fieldfor the event.Valid for \fBConfigure\fR events.Corresponds to the \fB%w\fR substitution for binding scripts..TP\fB\-when\fI when\fR\fIWhen\fR determines when the event will be processed; it must have oneof the following values:.RS.IP \fBnow\fR 10Process the event immediately, before the command returns.This also happens if the \fB\-when\fR option is omitted..IP \fBtail\fR 10Place the event on Tcl's event queue behind any events alreadyqueued for this application..IP \fBhead\fR 10Place the event at the front of Tcl's event queue, so that itwill be handled before any other events already queued..IP \fBmark\fR 10Place the event at the front of Tcl's event queue but behind anyother events already queued with \fB\-when mark\fR.This option is useful when generating a series of events that shouldbe processed in order but at the front of the queue..RE.TP\fB\-x\fI coord\fR\fICoord\fR must be a screen distance; it specifies the \fIx\fR fieldfor the event.Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBMotion\fR, \fBEnter\fR, \fBLeave\fR,\fBExpose\fR, \fBConfigure\fR, \fBGravity\fR, and \fBReparent\fRevents.Corresponds to the the \fB%x\fR substitution for binding scripts..TP\fB\-y\fI coord\fR\fICoord\fR must be a screen distance; it specifies the \fIy\fRfield for the event.Valid for \fBKeyPress\fR, \fBKeyRelease\fR, \fBButtonPress\fR,\fBButtonRelease\fR, \fBMotion\fR, \fBEnter\fR, \fBLeave\fR,\fBExpose\fR, \fBConfigure\fR, \fBGravity\fR, and \fBReparent\fRevents.Corresponds to the the \fB%y\fR substitution for binding scripts..PPAny options that are not specified when generating an event are filled with the value 0, except for \fIserial\fR, which is filled with the next X event serial number. .SH "VIRTUAL EVENT EXAMPLES".PPIn order for a virtual event binding to trigger, two things musthappen. First, the virtual event must be defined with the\fBevent add\fR command. Second, a binding must be created forthe virtual event with the \fBbind\fR command.Consider the following virtual event definitions:.CSevent add <<Paste>> <Control-y>event add <<Paste>> <Button-2>event add <<Save>> <Control-X><Control-S>event add <<Save>> <Shift-F12>.CEIn the \fBbind\fR command, a virtual event can be bound like any otherbuiltin event type as follows:.CSbind Entry <<Paste>> {%W insert [selection get]}.CEThe double angle brackets are used to specify that a virtual event is beingbound. If the user types Control-y or presses button 2, or ifa \fB<<Paste>>\fR virtual event is synthesized with \fBevent generate\fR,then the \fB<<Paste>>\fR binding will be invoked..PPIf a virtual binding has the exact same sequence as a separatephysical binding, then the physical binding will take precedence.Consider the following example:.CSevent add <<Paste>> <Control-y> <Meta-Control-y>bind Entry <Control-y> {puts Control-y}bind Entry <<Paste>> {puts Paste}.CEWhen the user types Control-y the \fB<Control-y>\fR bindingwill be invoked, because a physical event is consideredmore specific than a virtual event, all other things being equal.However, when the user types Meta-Control-y the\fB<<Paste>>\fR binding will be invoked, because the\fBMeta\fR modifier in the physical pattern associated with the virtual binding is more specific than the \fB<Control-y\fR> sequence forthe physical event..PPBindings on a virtual event may be created before the virtual event exists.Indeed, the virtual event never actually needs to be defined, for instance,on platforms where the specific virtual event would meaningless orungeneratable..PPWhen a definition of a virtual event changes at run time, all windowswill respond immediately to the new definition.Starting from the preceding example, if the following code is executed:.CSbind <Entry> <Control-y> {}event add <<Paste>> <Key-F6>.CEthe behavior will change such in two ways. First, the shadowed\fB<<Paste>>\fR binding will emerge.Typing Control-y will no longer invoke the \fB<Control-y>\fR binding, but instead invoke the virtual event \fB<<Paste>>\fR. Second,pressing the F6 key will now also invoke the \fB<<Paste>>\fR binding..SH "SEE ALSO"bind.SH KEYWORDSevent, binding, define, handle, virtual event
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -