## Input/Output Device Driver Reference

[prev][next][parent][TOC]

### Keyboard Run-Time Operation

When a session is started, a default logical keyboard already exists. This keyboard is identified to the subsystem by a zero handle. Any program can share the keyboard by using Handle 0. If multiple programs use the default keyboard they must coordinate their access to it. The default keyboard logically terminates when the session terminates.

If a program wants a logical keyboard separate from the default logical keyboard, it issues a KbdOpen. This open creates a new logical keyboard, but does not make the physical-to-logical bond. As a result of an open, a handle unique within a process is returned to the caller, which is later used to identify the logical keyboard. The handle ownership is tied to the process; handles are not inherited. Use of KbdOpen does not prohibit the process from using the default keyboard.

To make the physical-to-logical bond, the process issues the KbdGetFocus using the handle which identifies the logical keyboard. When the bond is made, the logical keyboard can receive keystrokes. Note that type-ahead keystrokes are not possible before the bond is made. The keyboard API can be used only when the bond is made, or with Handle 0 when no other handle has the bond.

The bond represents a foreground keyboard (one physical-to-logical bond exists for each session). This is the default or a created logical keyboard . To break the bond, issue a KbdFreeFocus call. If other threads have a KbdGetFocus outstanding, the thread having the highest priority gets the bond. If there are no KbdGetFocus calls outstanding, the physical keyboard reverts to the default keyboard.

A logical keyboard is destroyed with a KbdClose. The close frees the focus, flushes the buffer, and deallocates the KCB and related memory. The close is done by the process kill mechanism, if it is not performed by the program.