1event(3) User Contributed Perl Documentation event(3)
2
3
4
6 Tk::event - Miscellaneous event facilities: define virtual events and
7 generate events
8
10 $widget->eventAction(?arg, arg, ...?);
11
13 The eventAction methods provides several facilities for dealing with
14 window system events, such as defining virtual events and synthesizing
15 events. Virtual events are shared by all widgets of the same
16 MainWindow. Different MainWindows can have different virtual event.
17
18 The following methods are currently supported:
19
20 $widget->eventAdd('<<virtual>>', sequence ?,sequence, ...?)
21 Associates the virtual event virtual with the physical event
22 sequence(s) given by the sequence arguments, so that the virtual
23 event will trigger whenever any one of the sequences occurs.
24 Virtual may be any string value and sequence may have any of the
25 values allowed for the sequence argument to the bind method. If
26 virtual is already defined, the new physical event sequences add to
27 the existing sequences for the event.
28
29 $widget->eventDelete('<<virtual>>' ?,sequence, sequence, ...?)
30 Deletes each of the sequences from those associated with the
31 virtual event given by virtual. Virtual may be any string value
32 and sequence may have any of the values allowed for the sequence
33 argument to the bind method. Any sequences not currently
34 associated with virtual are ignored. If no sequence argument is
35 provided, all physical event sequences are removed for virtual, so
36 that the virtual event will not trigger anymore.
37
38 $widget->eventGenerate(event ?,option => value, option => value, ...?)
39 Generates a window event and arranges for it to be processed just
40 as if it had come from the window system. $window is a reference
41 to the window for which the event will be generated. Event
42 provides a basic description of the event, such as <Shift-Button-2>
43 or <<Paste>>. If Window is empty the whole screen is meant, and
44 coordinates are relative to the screen. Event may have any of the
45 forms allowed for the sequence argument of the bind method except
46 that it must consist of a single event pattern, not a sequence.
47 Option-value pairs may be used to specify additional attributes of
48 the event, such as the x and y mouse position; see "EVENT FIELDS"
49 below. If the -when option is not specified, the event is
50 processed immediately: all of the handlers for the event will
51 complete before the eventGenerate method returns. If the -when
52 option is specified then it determines when the event is processed.
53
54 $widget->eventInfo(?'<<virtual>>'?)
55 Returns information about virtual events. If the <<virtual>>
56 argument is omitted, the return value is a list of all the virtual
57 events that are currently defined. If <<virtual>> is specified
58 then the return value is a list whose elements are the physical
59 event sequences currently defined for the given virtual event; if
60 the virtual event is not defined then undef is returned.
61
63 The following options are supported for the eventGenerate method.
64 These correspond to the ``%'' expansions allowed in binding callback
65 for the bind method.
66
67 -above => window
68 Window specifies the above field for the event, either as a window
69 path name or as an integer window id. Valid for Configure events.
70 Corresponds to the %a substitution for binding scripts.
71
72 -borderwidth => size
73 Size must be a screen distance; it specifies the border_width
74 field for the event. Valid for Configure events. Corresponds to
75 the %B substitution for binding scripts.
76
77 -button => number
78 Number must be an integer; it specifies the detail field for a
79 ButtonPress or ButtonRelease event, overriding any button number
80 provided in the base event argument. Corresponds to the %b
81 substitution for binding scripts.
82
83 -count => number
84 Number must be an integer; it specifies the count field for the
85 event. Valid for Expose events. Corresponds to the %c
86 substitution for binding scripts.
87
88 -delta => number
89 number must be an integer; it specifies the delta field for the
90 MouseWheel event. The delta refers to the direction and magnitude
91 the mouse wheel was rotated. Note the value is not a screen
92 distance but are units of motion in the mouse wheel. Typically
93 these values are multiples of 120. For example, 120 should scroll
94 the text widget up 4 lines and -240 would scroll the text widget
95 down 8 lines. Of course, other widgets may define different
96 behaviors for mouse wheel motion. This field corresponds to the %D
97 substitution for binding scripts.
98
99 -detail => detail
100 Detail specifies the detail field for the event and must be one of
101 the following:
102
103 NotifyAncestor NotifyNonlinearVirtual
104 NotifyDetailNone NotifyPointer
105 NotifyInferior NotifyPointerRoot
106 NotifyNonlinear NotifyVirtual
107
108 Valid for Enter, Leave, FocusIn and FocusOut events. Corresponds
109 to the %d substitution for binding scripts.
110
111 -focus boolean
112 Boolean must be a boolean value; it specifies the focus field for
113 the event. Valid for Enter and Leave events. Corresponds to the
114 %f substitution for binding scripts.
115
116 -height size
117 Size must be a screen distance; it specifies the height field for
118 the event. Valid for Configure events. Corresponds to the %h
119 substitution for binding scripts.
120
121 -keycode number
122 Number must be an integer; it specifies the keycode field for the
123 event. Valid for KeyPress and KeyRelease events. Corresponds to
124 the %k substitution for binding scripts.
125
126 -keysym name
127 Name must be the name of a valid keysym, such as g, space, or
128 Return; its corresponding keycode value is used as the keycode
129 field for event, overriding any detail specified in the base event
130 argument. Valid for KeyPress and KeyRelease events. Corresponds
131 to the %K substitution for binding scripts.
132
133 -mode notify
134 Notify specifies the mode field for the event and must be one of
135 NotifyNormal, NotifyGrab, NotifyUngrab, or NotifyWhileGrabbed.
136 Valid for Enter, Leave, FocusIn, and FocusOut events. Corresponds
137 to the %m substitution for binding scripts.
138
139 -override boolean
140 Boolean must be a boolean value; it specifies the
141 override_redirect field for the event. Valid for Map, Reparent,
142 and Configure events. Corresponds to the %o substitution for
143 binding scripts.
144
145 -place where
146 Where specifies the place field for the event; it must be either
147 PlaceOnTop or PlaceOnBottom. Valid for Circulate events.
148 Corresponds to the %p substitution for binding scripts.
149
150 -root window
151 Window must be either a window path name or an integer window
152 identifier; it specifies the root field for the event. Valid for
153 KeyPress, KeyRelease, ButtonPress, ButtonRelease, Enter, Leave, and
154 Motion events. Corresponds to the %R substitution for binding
155 scripts.
156
157 -rootx coord
158 Coord must be a screen distance; it specifies the x_root field for
159 the event. Valid for KeyPress, KeyRelease, ButtonPress,
160 ButtonRelease, Enter, Leave, and Motion events. Corresponds to the
161 %X substitution for binding scripts.
162
163 -rooty coord
164 Coord must be a screen distance; it specifies the y_root field for
165 the event. Valid for KeyPress, KeyRelease, ButtonPress,
166 ButtonRelease, Enter, Leave, and Motion events. Corresponds to the
167 %Y substitution for binding scripts.
168
169 -sendevent boolean
170 Boolean must be a boolean value; it specifies the send_event field
171 for the event. Valid for all events. Corresponds to the %E
172 substitution for binding scripts.
173
174 -serial number
175 Number must be an integer; it specifies the serial field for the
176 event. Valid for all events. Corresponds to the %# substitution
177 for binding scripts.
178
179 -state state
180 State specifies the state field for the event. For KeyPress,
181 KeyRelease, ButtonPress, ButtonRelease, Enter, Leave, and Motion
182 events it must be an integer value. For Visibility events it must
183 be one of VisibilityUnobscured, VisibilityPartiallyObscured, or
184 VisibilityFullyObscured. This option overrides any modifiers such
185 as Meta or Control specified in the base event. Corresponds to the
186 %s substitution for binding scripts.
187
188 -subwindow window
189 Window specifies the subwindow field for the event, either as a
190 path name for a Tk widget or as an integer window identifier.
191 Valid for KeyPress, KeyRelease, ButtonPress, ButtonRelease, Enter,
192 Leave, and Motion events. Similar to %S substitution for binding
193 scripts.
194
195 -time integer
196 Integer must be an integer value; it specifies the time field for
197 the event. Valid for KeyPress, KeyRelease, ButtonPress,
198 ButtonRelease, Enter, Leave, Motion, and Property events.
199 Corresponds to the %t substitution for binding scripts.
200
201 -warp boolean
202 boolean must be a boolean value; it specifies whether the screen
203 pointer should be warped as well. Valid for KeyPress, KeyRelease,
204 ButtonPress, ButtonRelease, and Motion events.
205
206 -width size
207 Size must be a screen distance; it specifies the width field for
208 the event. Valid for Configure events. Corresponds to the %w
209 substitution for binding scripts.
210
211 -when when
212 When determines when the event will be processed; it must have one
213 of the following values:
214
215 now Process the event immediately, before the command returns.
216 This also happens if the -when option is omitted.
217
218 tail Place the event on perl/Tk's event queue behind any events
219 already queued for this application.
220
221 head Place the event at the front of perl/Tk's event queue, so
222 that it will be handled before any other events already
223 queued.
224
225 mark Place the event at the front of perl/Tk's event queue but
226 behind any other events already queued with -when mark.
227 This option is useful when generating a series of events
228 that should be processed in order but at the front of the
229 queue.
230
231 -x coord
232 Coord must be a screen distance; it specifies the x field for the
233 event. Valid for KeyPress, KeyRelease, ButtonPress, ButtonRelease,
234 Motion, Enter, Leave, Expose, Configure, Gravity, and Reparent
235 events. Corresponds to the the %x substitution for binding
236 scripts. If Window is empty the coordinate is relative to the
237 screen, and this option corresponds to the %X substitution for
238 binding scripts.
239
240 -y coord
241 Coord must be a screen distance; it specifies the y field for the
242 event. Valid for KeyPress, KeyRelease, ButtonPress, ButtonRelease,
243 Motion, Enter, Leave, Expose, Configure, Gravity, and Reparent
244 events. Corresponds to the the %y substitution for binding
245 scripts. If Window is empty the coordinate is relative to the
246 screen, and this option corresponds to the %Y substitution for
247 binding scripts.
248
249 Any options that are not specified when generating an event are
250 filled with the value 0, except for serial, which is filled with
251 the next X event serial number.
252
254 In order for a virtual event binding to trigger, two things must
255 happen. First, the virtual event must be defined with the eventAdd
256 method. Second, a binding must be created for the virtual event with
257 the bind method. Consider the following virtual event definitions:
258
259 $widget->eventAdd('<<Paste>>' => '<Control-y>');
260 $widget->eventAdd('<<Paste>>' => '<Button-2>');
261 $widget->eventAdd('<<Save>>' => '<Control-X><Control-S>');
262 $widget->eventAdd('<<Save>>' => '<Shift-F12>');
263
264 In the bind method, a virtual event can be bound like any other builtin
265 event type as follows:
266
267 $entry->bind('Tk::Entry', '<<Paste>>' => sub {
268 $entry->Insert($entry->selectionGet) });
269
270 The double angle brackets are used to specify that a virtual event is
271 being bound. If the user types Control-y or presses button 2, or if a
272 <<Paste>> virtual event is synthesized with eventGenerate, then the
273 <<Paste>> binding will be invoked.
274
275 If a virtual binding has the exact same sequence as a separate physical
276 binding, then the physical binding will take precedence. Consider the
277 following example:
278
279 $mw->eventAdd('<<Paste>>' => '<Control-y>','<Meta-Control-y>');
280 $mw->bind('Tk::Entry', '<Control-y>' => sub{print 'Control-y'});
281 $mw->bind('Tk::Entry', '<<Paste>>' => sub{print 'Paste'});
282
283 When the user types Control-y the <Control-y> binding will be invoked,
284 because a physical event is considered more specific than a virtual
285 event, all other things being equal. However, when the user types
286 Meta-Control-y the <<Paste>> binding will be invoked, because the Meta
287 modifier in the physical pattern associated with the virtual binding is
288 more specific than the <Control-y> sequence for the physical event.
289
290 Bindings on a virtual event may be created before the virtual event
291 exists. Indeed, the virtual event never actually needs to be defined,
292 for instance, on platforms where the specific virtual event would
293 meaningless or ungeneratable.
294
295 When a definition of a virtual event changes at run time, all windows
296 will respond immediately to the new definition. Starting from the
297 preceding example, if the following code is executed:
298
299 $entry->bind(ref($entry), '<Control-y>' => undef);
300 $entry->eventAdd('<<Paste>>' => '<Key-F6>');
301
302 the behavior will change such in two ways. First, the shadowed
303 <<Paste>> binding will emerge. Typing Control-y will no longer invoke
304 the <Control-y> binding, but instead invoke the virtual event
305 <<Paste>>. Second, pressing the F6 key will now also invoke the
306 <<Paste>> binding.
307
309 Tk::bind Tk::callbacks
310
312 event, binding, define, handle, virtual event
313
314
315
316perl v5.12.0 2010-05-13 event(3)