An application program is notified of keyboard input via messages that are delivered to the associated window procedure or class. As a key is pressed and released, the keyboard driver passes messages to the operating system. The operating system saves the keystrokes in the form of messages in the system message queue. Messages are transferred from the system message queue to the message queue of an application one at a time. The window that receives these messages is the window with the input focus.
When a key is pressed on the keyboard, only one window ultimately receives the associated message. The window that receives keyboard input messages is the window with the input focus. The concept of input focus is closely related to the concept of the active window. The window with the input focus is either the active window or a child of the active window. The active window is able to be identified visually. If the active window has a title bar, the title bar is highlighted. If the active window has a dialog frame, the frame is highlighted. If the active window is minimized, the text displayed adjacent to the icon is highlighted.
A child window is never the active window. Controls such as list boxes, combo boxes and buttons of various types usually appear within a dialog. If one of these has the input focus, the active window is its containing parent. A child window usually indicates that it has the input focus visually. Some controls display a flashing caret while others draw a dotted rectangle etc.
If the active window has been minimized, no window has the input focus. In this case, the operating system continues to send keyboard messages to the program, but the messages differ in form to messages sent to an active window that is not minimized.
An application can monitor whether it has the input focus by intercepting the messages message::set_focus and message::remove_focus. The former indicates that the application is receiving the focus and the latter that it is losing the focus.