1event(n)                     Tk Built-In Commands                     event(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       event  - Miscellaneous event facilities: define virtual events and gen‐
9       erate events
10

SYNOPSIS

12       event option ?arg arg ...?
13______________________________________________________________________________
14

DESCRIPTION

16       The event command provides several facilities for dealing  with  window
17       system events, such as defining virtual events and synthesizing events.
18       The command has several different forms, determined by the first  argu‐
19       ment.  The following forms are currently supported:
20
21       event add <<virtual>> sequence ?sequence ...?
22              Associates  the  virtual  event  virtual with the physical event
23              sequence(s) given by the sequence arguments, so that the virtual
24              event  will  trigger  whenever  any one of the sequences occurs.
25              Virtual may be any string value and sequence may have any of the
26              values  allowed  for  the sequence argument to the bind command.
27              If virtual is already defined, the new physical event  sequences
28              add to the existing sequences for the event.
29
30       event delete <<virtual>> ?sequence sequence ...?
31              Deletes  each  of  the  sequences from those associated with the
32              virtual event given by virtual.  Virtual may be any string value
33              and sequence may have any of the values allowed for the sequence
34              argument to the bind command.  Any sequences not currently asso‐
35              ciated  with  virtual  are  ignored.  If no sequence argument is
36              provided, all physical event sequences are removed for  virtual,
37              so that the virtual event will not trigger anymore.
38
39       event generate window event ?option value option value ...?
40              Generates  a  window  event  and arranges for it to be processed
41              just as if it had come from the window system.  Window gives the
42              path  name  of the window for which the event will be generated;
43              it may also be an identifier (such as returned by winfo  id)  as
44              long  as  it  is for a window in the current application.  Event
45              provides a basic description of the event, such  as  <Shift-But‐
46              ton-2>  or  <<Paste>>.   If  Window is empty the whole screen is
47              meant, and coordinates are relative to the  screen.   Event  may
48              have  any  of the forms allowed for the sequence argument of the
49              bind command except that it must consist of a single event  pat‐
50              tern, not a sequence.  Option-value pairs may be used to specify
51              additional attributes of the event, such as the x  and  y  mouse
52              position;   see  EVENT FIELDS below.  If the -when option is not
53              specified, the event is processed immediately:  all of the  han‐
54              dlers for the event will complete before the event generate com‐
55              mand returns.  If the -when option is specified then  it  deter‐
56              mines  when the event is processed.  Certain events, such as key
57              events, require that the window has focus to receive  the  event
58              properly.
59
60       event info ?<<virtual>>?
61              Returns  information  about  virtual events.  If the <<virtual>>
62              argument is omitted, the return value is a list of all the  vir‐
63              tual events that are currently defined.  If <<virtual>> is spec‐
64              ified then the return value is a list  whose  elements  are  the
65              physical event sequences currently defined for the given virtual
66              event;  if the virtual event is not defined then an empty string
67              is returned.
68
69              Note  that  virtual  events that are not bound to physical event
70              sequences are not returned by event info.
71

EVENT FIELDS

73       The following options are supported for  the  event  generate  command.
74       These  correspond  to the “%” expansions allowed in binding scripts for
75       the bind command.
76
77       -above window
78              Window specifies the above field for the event, either as a win‐
79              dow  path  name or as an integer window id.  Valid for Configure
80              events.  Corresponds to the %a substitution for binding scripts.
81
82       -borderwidth size
83              Size must be a screen distance;  it specifies  the  border_width
84              field  for  the event.  Valid for Configure events.  Corresponds
85              to the %B substitution for binding scripts.
86
87       -button number
88              Number must be an integer;  it specifies the detail field for  a
89              ButtonPress  or ButtonRelease event, overriding any button  num‐
90              ber provided in the base event argument.  Corresponds to the  %b
91              substitution for binding scripts.
92
93       -count number
94              Number must be an integer;  it specifies the count field for the
95              event.  Valid for Expose events.  Corresponds to the %c  substi‐
96              tution for binding scripts.
97
98       -data string
99              String  may  be  any value; it specifies the user_data field for
100              the event.  Only valid for virtual events.  Corresponds  to  the
101              %d substitution for virtual events in binding scripts.
102
103       -delta number
104              Number must be an integer;  it specifies the delta field for the
105              MouseWheel event.  The delta refers to the direction and  magni‐
106              tude  the  mouse  wheel  was  rotated.   Note the value is not a
107              screen distance but are units of  motion  in  the  mouse  wheel.
108              Typically  these  values are multiples of 120.  For example, 120
109              should scroll the text widget up 4 lines and -240  would  scroll
110              the  text  widget  down  8  lines.  Of course, other widgets may
111              define different behaviors for mouse wheel motion.   This  field
112              corresponds to the %D substitution for binding scripts.
113
114       -detail detail
115              Detail  specifies the detail field for the event and must be one
116              of the following:
117
118                     NotifyAncestor          NotifyNonlinearVirtual
119                     NotifyDetailNone        NotifyPointer
120                     NotifyInferior          NotifyPointerRoot
121                     NotifyNonlinear         NotifyVirtual
122
123              Valid for Enter, Leave, FocusIn  and  FocusOut  events.   Corre‐
124              sponds to the %d substitution for binding scripts.
125
126       -focus boolean
127              Boolean  must  be a boolean value;  it specifies the focus field
128              for the event.  Valid for Enter and Leave  events.   Corresponds
129              to the %f substitution for binding scripts.
130
131       -height size
132              Size  must  be a screen distance;  it specifies the height field
133              for the event.  Valid for Configure events.  Corresponds to  the
134              %h substitution for binding scripts.
135
136       -keycode number
137              Number   must be an integer;  it specifies the keycode field for
138              the event.  Valid for KeyPress and  KeyRelease  events.   Corre‐
139              sponds to the %k substitution for binding scripts.
140
141       -keysym name
142              Name  must  be  the name of a valid keysym, such as g, space, or
143              Return;  its corresponding keycode value is used as the  keycode
144              field  for  event,  overriding  any detail specified in the base
145              event argument.  Valid for KeyPress and KeyRelease events.  Cor‐
146              responds to the %K substitution for binding scripts.
147
148       -mode notify
149              Notify specifies the mode field for the event and must be one of
150              NotifyNormal, NotifyGrab, NotifyUngrab,  or  NotifyWhileGrabbed.
151              Valid  for  Enter,  Leave, FocusIn, and FocusOut events.  Corre‐
152              sponds to the %m substitution for binding scripts.
153
154       -override boolean
155              Boolean must be a boolean value;  it specifies the  override_re‐
156              direct  field  for the event.  Valid for Map, Reparent, and Con‐
157              figure events.  Corresponds to the %o substitution  for  binding
158              scripts.
159
160       -place where
161              Where  specifies  the  place  field  for  the event;  it must be
162              either PlaceOnTop or PlaceOnBottom.  Valid for Circulate events.
163              Corresponds to the %p substitution for binding scripts.
164
165       -root window
166              Window  must  be  either a window path name or an integer window
167              identifier;  it specifies the root field for the  event.   Valid
168              for  KeyPress,  KeyRelease,  ButtonPress,  ButtonRelease, Enter,
169              Leave, and Motion events.  Corresponds to  the  %R  substitution
170              for binding scripts.
171
172       -rootx coord
173              Coord  must be a screen distance;  it specifies the x_root field
174              for the event.  Valid  for  KeyPress,  KeyRelease,  ButtonPress,
175              ButtonRelease,  Enter, Leave, and Motion events.  Corresponds to
176              the %X substitution for binding scripts.
177
178       -rooty coord
179              Coord must be a screen distance;  it specifies the y_root  field
180              for  the  event.   Valid  for KeyPress, KeyRelease, ButtonPress,
181              ButtonRelease, Enter, Leave, and Motion events.  Corresponds  to
182              the %Y substitution for binding scripts.
183
184       -sendevent boolean
185              Boolean  must  be  a boolean value;  it specifies the send_event
186              field for the event.  Valid for all events.  Corresponds to  the
187              %E substitution for binding scripts.
188
189       -serial number
190              Number  must  be  an integer;  it specifies the serial field for
191              the event.  Valid for all events.  Corresponds to the %# substi‐
192              tution for binding scripts.
193
194       -state state
195              State  specifies  the  state field for the event.  For KeyPress,
196              KeyRelease, ButtonPress, ButtonRelease, Enter, Leave, and Motion
197              events  it  must  be an integer value.  For Visibility events it
198              must  be  one  of  VisibilityUnobscured,  VisibilityPartiallyOb‐
199              scured,  or  VisibilityFullyObscured.  This option overrides any
200              modifiers such as Meta or Control specified in the  base  event.
201              Corresponds to the %s substitution for binding scripts.
202
203       -subwindow window
204              Window  specifies the subwindow field for the event, either as a
205              path name for a Tk widget or as an  integer  window  identifier.
206              Valid  for  KeyPress,  KeyRelease,  ButtonPress,  ButtonRelease,
207              Enter, Leave, and Motion events.  Similar to %S substitution for
208              binding scripts.
209
210       -time integer
211              Integer  must  be an integer value;  it specifies the time field
212              for the event. Additonally the special value current is allowed,
213              this value will be substituted by the current event time.  Valid
214              for KeyPress,  KeyRelease,  ButtonPress,  ButtonRelease,  Enter,
215              Leave,  Motion, and Property events.  Corresponds to the %t sub‐
216              stitution for binding scripts.
217
218       -warp boolean
219              boolean must be a  boolean  value;   it  specifies  whether  the
220              screen  pointer  should  be warped as well.  Valid for KeyPress,
221              KeyRelease, ButtonPress, ButtonRelease, and Motion events.   The
222              pointer will only warp to a window if it is mapped.
223
224       -width size
225              Size  must  be  a screen distance;  it specifies the width field
226              for the event.  Valid for Configure events.  Corresponds to  the
227              %w substitution for binding scripts.
228
229       -when when
230              When  determines when the event will be processed;  it must have
231              one of the following values:
232
233              now       Process the  event  immediately,  before  the  command
234                        returns.   This  also  happens  if the -when option is
235                        omitted.
236
237              tail      Place the event on Tcl's event queue behind any events
238                        already queued for this application.
239
240              head      Place  the event at the front of Tcl's event queue, so
241                        that it  will  be  handled  before  any  other  events
242                        already queued.
243
244              mark      Place  the event at the front of Tcl's event queue but
245                        behind any other  events  already  queued  with  -when
246                        mark.   This option is useful when generating a series
247                        of events that should be processed in order but at the
248                        front of the queue.
249
250       -x coord
251              Coord  must  be a screen distance;  it specifies the x field for
252              the event.  Valid for KeyPress, KeyRelease, ButtonPress, Button‐
253              Release,  Motion,  Enter, Leave, Expose, Configure, Gravity, and
254              Reparent events.  Corresponds to the %x substitution for binding
255              scripts.   If  Window is empty the coordinate is relative to the
256              screen, and this option corresponds to the %X  substitution  for
257              binding scripts.
258
259       -y coord
260              Coord  must  be a screen distance;  it specifies the y field for
261              the event.  Valid for KeyPress, KeyRelease, ButtonPress, Button‐
262              Release,  Motion,  Enter, Leave, Expose, Configure, Gravity, and
263              Reparent events.  Corresponds to the %y substitution for binding
264              scripts.   If  Window is empty the coordinate is relative to the
265              screen, and this option corresponds to the %Y  substitution  for
266              binding scripts.
267
268       Any  options that are not specified when generating an event are filled
269       with the value 0, except for serial, which is filled with  the  next  X
270       event serial number.
271

PREDEFINED VIRTUAL EVENTS

273       Tk  defines  the following virtual events for the purposes of notifica‐
274       tion:
275
276       <<AltUnderlined>>
277              This is sent to widget to notify  it  that  the  letter  it  has
278              underlined  (as  an  accelerator  indicator) with the -underline
279              option has been pressed in combination with  the  Alt  key.  The
280              usual  response  to  this is to either focus into the widget (or
281              some related widget) or to invoke the widget.
282
283       <<Invoke>>
284              This can be sent to some widgets (e.g. button, listbox, menu) as
285              an alternative to <space>.
286
287       <<ListboxSelect>>
288              This  is  sent  to a listbox when the set of selected item(s) in
289              the listbox is updated.
290
291       <<MenuSelect>>
292              This is sent to a menu when the currently selected item  in  the
293              menu changes. It is intended for use with context-sensitive help
294              systems.
295
296       <<Modified>>
297              This is sent to a text widget when the contents  of  the  widget
298              are changed.
299
300       <<Selection>>
301              This  is  sent to a text widget when the selection in the widget
302              is changed.
303
304       <<ThemeChanged>>
305              This is sent to all widgets when the ttk theme changed. The  ttk
306              widgets  listen  to  this event and redisplay themselves when it
307              fires.  The legacy widgets ignore this event.
308
309       <<TraverseIn>>
310              This is sent to a  widget  when  the  focus  enters  the  widget
311              because of a user-driven “tab to widget” action.
312
313       <<TraverseOut>>
314              This  is  sent  to  a  widget  when  the focus leaves the widget
315              because of a user-driven “tab to widget” action.
316
317       <<UndoStack>>
318              This is sent to a text widget when its undo stack or redo  stack
319              becomes empty or unempty.
320
321       <<WidgetViewSync>>
322              This  is  sent  to  a  text widget when its internal data become
323              obsolete, and again when these internal data are  back  in  sync
324              with  the  widget  view.  The  detail field (%d substitution) is
325              either true (when the widget is in sync) or false  (when  it  is
326              not).
327
328       Tk  defines  the  following virtual events for the purposes of unifying
329       bindings across multiple platforms. Users expect them to behave in  the
330       following way:
331
332       <<Clear>>
333              Delete the currently selected widget contents.
334
335       <<Copy>>
336              Copy the currently selected widget contents to the clipboard.
337
338       <<Cut>>
339              Move the currently selected widget contents to the clipboard.
340
341       <<LineEnd>>
342              Move  to  the  end of the line in the current widget while dese‐
343              lecting any selected contents.
344
345       <<LineStart>>
346              Move to the start of the line in the current widget while  dese‐
347              lecting any selected contents.
348
349       <<NextChar>>
350              Move  to  the next item (i.e., visible character) in the current
351              widget while deselecting any selected contents.
352
353       <<NextLine>>
354              Move to the next line in the current  widget  while  deselecting
355              any selected contents.
356
357       <<NextPara>>
358              Move to the next paragraph in the current widget while deselect‐
359              ing any selected contents.
360
361       <<NextWord>>
362              Move to the next group of items (i.e., visible word) in the cur‐
363              rent widget while deselecting any selected contents.
364
365       <<Paste>>
366              Replace the currently selected widget contents with the contents
367              of the clipboard.
368
369       <<PasteSelection>>
370              Insert the contents of the  selection  at  the  mouse  location.
371              (This event has meaningful %x and %y substitutions).
372
373       <<PrevChar>>
374              Move  to the previous item (i.e., visible character) in the cur‐
375              rent widget while deselecting any selected contents.
376
377       <<PrevLine>>
378              Move to the previous line in the current widget while  deselect‐
379              ing any selected contents.
380
381       <<PrevPara>>
382              Move to the previous paragraph in the current widget while dese‐
383              lecting any selected contents.
384
385       <<PrevWindow>>
386              Traverse to the previous window.
387
388       <<PrevWord>>
389              Move to the previous group of items (i.e., visible word) in  the
390              current widget while deselecting any selected contents.
391
392       <<Redo>>
393              Redo one undone action.
394
395       <<SelectAll>>
396              Set the range of selected contents to the complete widget.
397
398       <<SelectLineEnd>>
399              Move  to the end of the line in the current widget while extend‐
400              ing the range of selected contents.
401
402       <<SelectLineStart>>
403              Move to the start of  the  line  in  the  current  widget  while
404              extending the range of selected contents.
405
406       <<SelectNextChar>>
407              Move  to  the next item (i.e., visible character) in the current
408              widget while extending the range of selected contents.
409
410       <<SelectNextLine>>
411              Move to the next line in the current widget while extending  the
412              range of selected contents.
413
414       <<SelectNextPara>>
415              Move to the next paragraph in the current widget while extending
416              the range of selected contents.
417
418       <<SelectNextWord>>
419              Move to the next group of items (i.e., visible word) in the cur‐
420              rent widget while extending the range of selected contents.
421
422       <<SelectNone>>
423              Reset the range of selected contents to be empty.
424
425       <<SelectPrevChar>>
426              Move  to the previous item (i.e., visible character) in the cur‐
427              rent widget while extending the range of selected contents.
428
429       <<SelectPrevLine>>
430              Move to the previous line in the current widget while  extending
431              the range of selected contents.
432
433       <<SelectPrevPara>>
434              Move  to  the  previous  paragraph  in  the current widget while
435              extending the range of selected contents.
436
437       <<SelectPrevWord>>
438              Move to the previous group of items (i.e., visible word) in  the
439              current widget while extending the range of selected contents.
440
441       <<ToggleSelection>>
442              Toggle the selection.
443
444       <<Undo>>
445              Undo the last action.
446

EXAMPLES

448   MAPPING KEYS TO VIRTUAL EVENTS
449       In  order  for a virtual event binding to trigger, two things must hap‐
450       pen.  First, the virtual event must be defined with the event add  com‐
451       mand.  Second, a binding must be created for the virtual event with the
452       bind command.  Consider the following virtual event definitions:
453
454              event add <<Paste>> <Control-y>
455              event add <<Paste>> <Button-2>
456              event add <<Save>> <Control-X><Control-S>
457              event add <<Save>> <Shift-F12>
458              if {[tk windowingsystem] eq "aqua"} {
459                  event add <<Save>> <Command-s>
460              }
461
462       In the bind command, a virtual  event  can  be  bound  like  any  other
463       builtin event type as follows:
464
465              bind Entry <<Paste>> {%W insert [selection get]}
466
467       The  double  angle brackets are used to specify that a virtual event is
468       being bound.  If the user types Control-y or presses button 2, or if  a
469       <<Paste>>  virtual  event  is synthesized with event generate, then the
470       <<Paste>> binding will be invoked.
471
472       If a virtual binding has the exact same sequence as a separate physical
473       binding,  then the physical binding will take precedence.  Consider the
474       following example:
475
476              event add <<Paste>> <Control-y> <Meta-Control-y>
477              bind Entry <Control-y> {puts Control-y}
478              bind Entry <<Paste>> {puts Paste}
479
480       When the user types Control-y the <Control-y> binding will be  invoked,
481       because  a  physical  event  is considered more specific than a virtual
482       event, all other things being equal.   However,  when  the  user  types
483       Meta-Control-y  the <<Paste>> binding will be invoked, because the Meta
484       modifier in the physical pattern associated with the virtual binding is
485       more specific than the <Control-y> sequence for the physical event.
486
487       Bindings  on  a  virtual  event may be created before the virtual event
488       exists.  Indeed, the virtual event never actually needs to be  defined,
489       for  instance,  on  platforms where the specific virtual event would be
490       meaningless or ungeneratable.
491
492       When a definition of a virtual event changes at run time,  all  windows
493       will respond immediately to the new definition.  Starting from the pre‐
494       ceding example, if the following code is executed:
495
496              bind Entry <Control-y> {}
497              event add <<Paste>> <Key-F6>
498
499       the behavior will  change  such  in  two  ways.   First,  the  shadowed
500       <<Paste>>  binding will emerge.  Typing Control-y will no longer invoke
501       the  <Control-y>  binding,  but  instead  invoke  the   virtual   event
502       <<Paste>>.   Second,  pressing  the  F6  key  will  now also invoke the
503       <<Paste>> binding.
504
505   MOVING THE MOUSE POINTER
506       Sometimes it is useful to be able to really move the mouse pointer. For
507       example,  if  you  have  some software that is capable of demonstrating
508       directly to the user how to use the program. To do this,  you  need  to
509       “warp” the mouse around by using event generate, like this:
510
511              for {set xy 0} {$xy < 200} {incr xy} {
512                  event generate . <Motion> -x $xy -y $xy -warp 1
513                  update
514                  after 50
515              }
516
517       Note  that it is usually considered bad style to move the mouse pointer
518       for the user because it removes control from them. Therefore this tech‐
519       nique  should be used with caution. Also note that it is not guaranteed
520       to function on all platforms.
521

SEE ALSO

523       bind(n)
524

KEYWORDS

526       event, binding, define, handle, virtual event
527
528
529
530Tk                                    8.3                             event(n)
Impressum