Tk_CreateEventHandler(3tk)
π Tk_CreateEventHandler β the Tk Library Procedures girlies π
okay so bestie, you're in the Tk Library Procedures section and this page is all about Tk_CreateEventHandler, Tk_DeleteEventHandler, Tk_GetButtonMask and Tk_SendVirtualEvent. they all do one iconic thing: associate procedure callback with an X event β¨
πΈ NAME πΈ
Tk_CreateEventHandler, Tk_DeleteEventHandler, Tk_GetButtonMask, Tk_SendVirtualEvent β associate procedure callback with an X event π
β¨ SYNOPSIS β¨
#include <tk.h>
Tk_CreateEventHandler(tkwin, mask, proc, clientData)
Tk_DeleteEventHandler(tkwin, mask, proc, clientData)
Tk_GetButtonMask(button)
Tk_SendVirtualEvent(tkwin, eventName, detail)
π ARGUMENTS π
unsigned button(in) β the button number, bestie. just a number π’const char *eventName(in) β the name of the virtual event π¦Tcl_Obj *detail(in) β detail information for the virtual event. may beNULL, no biggie πTk_Window tkwin(in) β token for window in which events may occur πͺunsigned long mask(in) β bit-mask of events (likeButtonPressMask, iykyk) for which proc should be called π―Tk_EventProc *proc(in) β procedure to invoke whenever an event in mask occurs in the window given by tkwin πvoid *clientData(in) β arbitrary one-word value to pass to proc. yes, one word. keep it cute, keep it small π
π DESCRIPTION π
Tk_CreateEventHandler arranges for proc to be invoked in the future whenever one of the event types specified by mask occurs in the window specified by tkwin. the callback to proc gets made by Tk_HandleEvent β and the way that this mechanism only works is in programs that dispatch events through Tk_HandleEvent (or through other Tk procedures that call Tk_HandleEvent, like Tcl_DoOneEvent or Tk_MainLoop). so like, no dispatching, no callback. periodt π
Proc should have arguments and result that match the type Tk_EventProc:
typedef void Tk_EventProc(
void *clientData,
XEvent *eventPtr);
the clientData parameter to proc is a copy of the clientData argument you gave to Tk_CreateEventHandler back when the callback was created. typically, clientData points to a data structure containing application-specific information about the window in which the event occurred. and eventPtr is a pointer to the X event, which will be one of the ones specified in the mask argument to Tk_CreateEventHandler. literally just handing you back your own stuff π«Ά
Tk_DeleteEventHandler may be called to delete a previously-created event handler: it deletes the first handler it finds that is associated with tkwin and matches the mask, proc, and clientData arguments. if no such handler exists, then Tk_HandleEvent returns without doing anything. (yes, Tk_HandleEvent. that's what it says, bestie, we don't ask questions π)
ok so warning time π¨ β although Tk supports it, it's probably a bad idea to have more than one callback with the same mask, proc, and clientData arguments. just don't, ngl.
when a window is deleted, all of its handlers get deleted automatically, so in that case there is no need to call Tk_DeleteEventHandler at all. free cleanup, we love that π
if multiple handlers are declared for the same type of X event on the same window, then the handlers will be invoked in the order they were created. first come, first served, iconic π
Tk_GetButtonMask returns the button mask corresponding to the button. e.g. it will return Button1Mask for button Button1. π±οΈ
Tk_SendVirtualEvent sends a virtual event to Tk's event queue. that's it, that's the whole vibe β¨
π KEYWORDS π
bind, callback, event, handler
and that's the page, bestie!! this whole thing came to you from the Tk source, under the page name Tk_CreateEventHandler(3tk). go forth and handle those events, you absolute main character π¦πβ¨
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1990 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms