Unit Keymap

From Ultibo.org
Jump to: navigation, search

Return to Unit Reference


Description


Ultibo Keymap Interface unit

Keymaps

Keymaps define the translation of a keyboard scan code (the SCAN_CODE_* values) to a key code value (the KEY_CODE_* values) and provide the ability to handle different keyboard layouts in different countries and regions.

The keyboard scan codes are based on the values in Section 10 of the Universal Serial Bus HID Usage Tables v1.12 and are the actual values returned by the keyboard when a key is pressed.

The key code values are based on the Unicode standard with each key code mapped to the code point for that character.

This allows almost infinite flexibility in the way keyboard scan codes are mapped to actual characters and avoids the need to make unreliable assumptions about ASCII characters and upper or lower case handling.

Since the output of the keyboard is a stream of TKeyboardData structures containing both the scan code and the key code then higher level functions can retranslate the data in any way required.

Caps Keys

Caps keys account for the set of keys which are affected by Caps Lock in any given keyboard layout.

In some layouts only the alphabetic keys are affected, in other layouts some or all of the numeric and punctuation keys are also affected.

The caps keys data for any keyboard layout allows defining ranges of keys that are affected by the Caps Lock state.

Dead Keys

Dead keys account for the set of keys which behave as dead keys in any given keyboard layout.

On pressing a deadkey it will be recognized by the keyboard as such and stored until the next key press occurs. If the next keypress is one of the resolves for the pressed dead key then the output character will be the key code value of the resolve not for the key itself.

If the next keypress after a dead key is not one of the resolves that the dead key and the pressed key will both be output to the keyboard buffer.

Setting the default keymap for the system

Additional keymaps are provided as units which can be included in a program and will auto load themselves if included.

All keymap units are configured to check for both the environment variable KEYMAP_DEFAULT and the global configuration variable KEYMAP_DEFAULT to determine if either of them is set to the name of that keymap. If either is set to the keymap name then that keymap will also set itself as the default during system startup.

The environment variable KEYMAP_DEFAULT can be set by adding KEYMAP_DEFAULT=XX (where XX is the name of the keymap, eg DE for Keymap_DE) to the command line of the application (dependent on the system, for a Raspberry Pi use the cmdline.txt file on the SD card).

The global configuration variable KEYMAP_DEFAULT can be set in code by including the GlobalConfig unit in a program and setting the variable during startup.

At any time after startup the default keymap can be changed by call the KeymapSetDefault function.

Constants



[Expand]
Keymap specific constants KEYMAP_*


[Expand]
Keymap signature KEYMAP_SIGNATURE_*


[Expand]
Keymap name length KEYMAP_*_LENGTH


[Expand]
Keymap mode KEYMAP_MODE_*


[Expand]
Keymap flag KEYMAP_FLAG_*


[Expand]
Keymap index KEYMAP_INDEX_*


Type definitions



Keymap header

[Expand]

PKeymapHeader = ^TKeymapHeader;

TKeymapHeader = record

Keymap data

[Expand]

PKeymapData = ^TKeymapData;

TKeymapData = record

Keymap chars

[Expand]

PKeymapChars = ^TKeymapChars;

TKeymapChars = array[0..0] of Word;

Keymap capskey

[Expand]

PKeymapCapskey = ^TKeymapCapskey;

TKeymapCapskey = record

Keymap capskeys

[Expand]

PKeymapCapskeys = ^TKeymapCapskeys;

TKeymapCapskeys = record

Keymap resolve

[Expand]

PKeymapResolve = ^TKeymapResolve;

TKeymapResolve = record

Keymap deadkey

[Expand]

PKeymapDeadkey = ^TKeymapDeadkey;

TKeymapDeadkey = record

Keymap deadkeys

[Expand]

PKeymapDeadkeys = ^TKeymapDeadkeys;

TKeymapDeadkeys = record

Keymap properties

[Expand]

