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 MainWin‐
16 dow. 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. Vir‐
24 tual may be any string value and sequence may have any of the val‐
25 ues allowed for the sequence argument to the bind method. If vir‐
26 tual 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 vir‐
31 tual event given by virtual. Virtual may be any string value and
32 sequence may have any of the values allowed for the sequence argu‐
33 ment to the bind method. Any sequences not currently associated
34 with virtual are ignored. If no sequence argument is provided, all
35 physical event sequences are removed for virtual, so that the vir‐
36 tual 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 pro‐
42 vides a basic description of the event, such as <Shift-Button-2> or
43 <<Paste>>. If Window is empty the whole screen is meant, and coor‐
44 dinates 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 pro‐
50 cessed immediately: all of the handlers for the event will com‐
51 plete before the eventGenerate method returns. If the -when option
52 is specified then it determines when the event is processed.
53
54 $widget->eventInfo(?'<<virtual>>'?)
55 Returns information about virtual events. If the <<virtual>> argu‐
56 ment 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 substi‐
81 tution 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 substitu‐
86 tion 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 dis‐
92 tance but are units of motion in the mouse wheel. Typically these
93 values are multiples of 120. For example, 120 should scroll the
94 text widget up 4 lines and -240 would scroll the text widget down 8
95 lines. Of course, other widgets may define different behaviors for
96 mouse wheel motion. This field corresponds to the %D substitution
97 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 sub‐
119 stitution 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 override_redi‐
141 rect field for the event. Valid for Map, Reparent, and Configure
142 events. Corresponds to the %o substitution for binding scripts.
143
144 -place where
145 Where specifies the place field for the event; it must be either
146 PlaceOnTop or PlaceOnBottom. Valid for Circulate events. Corre‐
147 sponds to the %p substitution for binding scripts.
148
149 -root window
150 Window must be either a window path name or an integer window iden‐
151 tifier; it specifies the root field for the event. Valid for Key‐
152 Press, KeyRelease, ButtonPress, ButtonRelease, Enter, Leave, and
153 Motion events. Corresponds to the %R substitution for binding
154 scripts.
155
156 -rootx coord
157 Coord must be a screen distance; it specifies the x_root field for
158 the event. Valid for KeyPress, KeyRelease, ButtonPress, ButtonRe‐
159 lease, Enter, Leave, and Motion events. Corresponds to the %X sub‐
160 stitution for binding scripts.
161
162 -rooty coord
163 Coord must be a screen distance; it specifies the y_root field for
164 the event. Valid for KeyPress, KeyRelease, ButtonPress, ButtonRe‐
165 lease, Enter, Leave, and Motion events. Corresponds to the %Y sub‐
166 stitution for binding scripts.
167
168 -sendevent boolean
169 Boolean must be a boolean value; it specifies the send_event field
170 for the event. Valid for all events. Corresponds to the %E sub‐
171 stitution for binding scripts.
172
173 -serial number
174 Number must be an integer; it specifies the serial field for the
175 event. Valid for all events. Corresponds to the %# substitution
176 for binding scripts.
177
178 -state state
179 State specifies the state field for the event. For KeyPress,
180 KeyRelease, ButtonPress, ButtonRelease, Enter, Leave, and Motion
181 events it must be an integer value. For Visibility events it must
182 be one of VisibilityUnobscured, VisibilityPartiallyObscured, or
183 VisibilityFullyObscured. This option overrides any modifiers such
184 as Meta or Control specified in the base event. Corresponds to the
185 %s substitution for binding scripts.
186
187 -subwindow window
188 Window specifies the subwindow field for the event, either as a
189 path name for a Tk widget or as an integer window identifier.
190 Valid for KeyPress, KeyRelease, ButtonPress, ButtonRelease, Enter,
191 Leave, and Motion events. Similar to %S substitution for binding
192 scripts.
193
194 -time integer
195 Integer must be an integer value; it specifies the time field for
196 the event. Valid for KeyPress, KeyRelease, ButtonPress, ButtonRe‐
197 lease, Enter, Leave, Motion, and Property events. Corresponds to
198 the %t substitution for binding scripts.
199
200 -warp boolean
201 boolean must be a boolean value; it specifies whether the screen
202 pointer should be warped as well. Valid for KeyPress, KeyRelease,
203 ButtonPress, ButtonRelease, and Motion events.
204
205 -width size
206 Size must be a screen distance; it specifies the width field for
207 the event. Valid for Configure events. Corresponds to the %w sub‐
208 stitution for binding scripts.
209
210 -when when
211 When determines when the event will be processed; it must have one
212 of the following values:
213
214 now Process the event immediately, before the command returns.
215 This also happens if the -when option is omitted.
216
217 tail Place the event on perl/Tk's event queue behind any events
218 already queued for this application.
219
220 head Place the event at the front of perl/Tk's event queue, so
221 that it will be handled before any other events already
222 queued.
223
224 mark Place the event at the front of perl/Tk's event queue but
225 behind any other events already queued with -when mark.
226 This option is useful when generating a series of events
227 that should be processed in order but at the front of the
228 queue.
229
230 -x coord
231 Coord must be a screen distance; it specifies the x field for the
232 event. Valid for KeyPress, KeyRelease, ButtonPress, ButtonRelease,
233 Motion, Enter, Leave, Expose, Configure, Gravity, and Reparent
234 events. Corresponds to the the %x substitution for binding
235 scripts. If Window is empty the coordinate is relative to the
236 screen, and this option corresponds to the %X substitution for
237 binding scripts.
238
239 -y coord
240 Coord must be a screen distance; it specifies the y field for the
241 event. Valid for KeyPress, KeyRelease, ButtonPress, ButtonRelease,
242 Motion, Enter, Leave, Expose, Configure, Gravity, and Reparent
243 events. Corresponds to the the %y substitution for binding
244 scripts. If Window is empty the coordinate is relative to the
245 screen, and this option corresponds to the %Y substitution for
246 binding scripts.
247
248 Any options that are not specified when generating an event are
249 filled with the value 0, except for serial, which is filled with
250 the next X event serial number.
251
253 In order for a virtual event binding to trigger, two things must hap‐
254 pen. First, the virtual event must be defined with the eventAdd
255 method. Second, a binding must be created for the virtual event with
256 the bind method. Consider the following virtual event definitions:
257
258 $widget->eventAdd('<<Paste>>' => '<Control-y>');
259 $widget->eventAdd('<<Paste>>' => '<Button-2>');
260 $widget->eventAdd('<<Save>>' => '<Control-X><Control-S>');
261 $widget->eventAdd('<<Save>>' => '<Shift-F12>');
262
263 In the bind method, a virtual event can be bound like any other builtin
264 event type as follows:
265
266 $entry->bind('Tk::Entry', '<<Paste>>' => sub {
267 $entry->Insert($entry->selectionGet) });
268
269 The double angle brackets are used to specify that a virtual event is
270 being bound. If the user types Control-y or presses button 2, or if a
271 <<Paste>> virtual event is synthesized with eventGenerate, then the
272 <<Paste>> binding will be invoked.
273
274 If a virtual binding has the exact same sequence as a separate physical
275 binding, then the physical binding will take precedence. Consider the
276 following example:
277
278 $mw->eventAdd('<<Paste>>' => '<Control-y>','<Meta-Control-y>');
279 $mw->bind('Tk::Entry', '<Control-y>' => sub{print 'Control-y'});
280 $mw->bind('Tk::Entry', '<<Paste>>' => sub{print 'Paste'});
281
282 When the user types Control-y the <Control-y> binding will be invoked,
283 because a physical event is considered more specific than a virtual
284 event, all other things being equal. However, when the user types
285 Meta-Control-y the <<Paste>> binding will be invoked, because the Meta
286 modifier in the physical pattern associated with the virtual binding is
287 more specific than the <Control-y> sequence for the physical event.
288
289 Bindings on a virtual event may be created before the virtual event
290 exists. Indeed, the virtual event never actually needs to be defined,
291 for instance, on platforms where the specific virtual event would mean‐
292 ingless or ungeneratable.
293
294 When a definition of a virtual event changes at run time, all windows
295 will respond immediately to the new definition. Starting from the pre‐
296 ceding example, if the following code is executed:
297
298 $entry->bind(ref($entry), '<Control-y>' => undef);
299 $entry->eventAdd('<<Paste>>' => '<Key-F6>');
300
301 the behavior will change such in two ways. First, the shadowed
302 <<Paste>> binding will emerge. Typing Control-y will no longer invoke
303 the <Control-y> binding, but instead invoke the virtual event
304 <<Paste>>. Second, pressing the F6 key will now also invoke the
305 <<Paste>> binding.
306
308 Tk::bind Tk::callbacks
309
311 event, binding, define, handle, virtual event
312
313
314
315perl v5.8.8 2008-02-05 event(3)