13 Keyboard Components
A keyboard component is a visual component that represents a particular keyboard layout. A CEF keyboard component doesn't send data associated with keystrokes, but rather uses key names. For some keys, names are simply "A", or "1". For others, the name represents the glyph or function of the key - for instance, "LEFT" or "BREAK". Each key name also has a corresponding index. A series of individual keys can be pressed together (for instance, SHIFT and a letter). Such a combination of keys is called a "keystroke". A keystroke ends when all keys are no longer pressed by the user. Note that some keys can lock into a down position and in a down state do not prevent a keystroke from completing. The keyboard component can notify connected components of key state changes, but the keyboard can also be queried for keystroke state. These operations operate in parallel and the application can use the component in a polled or interrupt fashion. However, when used in an interrupt fashion, the keyboard should be polled to clear its queue of keystrokes and prevent excessive memory usage.
The convention of a "NKP_" prefix is used for otherwise normal characters that occur on a numeric keypad. Thus "1" indicates a normal "1" key, but "NKP_1" indicates a "1" key from a numeric keypad. Any receiver of data from a keyboard component should strip "NKP_" from the front of a key name when interpreting keys UNLESS that receiver wishes to specifically distinguish between the two keys. Likewise, "LEFT_" prior to a key name indicates the left of two instances of a key (for instance, SHIFT), and "RIGHT_" indicates the right of the two keys. These conditions should be handled appropriately.
When a key is pressed or released, the component does a port write to connected components where the port number is the key index and the data is 1 for keydown or 0 for keyup.
TKeyboard provides special functions for accessing simple LEDs on the keyboard. For more complicated displays, the Write method should be used. Functions unique to keyboards are accessed via the TKeyboard object, provided via the TComponent.Keyboard method.
The TKeyboard class has the following methods:
Retrieves the next key in a keystroke from the keyboard. Returns NULL if no more keystrokes or a null string if end of current keystroke. Note that all keys returned by this method are appropriate for any corresponding key states. For instance, when the "A" key is pressed then if SHIFT is down, the returned key will be "A". If SHIFT is up, the returned key will be "a".
Boolean Get_Key_Down( string Name )
Returns True if the specified key is down in the pending keystroke. If Name is NULL, returns True if any key is down in the pending keystroke. It also returns False if the key name is unknown.
void Set_Key_Down( string Name, Boolean State )
Sets the state of a given key to up or down. The key is reset when the next keystroke is returned. This can be used to synchronize the keyboard component's visible state with the physical keyboard.
string Get_Key_Name( integer Index )
Returns the name of the key associated with the passed index. Returns NULL if the index is invalid. It is valid for different indexes to refer to the same key name. Typically this occurs for corresponding upper and lower-case letters.
boolean Get_LED_State( string Name )
Returns True if the specified LED is lit. If the LED name is not recognized, the function returns false.
void Set_LED_State( string Name, boolean State ) ;
Sets the state of a given LED to lit or not. This can be used to synchronize the keyboard component's visible state with the physical keyboard.
string Get_LED_Name( integer Index )
Returns the name of the LED associated with the passed index. Returns NULL if the index is invalid.
Returns the version of the CEF specification that the object adheres to. This is the major.minor version times 10. For instance, a value of 20 indicates version 2.0.
Further, keyboard components have special meanings for TComponent methods, as follows:
Clears all pending keystrokes and sets all keys to the default state (usually up). A given implementation may also perform other functions during a Reset.