PKeymapProperties = ^TKeymapProperties;

TKeymapProperties = record

Keymap enumeration callback

TKeymapEnumerate = function(Handle:TKeymapHandle; Data:Pointer):LongWord;

Keymap entry

[Expand]

PKeymapEntry = ^TKeymapEntry;

TKeymapEntry = record


Public variables


None defined

Function declarations



Initialization functions

[Expand]
procedure KeymapInit;
Description: Initialize the keymap unit, keymap table and default keymap


Keymap functions

[Expand]
function KeymapLoad(Header:PKeymapHeader; Data:PKeymapData; Size:LongWord):TKeymapHandle;
Description: Load a Keymap from a keymap data block and add to the Keymap table


[Expand]
function KeymapLoadEx(Header:PKeymapHeader; Data:PKeymapData; Capskeys:PKeymapCapskeys; Deadkeys:PKeymapDeadkeys; Size:LongWord; Properties:PKeymapProperties):TKeymapHandle;
Description: Load a Keymap from a keymap data block and add to the Keymap table


[Expand]
function KeymapUnload(Handle:TKeymapHandle):LongWord;
Description: Unload an existing keymap and remove from the Keymap table


[Expand]
function KeymapGetName(Handle:TKeymapHandle):String;
Description: Get the name of the specified keymap


[Expand]
function KeymapGetDescription(Handle:TKeymapHandle):String;
Description: Get the description of the specified keymap


[Expand]
function KeymapCheckFlag(Handle:TKeymapHandle; Flag:LongWord):Boolean;
Description: Check if a specified keymap has a particular flag set or not


[Expand]
function KeymapGetKeyCode(Handle:TKeymapHandle; ScanCode:Word; Index:Byte):Word;
Description: Resolve a scan code and index value to a key code using the specified keymap


[Expand]
function KeymapGetCharCode(Handle:TKeymapHandle; KeyCode:Word):Char;
Description: Resolve a key code value to an ANSI character code using the specified keymap


[Expand]
function KeymapGetCharUnicode(Handle:TKeymapHandle; KeyCode:Word):WideChar;
Description: Resolve a key code value to a Unicode character code using the specified keymap


[Expand]
function KeymapCheckCapskey(Handle:TKeymapHandle; ScanCode:Word):Boolean;
Description: Check if a scan code is affected by the Caps Lock key in the specified keymap


[Expand]
function KeymapCheckDeadkey(Handle:TKeymapHandle; ScanCode:Word; Index:Byte):Boolean;
Description: Check if a scan code represents a Dead Key in the specified keymap


[Expand]
function KeymapResolveDeadkey(Handle:TKeymapHandle; DeadCode,ScanCode:Word; DeadIndex,ScanIndex:Byte; var KeyCode:Word):Boolean;
Description: Resolve a Dead Key and the next scan code to a key code value


[Expand]
function KeymapGetProperties(Handle:TKeymapHandle; Properties:PKeymapProperties):LongWord;
Description: Get the properties of the specified keymap


[Expand]
function KeymapFindByName(const Name:String):TKeymapHandle; 
Description: Find a keymap by name


[Expand]
function KeymapFindByDescription(const Description:String):TKeymapHandle;
Description: Find a keymap by description


[Expand]
function KeymapEnumerate(Callback:TKeymapEnumerate; Data:Pointer):LongWord;
Description: Enumerate all loaded keymaps


Keymap helper functions

[Expand]
function KeymapGetCount:LongWord;
Description: Get the current keymap count


[Expand]
function KeymapGetDefault:TKeymapHandle;
Description: Get the current default keymap


[Expand]
function KeymapSetDefault(Handle:TKeymapHandle):LongWord;
Description: Set the current default keymap


[Expand]
function KeymapCheck(Keymap:PKeymapEntry):PKeymapEntry;
Description: Check if the supplied Keymap is in the Keymap table


Return to Unit Reference