Tk::bind can arrange for X events to invoke callbacks.
Associate and destroy bindings:
The bind method associates callbacks with X events. If callback is specified, bind will arrange for callback to be evaluated whenever the event(s) given by sequence occur in the window(s) identified by $widget or tag. If callback is an empty string then the current binding for sequence is destroyed, leaving sequence unbound. In all of the cases where a callback argument is provided, bind returns an empty string.
If sequence is specified without a callback, then the callback currently bound to sequence is returned, or undef is returned if there is no binding for sequence. If neither sequence nor callback is specified, then the return value is a list whose elements are all the sequences for which there exist bindings for tag.
If no tag is specified then the bind refers to $widget. If tag is specified then it is typically a class name and the bind refers to all instances of the class on the MainWindow associated with $widget. (It is possible for tag to be another "widget object" but this practice is deprecated.) Perl's ref($object) can be used to get the class name of any object. Each window has an associated list of tags, and a binding applies to a particular window if its tag is among those specified for the window. Although the bindtags method may be used to assign an arbitrary set of binding tags to a window, the default binding tags provide the following behavior:
If a tag is the name of an internal window the binding applies to that window.
If the tag is the name of a toplevel window the binding applies to the toplevel window and all its internal windows.
If the tag is the name of a class of widgets, such as Tk::Button, the binding applies to all widgets in that class;
If tag has the value all, the binding applies to all windows descended from the MainWindow of the application.