Whenever the user moves the mouse, clicks or releases a mouse button, or presses a key on the keyboard, an event is generated for some window. The window that receives the event depends on the current state of the graphic display:
When the user clicks in a window, the window ``grabs'' the mouse, so that all mouse events go to that window until the mouse button is released (regardless of the location of the cursor). As a result, a user can click on a scrollbar thumb and drag it without keeping the cursor strictly inside the scrollbar control.
Within a top-level window, only certain kinds of subwindows can have the focus, depending on the conventions of the platform. Furthermore, the subwindow that initially owns the focus is platform-specific. A user can moves the focus in various ways, usually by clicking the target window. A program can use the focus method to move the focus to a subwindow or to set the initial focus.
Controls, such as buttons and list boxes, handle keyboard and mouse events automatically, eventually invoking the callback procedure that was provided when the control was created. A canvas propagates mouse and keyboard events to its on-event and on-char methods, respectively.
A mouse and keyboard event is delivered in a special way to its window. Each ancestor of the receiving window gets a chance to intercept the event through the on-subwindow-event and on-subwindow-char methods. See the method descriptions for more information.
The default on-subwindow-char method for a
top-level window intercepts keyboard events to detect menu-shortcut
events and focus-navigation events. See
on-subwindow-char in frame% and
on-subwindow-char in dialog% for details. Certain
OS-specific key combinations are captured at a low level, and cannot
be overridden. For example, under Windows and X, pressing and
releasing Alt always moves the keyboard focus to the menu
bar. Similarly, Alt-Tab switches to a different application under
Windows.