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 se‐
23              quence(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 de‐
111              fine 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 ei‐
162              ther 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, En‐
207              ter, 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  re‐
234                        turns.  This also happens if the -when option is omit‐
235                        ted.
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  al‐
242                        ready 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  un‐
278              derlined  (as  an accelerator indicator) with the -underline op‐
279              tion has been pressed in combination with the Alt key. The usual
280              response to this is to either focus into the widget (or some re‐
281              lated 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       <<TkWorldChanged>>
310              This event is sent to all widgets when a font  is  changed,  for
311              example,  by  the  use of [font configure].  The user_data field
312              (%d) will have the value "FontChanged".  For other  system  wide
313              changes,  this  event  will  be  sent  to  all  widgets, and the
314              user_data field will indicate the cause of  the  change.   NOTE:
315              all tk and ttk widgets already handle this event internally.
316
317       <<TraverseIn>>
318              This  is  sent  to a widget when the focus enters the widget be‐
319              cause of a user-driven “tab to widget” action.
320
321       <<TraverseOut>>
322              This is sent to a widget when the focus leaves  the  widget  be‐
323              cause of a user-driven “tab to widget” action.
324
325       <<UndoStack>>
326              This  is sent to a text widget when its undo stack or redo stack
327              becomes empty or unempty.
328
329       <<WidgetViewSync>>
330              This is sent to a text widget when its internal data become  ob‐
331              solete, and again when these internal data are back in sync with
332              the widget view. The detail field (%d  substitution)  is  either
333              true (when the widget is in sync) or false (when it is not).
334
335       Tk  defines  the  following virtual events for the purposes of unifying
336       bindings across multiple platforms. Users expect them to behave in  the
337       following way:
338
339       <<Clear>>
340              Delete the currently selected widget contents.
341
342       <<Copy>>
343              Copy the currently selected widget contents to the clipboard.
344
345       <<Cut>>
346              Move the currently selected widget contents to the clipboard.
347
348       <<LineEnd>>
349              Move  to  the  end of the line in the current widget while dese‐
350              lecting any selected contents.
351
352       <<LineStart>>
353              Move to the start of the line in the current widget while  dese‐
354              lecting any selected contents.
355
356       <<NextChar>>
357              Move  to  the next item (i.e., visible character) in the current
358              widget while deselecting any selected contents.
359
360       <<NextLine>>
361              Move to the next line in the current  widget  while  deselecting
362              any selected contents.
363
364       <<NextPara>>
365              Move to the next paragraph in the current widget while deselect‐
366              ing any selected contents.
367
368       <<NextWord>>
369              Move to the next group of items (i.e., visible word) in the cur‐
370              rent widget while deselecting any selected contents.
371
372       <<Paste>>
373              Replace the currently selected widget contents with the contents
374              of the clipboard.
375
376       <<PasteSelection>>
377              Insert the contents of the  selection  at  the  mouse  location.
378              (This event has meaningful %x and %y substitutions).
379
380       <<PrevChar>>
381              Move  to the previous item (i.e., visible character) in the cur‐
382              rent widget while deselecting any selected contents.
383
384       <<PrevLine>>
385              Move to the previous line in the current widget while  deselect‐
386              ing any selected contents.
387
388       <<PrevPara>>
389              Move to the previous paragraph in the current widget while dese‐
390              lecting any selected contents.
391
392       <<PrevWindow>>
393              Traverse to the previous window.
394
395       <<PrevWord>>
396              Move to the previous group of items (i.e., visible word) in  the
397              current widget while deselecting any selected contents.
398
399       <<Redo>>
400              Redo one undone action.
401
402       <<SelectAll>>
403              Set the range of selected contents to the complete widget.
404
405       <<SelectLineEnd>>
406              Move  to the end of the line in the current widget while extend‐
407              ing the range of selected contents.
408
409       <<SelectLineStart>>
410              Move to the start of the line in the current  widget  while  ex‐
411              tending the range of selected contents.
412
413       <<SelectNextChar>>
414              Move  to  the next item (i.e., visible character) in the current
415              widget while extending the range of selected contents.
416
417       <<SelectNextLine>>
418              Move to the next line in the current widget while extending  the
419              range of selected contents.
420
421       <<SelectNextPara>>
422              Move to the next paragraph in the current widget while extending
423              the range of selected contents.
424
425       <<SelectNextWord>>
426              Move to the next group of items (i.e., visible word) in the cur‐
427              rent widget while extending the range of selected contents.
428
429       <<SelectNone>>
430              Reset the range of selected contents to be empty.
431
432       <<SelectPrevChar>>
433              Move  to the previous item (i.e., visible character) in the cur‐
434              rent widget while extending the range of selected contents.
435
436       <<SelectPrevLine>>
437              Move to the previous line in the current widget while  extending
438              the range of selected contents.
439
440       <<SelectPrevPara>>
441              Move  to  the previous paragraph in the current widget while ex‐
442              tending the range of selected contents.
443
444       <<SelectPrevWord>>
445              Move to the previous group of items (i.e., visible word) in  the
446              current widget while extending the range of selected contents.
447
448       <<ToggleSelection>>
449              Toggle the selection.
450
451       <<Undo>>
452              Undo the last action.
453

EXAMPLES

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

SEE ALSO

530       bind(n)
531

KEYWORDS

533       event, binding, define, handle, virtual event
534
535
536
537Tk                                    8.3                             event(n)
Impressum