Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Keymap Library"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
m (Fixed small typos in MapRawKey.c preventing accurate value to be printed to the console)
 
(2 intermediate revisions by one other user not shown)
Line 4: Line 4:
 
Amiga computers are sold internationally with a variety of local keyboards which match the standards of particular countries. All Amigas have keyboards which are physically similar, and keys which output the same low-level raw key code for any particular physical key. However, in different countries, the keycaps of the keys may contain different letters or symbols. Since the physical position of a key determines the raw key code that it generates, raw key codes are not internationally compatible. For instance, on the German keyboard, the Y and Z keys are swapped when compared to the USA keyboard. The second key on the fifth row will generate the same raw key code on all Amiga keyboards, but should be decoded as a Z on a US keyboard and as a Y on a German keyboard.
 
Amiga computers are sold internationally with a variety of local keyboards which match the standards of particular countries. All Amigas have keyboards which are physically similar, and keys which output the same low-level raw key code for any particular physical key. However, in different countries, the keycaps of the keys may contain different letters or symbols. Since the physical position of a key determines the raw key code that it generates, raw key codes are not internationally compatible. For instance, on the German keyboard, the Y and Z keys are swapped when compared to the USA keyboard. The second key on the fifth row will generate the same raw key code on all Amiga keyboards, but should be decoded as a Z on a US keyboard and as a Y on a German keyboard.
   
The Amiga uses the ECMA-94 Latin 1 International 8-bit character set, and can map raw key codes to any desired ANSI character value, string, or escape sequence. This allows national keyboards to be supported by using keymaps. A keymap is a file which describes what character or string is tied to what key code. Generally, the user's startup-sequence will set a system default keymap that is correct for the user's keyboard. The console.device translates the raw key codes into the correct characters based on the installed keymap. This includes the translation of special deadkey sequential key combinations to produce accented international characters.
+
The Amiga uses the [http://www.ecma-international.org/publications/standards/Ecma-094.htm ECMA-94 Latin 1 International 8-bit] character set, and can map raw key codes to any desired ANSI character value, string, or escape sequence. This allows national keyboards to be supported by using keymaps. A keymap is a file which describes what character or string is tied to what key code. Generally, the user's startup-sequence will set a system default keymap that is correct for the user's keyboard. The console.device translates the raw key codes into the correct characters based on the installed keymap. This includes the translation of special deadkey sequential key combinations to produce accented international characters.
   
Programs which perform keyboard input using the console.device, CON:, RAW:, or Intuition VANILLAKEY, will receive custom keymaps, or may need to perform their own translation between raw key codes and ANSI characters. In this chapter, the term ANSI refers to the standard 8-bit character definitions which include printable ASCII characters, special characters, and escape sequences.
+
Programs which perform keyboard input using the console.device, CON:, RAW:, or Intuition VANILLAKEY, will receive custom keymaps, or may need to perform their own translation between raw key codes and ANSI characters. In this article, the term ANSI refers to the standard 8-bit character definitions which include printable ASCII characters, special characters, and escape sequences.
   
 
Keymap.library offers some of the keymap commands of the console.device, enabling applications to inquire after the default keymap and map key codes to ANSI characters. It also provides the ability to map ANSI characters back into raw codes. Unlike the console.device however, it can not be used to select a keymap for only one application, i.e., one console window.
 
Keymap.library offers some of the keymap commands of the console.device, enabling applications to inquire after the default keymap and map key codes to ANSI characters. It also provides the ability to map ANSI characters back into raw codes. Unlike the console.device however, it can not be used to select a keymap for only one application, i.e., one console window.
Line 197: Line 197:
 
inputevent.ie_Qualifier = imsg->Qualifier;
 
inputevent.ie_Qualifier = imsg->Qualifier;
   
IDOS->Printf("RAWKEY: Code=$%04x Qualifier=$%04lx\en",
+
IDOS->Printf("RAWKEY: Code=$%04lx Qualifier=$%04lx\n",
 
imsg->Code, imsg->Qualifier);
 
imsg->Code, imsg->Qualifier);
   
Line 1,413: Line 1,413:
 
== Function Reference ==
 
== Function Reference ==
   
The following are brief descriptions of the functions covered in this chapter. See the SDK for details on each function call.
+
The following are brief descriptions of the functions covered in this article. See the SDK for details on each function call.
   
 
{| class="wikitable"
 
{| class="wikitable"

Latest revision as of 16:54, 18 August 2019

WIP.png This page is currently being updated to AmigaOS 4.x. Some of the information contained here may not yet be applicable in part or totally.

Keymap Library

Amiga computers are sold internationally with a variety of local keyboards which match the standards of particular countries. All Amigas have keyboards which are physically similar, and keys which output the same low-level raw key code for any particular physical key. However, in different countries, the keycaps of the keys may contain different letters or symbols. Since the physical position of a key determines the raw key code that it generates, raw key codes are not internationally compatible. For instance, on the German keyboard, the Y and Z keys are swapped when compared to the USA keyboard. The second key on the fifth row will generate the same raw key code on all Amiga keyboards, but should be decoded as a Z on a US keyboard and as a Y on a German keyboard.

The Amiga uses the ECMA-94 Latin 1 International 8-bit character set, and can map raw key codes to any desired ANSI character value, string, or escape sequence. This allows national keyboards to be supported by using keymaps. A keymap is a file which describes what character or string is tied to what key code. Generally, the user's startup-sequence will set a system default keymap that is correct for the user's keyboard. The console.device translates the raw key codes into the correct characters based on the installed keymap. This includes the translation of special deadkey sequential key combinations to produce accented international characters.

Programs which perform keyboard input using the console.device, CON:, RAW:, or Intuition VANILLAKEY, will receive custom keymaps, or may need to perform their own translation between raw key codes and ANSI characters. In this article, the term ANSI refers to the standard 8-bit character definitions which include printable ASCII characters, special characters, and escape sequences.

Keymap.library offers some of the keymap commands of the console.device, enabling applications to inquire after the default keymap and map key codes to ANSI characters. It also provides the ability to map ANSI characters back into raw codes. Unlike the console.device however, it can not be used to select a keymap for only one application, i.e., one console window.

As a prelude to the following material, note that the Amiga keyboard transmits raw key information to the computer in the form of a key position and a transition. Raw key positions range from hexadecimal 00 to 7F. When a key is released, its raw key position, plus hexadecimal 80, is transmitted.

Keymap Functions

Keymap Library Functions
AskKeyMapDefault() Ask for a pointer to the current default keymap
MapANSI() Encode an ANSI string into key codes
MapRawKey() Decode a raw key input event to an ANSI string
SetKeyMapDefault() Set the current default keymap
Console Device Keymap Commands
CD_ASKKEYMAP Ask for the current console's keymap
CD_SETKEYMAP Set the current console's keymap
CD_ASKDEFAULTKEYMAP* Set the current default keymap
CD_SETDEFAULTKEYMAP** Ask for a pointer to the current default keymap
* Obsolete - use AskKeyMapDefault()
** Obsolete - use SetKeyMapDefault()

All of these commands deal with a set of pointers to key translation arrays, known as the KeyMap structure. The KeyMap structure is defined in <devices/keymap.h> and is shown below.

struct KeyMap
    {
    UBYTE *km_LoKeyMapTypes;
    ULONG *km_LoKeyMap;
    UBYTE *km_LoCapsable;
    UBYTE *km_LoRepeatable;
    UBYTE *km_HiKeyMapTypes;
    ULONG *km_HiKeyMap;
    UBYTE *km_HiCapsable;
    UBYTE *km_HiRepeatable;
    };

The KeyMap structure contains pointers to arrays which define the ANSI character or string that should be produced when a key or a combination of keys are pressed. For example, a keymap might specify that the key with raw value hex 20 should produce the ANSI character "a", and if the Shift key is being held it should produce the character "A".

Asking for the Default Keymap

The AskKeyMapDefault() returns a pointer to the current default keymap. To use the mapping functions in keymap.library it is normally not necessary to call this function. They accept NULL as equivalent to 'use default keymap' and will call this function for you. You can use this pointer for example to cache the system default in order to temporarily change the keymap your applications uses, or find the keymap in the keymap.resource list of loaded keymaps. You should never change the system wide default keymap unless the user asks you to do so; since the Amiga is a multitasking system, changing the keymap could interfere with the behaviour of other applications.

Setting the Default Keymap

The system default keymap can be set with the SetKeyMapDefault() function. This function takes a pointer to a loaded keymap. In general, this function should never be used by an application unless the application is a system Preferences editor, or an application that takes over the system. Normal applications should instead attach a console.device unit to their own Intuition window (see the Devices volume), and use the console.device command CD_SETKEYMAP to set a keymap only for their own console.

When making a keymap the system default, first check whether the keymap has been loaded previously by checking the keymap list of the keymap.resource. If it has not been loaded already, it can be loaded from DEVS:Keymaps, and added to the keymap list of keymap.resource. This will ensure that other applications which may want the keymap will not have to load a second instance. Once made the default, the keymap can never be safely removed from memory, even after if it is no longer the default, since other applications may still have and use a pointer to it.

Accessing the Keymap for the Current Console

The function AskKeyMap() shown below does not return a pointer to a table of pointers to currently assigned key mapping. Instead, it copies the current set of pointers to a user-designated area of memory. AskKeyMap() returns a TRUE or FALSE value that says whether or not the function succeeded.

The function SetKeyMap(), also shown below, copies the designated key map data structure to the console device. Thus this routine is complementary to AskKeymap() in that it can restore an original key mapping as well as establish a new one.

Ask/SetKeyMap()
These functions assume that you have already opened the console.device and that request is a valid IOStdReq structure for the newly opened console. These functions are not part of the keymap.library, nor of the console.device. These merely demonstrate CD_ASKKEYMAP and CD_SETKEYMAP which are console.device commands.
/* These functions require that you have created a port and an IO request,
 * and have opened the console device as shown in the "Console Device" section.
 */
#include <devices/keymap.h>
 
BOOL AskKeyMap(struct IOStdReq *request, struct KeyMap *keymap)
{
    request->io_Command = CD_ASKKEYMAP;
    request->io_Length = sizeof(struct KeyMap);
    request->io_Data = (APTR)keymap;  /* where to put it */
    IExec->DoIO(request);
    if(request->io_Error) return(FALSE);
    else  return(TRUE); /* if no error, it worked. */
}
 
BOOL SetKeyMap(struct IOStdReq *request, struct KeyMap *keymap)
{
    request->io_Command = CD_SETKEYMAP;
    request->io_Length = sizeof(struct KeyMap);
    request->io_Data = (APTR)keymap;      /* where to get it */
    IExec->DoIO(request);
    if(request->io_Error) return(FALSE);
    else  return(TRUE);     /* if no error, it worked. */
}

Mapping Key Codes to ANSI Strings

MapRawKey() converts raw key codes in ANSI characters based on a default or supplied keymap.

WORD MapRawKey(struct InputEvent *inputevent, STRPTR buffer, WORD bufferlength, struct Keymap *keymap);

MapRawKey() takes an IECLASS_RAWKEY inputevent, which may be chained, and converts the key codes to ANSI characters which are placed in the specified buffer. If the buffer would overflow, for example because a longer string is attached to a key, -1 will be returned. If no error occured, MapRawKey() will return the number of bytes written in the buffer. The keymap argument can be set to NULL if the default keymap is to be used for translation, or can be a pointer to a specific KeyMap structure.

The following example shows how to implement the MapRawKey() function.

/*
 * maprawkey.c - Map Intuition RAWKEY events to ANSI with MapRawKey();
 */
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <intuition/intuition.h>
#include <devices/inputevent.h>
 
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/keymap.h>
#include <proto/intuition.h>
 
/* our function prototypes */
void openall(void);
void closeall(void);
void closeout(UBYTE *errstring, LONG rc);
 
struct Library *IntuitionBase = NULL;
struct IntuitionIFace *IIntuition = NULL;
 
struct Library *KeymapBase = NULL;
struct KeymapIFace *IKeymap = NULL;
 
struct Window *window = NULL;
 
int main(int argc, char **argv)
{
    struct IntuiMessage *imsg;
    APTR                *eventptr;
    struct InputEvent   inputevent = {0};
    LONG                windowsignal;
    UBYTE               buffer[8];
    COUNT               i;
    BOOL                Done = FALSE;
 
    openall();
 
    window = IIntuition->OpenWindowTags(NULL,
                            WA_Width,  500,
                            WA_Height, 60,
                            WA_Title, "MapRawKey - Press Keys",
                            WA_Flags, WFLG_CLOSEGADGET | WFLG_ACTIVATE,
                            WA_IDCMP, IDCMP_RAWKEY | IDCMP_CLOSEWINDOW,
                            TAG_END);
    if(window == NULL)   closeout("Can't open window",RETURN_FAIL);
 
    windowsignal = 1L << window->UserPort->mp_SigBit;
 
    /* Initialize InputEvent structure (already cleared to 0) */
    inputevent.ie_Class = IECLASS_RAWKEY;
 
    while(!Done)
       {
       IExec->Wait(windowsignal);
 
       while (imsg = (struct IntuiMessage *)IExec->GetMsg(window->UserPort))
           {
           switch(imsg->Class)
               {
                case IDCMP_CLOSEWINDOW:
                    Done = TRUE;
                    break;
 
                case IDCMP_RAWKEY:
                    inputevent.ie_Code = imsg->Code;
                    inputevent.ie_Qualifier = imsg->Qualifier;
 
                    IDOS->Printf("RAWKEY: Code=$%04lx  Qualifier=$%04lx\n",
                             imsg->Code, imsg->Qualifier); 
 
                    /* Make sure deadkeys and qualifiers are taken
                     * into account.
                     */
                    eventptr = imsg->IAddress;
                    inputevent.ie_EventAddress = *eventptr;
 
                    /* Map RAWKEY to ANSI */
                    i = IKeymap->MapRawKey(&inputevent, buffer, 8, NULL);
 
                    if (i == -1) IDOS->Write(IDOS->Output(),"*Overflow*",10);
                    else if (i)
                        {
                        /* This key or key combination mapped to something */
                        IDOS->Printf("MAPS TO: ");
                        IDOS->Write(IDOS->Output(),buffer,i);
                        IDOS->Printf("\en");
                        }
                    break;
                }
            IExec->ReplyMsg((struct Message *)imsg);
            }
        }
    IIntuition->CloseWindow(window);
    closeall();
    return RETURN_OK;
}
 
void openall(void)
{
    KeymapBase = IExec->OpenLibrary("keymap.library", 50);
    IKeymap = (struct KeymapIFace*)IExec->GetInterface(KeymapBase, "main", 1, NULL);
    if (IKeymap == NULL)    closeout("Can't get IKeymap",RETURN_FAIL);
 
    IntuitionBase = IExec->OpenLibrary("intuition.library", 50);
    IIntuition = (struct IntuitionIFace*)IExec->GetInterface(IntuitionBase, "main", 1, NULL);
    if (IIntuition == NULL) closeout("Can't get IIntuition",RETURN_FAIL);
}
 
void closeall(void)
{
    IExec->DropInterface((struct Interface*)IIntuition);
    IExec->CloseLibrary(IntuitionBase);
 
    IExec->DropInterface((struct Interface*)IKeymap);
    IExec->CloseLibrary(KeymapBase);
}
 
void closeout(UBYTE *errstring, LONG rc)
{
    if (*errstring)  IDOS->Printf("%s\en",errstring);
    closeall();
    exit(rc);
}

Mapping ANSI Strings to Key Codes

The MapANSI() function translates ANSI strings into raw key codes, complete with qualifiers and (double) dead keys, based on a default or supplied keymap.

LONG MapANSI(UBYTE *string, LONG stringlength, UBYTE *buffer, LONG bufferlength, struct KeyMap *keymap);

The string argument is a pointer to an ANSI string, of length stringlength. The buffer argument is a pointer to the memory block where the translated key codes will be placed. The length of this buffer must be indicated in WORDs since each translation will occupy one byte for the key code and one for the qualifier. Since one ANSI character can be translated to two dead keys and one key, the buffer must be at least 3 WORDs per character in the string to be translated. The keymap argument can be set to NULL if the default keymap is to be used, or can be a pointer to a KeyMap structure. Upon return, the function will indicate how many key code/qualifier combinations are placed in the buffer or a negative number in case an error occurred. If zero is returned, the character could not be translated.

The following example shows the usage of MapANSI() and demonstrates how returned key codes can be processed.

/*
mapansi.c - converts a string to input events using MapANSI() function.
 
            This example will also take the created input events
            and add them to the input stream using the simple
            commodities.library function AddIEvents().  Alternately,
            you could open the input.device and use the input device
            command IND_WRITEEVENT to add events to the input stream.
*/
 
#include       <exec/types.h>
#include       <exec/memory.h>
#include       <exec/io.h>
#include       <dos/dos.h>
#include       <devices/input.h>
#include       <devices/inputevent.h>
 
#include       <proto/exec.h>
#include       <proto/dos.h>
#include       <proto/keymap.h>
#include       <proto/commodities.h>
 
struct Library *KeymapBase = NULL;       /* MapAnsi() function    */
struct KeymapIFace *IKeymap = NULL;
 
struct Library *CxBase = NULL;           /* AddIEvents() function */
struct CommoditiesIFace *ICommodities = NULL;
 
struct InputEvent       *InputEvent = NULL;       /* we'll allocate this */
 
/* prototypes for our program functions */
 
void openall(void);
void closeall(void);
void closeout(UBYTE *errstring, LONG rc);
 
 
int main(int argc, char **argv)
{
    UBYTE               *string;
    UBYTE               *tmp1;
    UBYTE               *tmp2;
    UBYTE               iebuffer[6];            /* Space for two dead keys */
                                                /* + 1 key + qualifiers    */
    COUNT               i;
    LONG                rc = 0;
 
 
    openall();
 
    string = ";String converted to input events and sent to input device\n";
 
    InputEvent->ie_Class = IECLASS_RAWKEY;
 
    /* Turn each character into an InputEvent */
    tmp1 = string;
 
    while (*tmp1)
    {
        /* Convert one character, use default key map */
        i = IKeymap->MapANSI(tmp1, 1, iebuffer, 3, NULL);
 
        /* Make sure we start without deadkeys */
        InputEvent->ie_Prev1DownCode = InputEvent->ie_Prev1DownQual = 0;
        InputEvent->ie_Prev2DownCode = InputEvent->ie_Prev2DownQual = 0;
 
        tmp2 = iebuffer;
 
        switch (i)
        {
          case -2:
            IDOS->Printf("Internal error\n", NULL);
            rc = RETURN_FAIL;
            break;
 
          case -1:
            IDOS->Printf("Overflow\n", NULL);
            rc = RETURN_FAIL;
            break;
 
          case 0:
            IDOS->Printf("Can't generate code\n", NULL);
            break;
 
          case 3:
            InputEvent->ie_Prev2DownCode = *tmp2++;
            InputEvent->ie_Prev2DownQual = *tmp2++;
            /* FALL THROUGH */
 
          case 2:
            InputEvent->ie_Prev1DownCode = *tmp2++;
            InputEvent->ie_Prev1DownQual = *tmp2++;
            /* FALL THROUGH */
 
          case 1:
            InputEvent->ie_Code = *tmp2++;
            InputEvent->ie_Qualifier = *tmp2;
            break;
        }
 
        if (rc == RETURN_OK)
        {
            /* Send the key down event */
            ICommodities->AddIEvents(InputEvent);
 
            /* Create a key up event */
            InputEvent->ie_Code |= IECODE_UP_PREFIX;
 
            /* Send the key up event */
            ICommodities->AddIEvents(InputEvent);
         }
 
        if (rc != RETURN_OK)
            break;
 
        tmp1++;
    }
 
    closeall();
    return rc;
}
 
 
void openall(void)
{
    KeymapBase = IExec->OpenLibrary("keymap.library", 50);
    IKeymap = (struct KeymapIFace*)IExec->GetInterface(KeymapBase, "main", 1, NULL);
    if (IKeymap == NULL)  closeout("Can't get IKeymap", RETURN_FAIL);
 
    CxBase = IExec->OpenLibrary("commodities.library", 50);
    ICommodities = (struct CommoditiesIFace*)IExec->GetInterface(CxBase, "main", 1, NULL);
    if (ICommodities == NULL)  closeout("Can't get ICommodities", RETURN_FAIL);
 
    InputEvent = IExec->AllocMem(sizeof(struct InputEvent), MEMF_CLEAR);
    if (InputEvent == NULL)  closeout("Can't allocate input event",RETURN_FAIL);
}
 
 
void closeall()
{
    if (InputEvent)    IExec->FreeMem(InputEvent, sizeof(struct InputEvent));
 
    IExec->DropInterface((struct Interface*)ICommodities);
    IExec->CloseLibrary(CxBase);
 
    IExec->DropInterface((struct Interface*)IKeymap);
    IExec->CloseLibrary(KeymapBase);
}
 
 
void closeout(UBYTE *errstring, LONG rc)
{
    if(*errstring)     IDOS->Printf("%s\n",errstring);
    closeall();
    exit(rc);
}

Details of the Keymap Structure

A KeyMap structure contains pointers to arrays which determine the translation from raw key codes to ANSI characters.

struct KeyMap
    {
    UBYTE *km_LoKeyMapTypes;
    ULONG *km_LoKeyMap;
    UBYTE *km_LoCapsable;
    UBYTE *km_LoRepeatable;
    UBYTE *km_HiKeyMapTypes;
    ULONG *km_HiKeyMap;
    UBYTE *km_HiCapsable;
    UBYTE *km_HiRepeatable;
    };

LoKeyMap and HighKeyMap

The low key map provides translation of the key values from hex 00-3F; the high key map provides translation of key values from hex 40-7F. Key values from hex 68-7F are not used by the existing keyboards, but this may change in the future. A raw key value (hex 00-7F) plus hex 80 is the release of that key. If you need to check for raw key releases do it like this:

if (keyvalue & 0x80)     {  /* do key up processing   */  }
else                     {  /* do key down processing */  }

Raw output from the keyboard for the low key map does not include the space bar, Tab, Alt, Ctrl, arrow keys, and several other keys.

High Key Map Hex Values
Key Number Keycap Legend for Function
40 Space
41 Backspace
42 Tab
43 Enter
44 Return
45 Escape
46 Delete
4A Numeric Pad character
4C Cursor Up
4D Cursor Down
4E Cursor Right
4F Cursor Left
50-59 Function keys F1-F10
5A-5E Numeric Pad characters
5F Help
60 Left Shift
61 Right Shift
62 Caps Lock
63 Control
64 Left Alt
65 Right Alt
66 Left Amiga
67 Right Amiga

The keymap table for the low and high keymaps consists of 4-byte entries, one per hex key code. These entries are interpreted in one of two possible ways:

  • As four separate bytes, specifying how the key is to be interpreted when pressed alone, with one qualifier, with another qualifier, or with both qualifiers (where a qualifier is one of three possible keys: Ctrl, Alt, or Shift).
  • As a longword containing the address of a string descriptor, where a string of characters is to be output when this key is pressed. If a string is to be output, any combination of qualifiers can affect the string that may be transmitted.
  • As a longword containing the address of a dead-key descriptor, where additional data describe the character to be output when this key is pressed alone or with another dead key.
The keymap tables must be word aligned
The keymap tables must begin aligned on a word boundary. Each entry is four bytes long, thereby maintaining word alignment throughout the table. This is necessary because some of the entries may be longword addresses and must be aligned properly for the 68000.

LoKeyMapTypes and HiKeyMapTypes

The tables named km_LoKeyMapTypes and km_HiKeyMapTypes each contain one byte per raw key code. Each byte defines the type of entry that is found in the keymap table for that raw key code.

Possible key types are:

  • Any of the qualifier groupings noted above
  • KCF_STRING + any combination of KCF_SHIFT, KCF_ALT, KCF_CONTROL (or KC_NOQUAL) if the result of pressing the key is to be a stream of bytes (and key-with-one-or-more-qualifiers is to be one or more alternate streams of bytes). Any key can be made to output up to eight unique byte streams if KCF_STRING is set in its keytype. The only limitation is that the total length of all of the strings assigned to a key must be within the "jump range" of a single byte increment. See the "String Output Keys" section below for more information.
  • KCF_DEAD + any combination of KCF_SHIFT, KCF_ALT, KCF_CONTROL (or KC_NOQUAL) if the key is a dead-class key and can thus modify or be modified by another dead-class key. See the "Dead-Class Keys" section below for more information.

The low keytype table covers the raw key codes from hex 00-3F and contains one byte per key code. Therefore this table contains 64 (decimal) bytes. The high keytype table covers the raw key codes from hex 40-7F and contains 64 (decimal) bytes.

More About Qualifiers

For keys such as the Return key or Esc key, the qualifiers specified in the keytypes table (up to two) are the qualifiers used to establish the response to the key. This is done as follows. In the keytypes table, the values listed for the key types are those listed for the qualifiers in <devices/keymap.h> and <devices/keymap>. Specifically, these qualifier equates are:

KC_NOQUAL 0x00
KCF_SHIFT 0x01
KCF_ALT 0x02
KCF_CONTROL 0x04
KC_VANILLA 0x07
KCF_DOWNUP 0x08
KCF_STRING 0x40

As shown above, the qualifiers for the various types of keys occupy specific bit positions in the key types control byte. As you may have noticed, there are three possible qualifiers, but only a 4-byte space in the table for each key. This does not allow space to describe what the computer should output for all possible combinations of qualifiers. A solution exists, however, for "vanilla" keys, such as the alphabetic keys. Here is how that works.

Keys of type KC_VANILLA use the 4 bytes to represent the data output for the key alone, Shifted key, Alt'ed key, and Shifted-and-Alt'ed key. Then for the Ctrl-key-plus-vanilla-key, use the code for the key alone with bits 6 and 5 set to 0.

The Vanilla Qualifier Does Not Mean Plain
The qualifier KC_VANILLA is equivalent to KCF_SHIFT+KCF_ALT+KCF_CONTROL.

This table shows how to interpret the keymap for various combinations of the qualifier bits:

Keymap Qualifier Bits
If Keytype is: Then data at this position in the keytable is output when the key is pressed along with:
KC_NOQUAL - - - alone
KCF_SHIFT - - Shift alone
KCF_ALT - - Alt alone
KCF_CONTROL - - Ctrl alone
KCF_ALT+KCF_SHIFT Shift+Alt Alt Shift alone
KCF_CONTROL+KCF_ALT Ctrl+Alt Ctrl Alt alone
KCF_CONTROL+KCF_SHIFT Ctrl+Shift Ctrl Shift alone
KC_VANILLA Shift+Alt Alt Shift alone*
*Special case--Ctrl key, when pressed with one of the alphabet keys and certain others, is to output key-alone value with the bits 6 and 5 set to zero.

String Output Keys

When a key is to output a string, the keymap table contains the address of a string descriptor in place of a 4-byte mapping of a key as shown above. Here is a partial table for a new high keymap table that contains only three entries thus far. The first two are for the space bar and the backspace key; the third is for the tab key, which is to output a string that says "[TAB]". An alternate string, "[SHIFTED-TAB]", is also to be output when a shifted TAB key is pressed.

newHiMapTypes:
    DC.B        KCF_ALT,KC_NOQUAL,      ;key 41
    DC.B        KCF_STRING+KCF_SHIFT,   ;key 42
        ...     ;(more)
newHiMap:
    DC.B        0,0,$A0,$20     ;key 40: space bar, and Alt-space bar
    DC.B        0,0,0,$08       ;key 41: Back Space key only
    DC.L        newkey42        ;key 42: new definition for string to output for Tab key
        ...     ;(more)
newkey42:
    DC.B        new42ue - new42us       ;length of the unshifted string
    DC.B        new42us - newkey42      ;number of bytes from start of
                                        ;string descriptor to start of this string
    DC.B        new42se - new42ss       ;length of the shifted string
    DC.B        new42ss - newkey42      ;number of bytes from start of
                                        ;string descriptor to start of this string
new42us:  DC.B        '[TAB]'
new42ue:
new42ss:  DC.B        '[SHIFTED-TAB]'
new42se:

The new high map table points to the string descriptor at address newkey42. The new high map types table says that there is one qualifier, which means that there are two strings in the key string descriptor.

Each string in the descriptor takes two bytes in this part of the table: the first byte is the length of the string, and the second byte is the distance from the start of the descriptor to the start of the string. Therefore, a single string (KCF_STRING + KC_NOQUAL) takes 2 bytes of string descriptor. If there is one qualifier, 4 bytes of descriptor are used. If there are two qualifiers, 8 bytes of descriptor are used. If there are 3 qualifiers, 16 bytes of descriptor are used. All strings start immediately following the string descriptor in that they are accessed as single-byte offsets from the start of the descriptor itself. Therefore, the distance from the start of the descriptor to the last string in the set (the one that uses the entire set of specified qualifiers) must start within 255 bytes of the descriptor address.

Because the length of the string is contained in a single byte, the length of any single string must be 255 bytes or less while also meeting the "reach" requirement. However, the console input buffer size limits the string output from any individual key to 32 bytes maximum.

The length of a keymap containing string descriptors and strings is variable and depends on the number and size of the strings that you provide.

Capsable Bit Tables

The vectors km_LoCapsable and km_HiCapsable each point to an array of 8 bytes that contain more information about the keytable entries. Specifically, if the Caps Lock key has been pressed (the Caps Lock LED is on) and if there is a bit \fIon\fP in that position in the capsable map, then this key will be treated as though the Shift key is now currently pressed. For example, in the default key mapping, the alphabetic keys are "capsable" but the punctuation keys are not. This allows you to set the Caps Lock key, just as on a normal typewriter, and get all capital letters. However, unlike a normal typewriter, you need not go out of Caps Lock to correctly type the punctuation symbols or numeric keys.

In the byte array, the bits that control this feature are numbered from the lowest bit in the byte, and from the lowest memory byte address to the highest. For example, the bit representing capsable status for the key that transmits raw code 00 is bit 0 in byte 0; for the key that transmits raw code 08 it is bit 0 in byte 1, and so on.

There are 64 bits (8 bytes) in each of the two capsable tables.

Repeatable Bit Tables

The vectors km_LoRepeatable and km_HiRepeatable each point to an array of 8 bytes that contain additional information about the keytable entries. A bit for each key indicates whether or not the specified key should repeat at the rate set by the Input Preferences program.

The bit positions correspond to those specified in the capsable bit table. If there is a 1 in a specific position, the key can repeat. There are 64 bits (8 bytes) in each of the two repeatable tables.

Key Map Standards

Users and programs depend on certain predictable behaviors from all keyboards and keymaps. With the exception of dead-class keys (see "Dead-Class Keys" section), mapping of keys in the low key map should follow these general rules:

  • When pressed alone, keys should transmit the ASCII equivalent of the unshifted letter or lower symbol on the keycap.
  • When Shifted, keys should transmit the ASCII equivalent of the shifted letter or upper symbol printed on the keycap.
  • When Alt'ed, keys should generally transmit the same character (or act as the same deadkey) as the Alt'ed key in the usa1 keymap.
  • When pressed with CTRL alone, alphabetic keys should generally transmit their unshifted value but with bits 5 and 6 cleared. This allows keyboard typing of "control characters." For example, the C key (normally value $63) should transmit value $03 (Ctrl-C) when Ctrl and C are pressed together.

The keys in the high key map (keys with raw key values $40 and higher) are generally non-alphanumeric keys such as those used for editing (backspace, delete, cursor keys, etc.), and special Amiga keys such as the function and help keys. Keymaps should translate these keys to the same values or strings as those shown in ROM Default Key Mapping table.

In addition to their normal unshifted and shifted values, the following translations are standard for particular qualified high keymap keys:

Key Generates This Value If Used with Qualifier, Generates This Value
Space $20 $A0 with qualifier KCF_ALT
Return $0D $0A with qualifier KCF_CONTROL
Esc $1B $9B with qualifier KCF_ALT

Dead-Class Keys

All of the national keymaps, including USA, contain dead-class keys. This term refers to keys that either modify or can themselves be modified by other dead-class keys. There are two types of dead-class keys: dead and deadable. A dead key is one which can modify certain keys pressed immediately following. For example, on the German keyboard there is a dead key marked with the grave accent (`). The dead key produces no console output, but when followed by (for instance) the A key, the combination will produce the a-grave (à) character (National Character Code $E0). On the U.S. keyboard, Alt-G is the deadkey used to add the grave accent (`) to the next appropriate character typed.

A deadable key is one that can be prefixed by a dead key. The A key in the previous example is a deadable key. Thus, a dead key can only affect the output of a deadable key.

For any key that is to have a dead-class function, whether dead or deadable, the qualifier KCF_DEAD flag must be included in the entry for the key in the KeyMapTypes table. The KCF_DEAD type may also be used in conjunction with the other qualifiers. Furthermore, the key's keymap table entry must contain the longword address of the key's dead-key descriptor data area in place of the usual 4 ASCII character mapping.

Below is an excerpt from the Amiga 1000 German key map which is referred to in the following discussion.

KMLowMapType:
        DC.B    KCF_DEAD+KC_VANILLA     ; aA (Key 20)
                    ...                 ; (more...)
        DC.B    KCF_DEAD+KC_VANILLA     ; hH (Key 25)
                    ...                 ; (more...)
KMLowMap:
        DC.L    key20                   ; a, A, ae, AE
                    ...                 ; (more...)
        DC.L    key25                   ; h, H, dead ^
                    ...                 ; (more...)
;------ possible dead keys
key25:
        DC.B    0,'h',0,'H'             ; h, H
        DC.B    DPF_DEAD,3,DPF_DEAD,3   ; dead ^, dead ^
        DC.B    0,$08,0,$08,0,$88,0,$88 ; control translation
                    ...                 ; (more...)
;------ deadable keys (modified by dead keys)
key20:                  ; a, A, ae, AE
        DC.B    DPF_MOD,key20u-key20    ; deadable flag, number of
                                        ; bytes from start of key20
                                        ; descriptor to start of un-
                                        ; shifted data
        DC.B    DPF_MOD,key20s-key20    ; deadable flag, number of
                                        ; bytes from start of key20
                                        ; descriptor to start of shift-
                                        ; ed data
        DC.B    0,$E6,0,$C6             ; null flags followed by rest
        DC.B    0,$01,0,$01,0,$81,0,$81 ; of values (ALT, CTRL...)
key20u:
        DC.B    'a',$E1,$E0,$E2,$E3,$E4 ; 'a' alone and characters to
                                        ; output when key alone is
                                        ; prefixed by a dead key
        DC.B    $E1,$E1,$E2,$E1,$E1,$E1 ; most recent is '
        DC.B    $E0,$E2,$E0,$E0,$E0,$E0 ; most recent is `
key20s:
        DC.B    'A',$C1,$C0,$C2,$C3,$C4 ; SHIFTed 'a' and characters to
                                        ; output when SHIFTed key is
                                        ; prefixed by a dead key
        DC.B    $C1,$C1,$C2,$C1,$C1,$C1 ; most recent is '
        DC.B    $C0,$C2,$C0,$C0,$C0,$C0 ; most recent is `

In the example, key 25 (the H key) is a dead key and key 20 (the A key) is a deadable key. Both keys use the addresses of their descriptor data areas as entries in the LoKeyMap table. The LoKeyMapTypes table says that there are four qualifiers for both: the requisite KCF_DEAD, as well as KCF_SHIFT, KCF_ALT, and KCF_CONTROL. The number of qualifiers determine length and arrangement of the descriptor data areas for each key. The next table shows how to interpret the KeyMapTypes for various combinations of the qualifier bits. For each possible position a pair of bytes is needed. The first byte in each pair tells how to interpret the second byte (more about this below).

Dead Key Qualifier Bits
If type is: Then the pair of bytes in this position in the dead-class key descriptor data is output when the key is pressed along with:
NOQUAL alone - - - - - - -
A alone - - - - - - -
C alone C - - - - - -
S alone S - - - - - -
A+C alone A C A+C - - - -
A+S alone S A A+S - - - -
C+S alone S C C+S - - - -
S+A+C (VANILLA) alone S A S+A C C+S C+A C+S+A
The abbreviations A, C, S stand for KCF_ALT, KCF_CONTROL, and KCF_SHIFT, respectively. Also note that the ordering is reversed from that in the normal KeyMap table.

Because keys 20 and 25 each use three qualifier bits (not including KCF_DEAD), according to the table there must be 8 pairs of data, arranged as shown. Had only KCF_ALT been set, for instance, (not including KCF_DEAD), just two pairs would have been needed.

As mentioned earlier, the first byte of each data pair in the descriptor data area specifies how to interpret the second byte. There are three possible values: 0, DPF_DEAD and DPF_MOD. In the Amiga 1000 German keymap listed above, DPF_DEAD appears in the data for key 25, while DPF_MOD is used for key 20. It is the use of these flags that determines whether a dead-class key has dead or deadable function. A value of zero causes the unrestricted output of the following byte.

If the flag byte is DPF_DEAD, then that particular key combination (determined by the placement of the pair of bytes in the data table) is dead and will modify the output of the next key pressed (if deadable). How it modifies is controlled by the second byte of the pair which is used as an index into part(s) of the data area for ALL the deadable (DPF_MOD set) keys.

Before going further, an understanding of the structure of a descriptor data area wherein DPF_MOD is set for one (or more) of its members is necessary. Referring to the example, we see that DPF_MOD is set for the first and second pairs of bytes. According to its LoKeyMapTypes entry, and using table above (Dead Key Qualifier Bits) as a guide, these pairs represent the alone and SHIFTed values for the key. When DPF_MOD is set, the byte immediately following the flag must be the offset from the start of the key's descriptor data area to the start of a table of bytes describing the characters to output when this key combination is preceded by any dead keys. This is where the index mentioned above comes in. The value of the index from a prefixing dead key is used to determine which of the bytes from the deadable keys special table to output. The byte in the index+1 position is sent out. (The very first byte is the value to output if the key was not prefixed by a dead key.) Thus, if Alt-H is pressed (dead) and then Shift-A, an 'a' with a circumflex (^) accent will be output. This is because:

  • The byte pair for the ALT position of the "H" key (key 25) is DPF_DEAD,3 so the index is 3.
  • The byte pair for the SHIFT position of the "A" key (key 20) is DPF_MOD, key20s-key20, so we refer to the table-of-bytes at key20s.
  • The third+1 byte of the table-of-bytes is $C2, an 'a' character.
A Note About Table Size
The number of bytes in the table-of-bytes for all deadable keys must be equal to the highest index value of all dead keys plus 1.

Double-Dead Keys

Double-dead keys are an extension of the dead-class keys explained above. Unlike normal dead keys wherein one dead key of type DPF_DEAD can modify a second of type DPF_MOD, double-dead keys employ two consecutive keys of type DPF_DEAD to together modify a third of type DPF_MOD.

For example, the key on the German keyboard labeled with single quotes ('') is a double-dead key. When this key is pressed alone and then pressed again shifted, there is no output. But when followed by an appropriate third key, for example the A key, the three keypresses combine to produce an 'a' with a circumflex (^) accent (character code $E2). Thus the double-dead pair qualify the output of the A key.

The system always keeps the last two down key codes for possible further translation. If they are both of type DPF_DEAD and the key immediately following is DPF_MOD then the two are used to form an index into the (third) key's translation table as follows:

In addition to the index found after the DPF_DEAD qualifier in a normal dead key, a second factor is included in the high nibble of double-dead keys (it is shifted into place with DP_2DFACSHIFT). Its value equals the total number of dead key types + 1 in the keymap. This second index also serves as an identifying flag to the system that two dead keys can be significant.

When a key of type DPF_MOD is pressed, the system checks the two key codes which preceded the current one. If they were both DPF_DEAD then the most recent of the two is checked for the double-dead index/flag. If it is found then a new index is formed by multiplying the value in lower nibble with that in the upper. Then, the lower nibble of the least recent DPF_DEAD key is added in to form the final offset.

Finally, this last value is used as an index into the translation table of the current, DPF_MOD, key.

The translation table of all deadable (DPF_MOD) keys has [number of dead key types + 1] * [number of double dead key types + 1] entries, arranged in [number of double dead key types + 1] rows of [number of dead key types + 1] entries. This is because as indices are assigned for dead keys in the keymap, those that are double dead keys are assigned the lower numbers.

Following is a code fragment from the German (d) keymap source:

key0C:
        DC.B    DPF_DEAD,1+(6<<DP_2DFACSHIFT)   ; dead '
        DC.B    DPF_DEAD,2+(6<<DP_2DFACSHIFT)   ; dead `
        DC.B    0,'=',0,'+'                     ; =, +
key20:                  ; a, A, ae, AE
        DC.B    DPF_MOD,key20u-key20,DPF_MOD,key20s-key20
        DC.B    0,$E6,0,$C6
        DC.B    0,$01,0,$01,0,$81,0,$81 ; control translation
key20u:
        DC.B    'a',$E1,$E0,$E2,$E3,$E4
        DC.B    $E1,$E1,$E2,$E1,$E1,$E1 ; most recent is '
        DC.B    $E0,$E2,$E0,$E0,$E0,$E0 ; most recent is `
key20s:
        DC.B    'A',$C1,$C0,$C2,$C3,$C4
        DC.B    $C1,$C1,$C2,$C1,$C1,$C1 ; most recent is '
        DC.B    $C0,$C2,$C0,$C0,$C0,$C0 ; most recent is `

Raw key0C, the German single quotes ('') key, is a double dead key. Pressing this key alone, then again while the shift key is down will produce no output but will form a double-dead qualifier. The output of key20 (A), a deadable key, will consequently be modified, producing an "a" with a circumflex (^) accent. The mechanics are as follows:

  • When key0C is pressed alone the DPF_DEAD of the first byte pair in the key's table indicates that the key as dead. The second byte is then held by the system.
  • Next, when key0C is pressed again, this time with the Shift key down, the DPF_DEAD of the second byte pair (recall that the second pair is used because of the SHIFT qualifier) again indicates the key is a dead key. The second byte of this pair is also held by the system.
  • Finally, when the A key is pressed the system recalls the latter of the two bytes it has saved. The upper nibble, $6, is multiplied by

the lower nibble, $2. The result, $0C, is then added to the lower nibble of the earlier of the two saved bytes, $1. This new value, $0D, is used as an index into the (unshifted) translation table of key20. The character at position $0D is character $E2, an 'a' with a circumflex (^) accent.

Note About Double Dead Keys
If only one double-dead key is pressed before a deadable key then the output is the same as if the double-dead were a normal dead key. If shifted key0C is pressed on the German keyboard and then immediately followed by key20, the output produced is character $E0 'à'. As before, the upper nibble is multiplied with the lower, resulting in $0C. But because there was no second dead-key, this product is used as the final index.

Keyboard Layout

The keys with key codes $2B and $30 in the following keyboard diagrams are keys which are present on some national Amiga keyboards.

Amiga 1000 Keyboard Showing Key Codes in Hex

Amiga 500/2000 Keyboard Showing Key Codes in Hex

The default values given above correspond to the values the console device will return when these keys are pressed with the keycaps as shipped with the standard American keyboard.

ROM Default (USA0) and USA1 Console Key Mapping
Raw Key Number Keycap Legend Unshifted Default Value Shifted Default Value
00 `~ ` (Accent grave) ~ (tilde)
01 1 ! 1 !
02 2 @ 2 @
03 3 # 3 #
04 4 $ 4 $
05 5 % 5 %
06 6 ^ 6 ^
07 7 & 7 &
08 8 * 8
09 9 ( 9 (
0A 0 ) 0 )
0B - _ - (Hyphen) _ (Underscore)
0C = + = +
0D | |
0E (undefined)
0F 0 0 0 (Numeric pad)
10 Q q Q
11 W w W
12 E e E
13 R r R
14 T t T
15 Y y Y
16 U u U
17 I i I
18 O o O
19 P p P
1A [ { [ {
1B ] } ] }
1C (undefined)
1D 1 1 1 (Numeric pad)
1E 2 2 2 (Numeric pad)
1F 3 3 3 (Numeric pad)
20 A a A
21 S s S
22 D d D
23 F f F
24 G g G
25 H h H
26 J j J
27 K k K
28 L l L
29 ; : ; :
2A ' " ' (single quote) "
2B (not on most U.S. keyboards)
2C (undefined)
2D 4 4 4 (Numeric pad)
2E 5 5 5 (Numeric pad)
2F 6 6 6 (Numeric pad)
30 (not on most U.S. keyboards)
31 Z z Z
32 X x X
33 C c C
34 V v V
35 B b B
36 N n N
37 M m M
38 , < , (comma) <
39 . > . (period) >
3A / ? / ?
3B (undefined)
3C . . . (Numeric pad)
3D 7 7 7 (Numeric pad)
3E 8 8 8 (Numeric pad)
3F 9 9 9 (Numeric pad)
40 Space bar 0x20 0x20
41 Back Space 0x08 0x08
42 Tab 0x09 0x09
43 Enter 0x0D 0x0D
44 Return 0x0D 0x0D (Numeric pad)
45 Esc 0x1B 0x1B
46 Del 0x7F 0x7F
47 (undefined)
48 (undefined)
49 (undefined)
4A - - - (Numeric Pad)
4B (undefined)
4C Up arrow <CSI>A <CSI>T
4D Down arrow <CSI>B <CSI>S
4E Forward arrow <CSI>C <CSI> A (note blank space after <CSI>)
4F Backward arrow <CSI>D <CSI> @ (note blank space after <CSI>)
50 F1 <CSI>0~ <CSI>10~
51 F2 <CSI>1~ <CSI>11~
52 F3 <CSI>2~ <CSI>12~
53 F4 <CSI>3~ <CSI>13~
54 F5 <CSI>4~ <CSI>14~
55 F6 <CSI>5~ <CSI>15~
56 F7 <CSI>6~ <CSI>16~
57 F8 <CSI>7~ <CSI>17~
58 F9 <CSI>8~ <CSI>18~
59 F10 <CSI>9~ <CSI>19~
5A ( ( ( (usa1 Numeric pad)
5B ) ) ) (usa1 Numeric pad)
5C / / / (usa1 Numeric pad)
5D * * * (usa1 Numeric pad)
5E + + + (usa1 Numeric pad)
5F Help <CSI>?~ <CSI>?~
Raw Key Number Function or Keycap Legend
60 Shift (left of space bar)
61 Shift (right of space bar)
62 Caps Lock
63 Ctrl
64 (Left) Alt
65 (Right) Alt
66 Amiga (left of space bar)
67 Amiga (right of space bar)
68 Left mouse button (not converted)
69 Right mouse button (not converted)
6A Middle mouse button (not converted)
6B (undefined)
6C (undefined)
6D (undefined)
6E (undefined)
6F (undefined)
70-7F (undefined)
80-F8 Up transition (release or unpress key of one of the above keys) (80 for 00, F8 for 7F)
F9 Last key code was bad (was sent in order to resynchronize)
FA Keyboard buffer overflow
FB (undefined, reserved for keyboard processor catastrophe)
FC Keyboard selftest failed
FD Power-up key stream start. Keys pressed or stuck at power-up will be sent between FD and FE.
FE Power-up key stream end
FF (undefined, reserved)
FF Mouse event, movement only, no button change (not converted)

Notes about the preceding table:

  1. "<CSI>" is the Control Sequence Introducer, value hex 9B.
  2. (undefined)" indicates that the current keyboard design should not generate this number. If you are using SetKeyMap() to change the key map, the entries for these numbers must still be included.
  3. "(not converted)" refers to mouse button events. You must use the sequence "<CSI>2{" to inform the console driver that you wish to receive mouse events; otherwise these will not be transmitted.
  4. "(RESERVED)" indicates that these key codes have been reserved for national keyboards. The $2B code key will be between the double-quote (") and Return keys. The $30 code key will be between the Shift and Z keys.
ECMA-94 Latin 1 International 8-Bit Character Set

Raw Key Table

The following table defines all of the Amiga raw key codes and what they mean.

Note
All values are in hexadecimal
Raw Key USB Page USB Code PS2 Set 1 Code PS2 Set 2 Code Name Classic Amiga Key
0000 0007 0035 0029 000E `~
0001 0007 001E 0002 0016 1!
0002 0007 001F 0003 001E 2@
0003 0007 0020 0004 0026 3#
0004 0007 0021 0005 0025 4$
0005 0007 0022 0006 002E 5%
0006 0007 0023 0007 0036 6^
0007 0007 0024 0008 003D 7&
0008 0007 0025 0009 003E 8*
0009 0007 0026 000A 0046 9(
000A 0007 0027 000B 0045 0)
000B 0007 002D 000C 004E -_
000C 0007 002E 000D 0055 =+
000D 0007 0031 \| near Backspace
000E 0007 0089 007D 006A Intl 3 Yen
000F 0007 0062 0052 0070 NP 0
0010 0007 0014 0010 0015 qQ
0011 0007 001A 0011 001D wW
0012 0007 0008 0012 0024 eE
0013 0007 0015 0013 002D rR
0014 0007 0017 0014 002C tT
0015 0007 001C 0015 0035 yY
0016 0007 0018 0016 003C uU
0017 0007 000C 0017 0043 iI
0018 0007 0012 0018 0044 oO
0019 0007 0013 0019 004D pP
001A 0007 002F 001A 0054 [{
001B 0007 0030 001B 005B ]}
001C undefined
001D 0007 0059 004F 0069 NP 1
001E 0007 005A 0050 0072 NP 2
001F 0007 005B 0051 007A NP 3
0020 0007 0004 001E 001C aA
0021 0007 0016 001F 001B sS
0022 0007 0007 0020 0023 dD
0023 0007 0009 0021 002B fF
0024 0007 000A 0022 0034 gG
0025 0007 000B 0023 0033 hH
0026 0007 000D 0024 003B jJ
0027 0007 000E 0025 0042 kK
0028 0007 000F 0026 004B lL
0029 0007 0033 0027 004C ;:
002A 0007 0034 0028 0052 '"
002B 0007 0032 002B 005D Intl 1 near Return
002C undefined
002D 0007 005C 004B 006B NP 4
002E 0007 005D 004C 0073 NP 5
002F 0007 005E 004D 0074 NP 6
0030 0007 0064 0056 0061 Intl 2 near LShift
0031 0007 001D 002C 001A zZ
0032 0007 001B 002D 0022 xX
0033 0007 0006 002E 0021 cC
0034 0007 0019 002F 002A vV
0035 0007 0005 0030 0032 bB
0036 0007 0011 0031 0031 nN
0037 0007 0010 0032 003A mM
0038 0007 0036 0033 0041 ,<
0039 0007 0037 0034 0049 .>
003A 0007 0038 0035 004A /?
003B 0007 0087 0073 0051 /? Brazil (near RShift) and International 1 (Ro)
003C 0007 0063 0053 0071 NP .
003D 0007 005F 0047 006C NP 7
003E 0007 0060 0048 0075 NP 8
003F 0007 0061 0049 007D NP 9
0040 0007 002C 0039 0029 SPACE Space
0041 0007 002A 000E 0066 BACKSPACE Backspace
0042 0007 002B 000F 000D TAB Tab
0043 0007 0058 00E01C 00E05A ENTER NP Enter
0044 0007 0028 001C 005A RETURN Return
0045 0007 0029 0001 0076 ESC Escape
0046 0007 004C 00E053 00E071 DEL Delete
0047 0007 0049 00E052 00E070 INSERT Insert
0048 0007 004B 00E049 00E07D PAGE_UP PageUp
0049 0007 004E 00E051 00E07A PAGE_DOWN PageDown
004A 0007 0056 004A 007B NP -
004B 0007 0044 0057 0078 F11 F11
004C 0007 0052 00E048 00E075 CURSOR_UP CrsrUp
004D 0007 0051 00E050 00E072 CURSOR_DOWN CrsrDown
004E 0007 004F 00E04D 00E074 CURSOR_RIGHT CrsrRight
004F 0007 0050 00E04B 00E06B CURSOR_LEFT CrsrLeft
0050 0007 003A 003B 0005 F1 F1
0051 0007 003B 003C 0006 F2 F2
0052 0007 003C 003D 0004 F3 F3
0053 0007 003D 003E 000C F4 F4
0054 0007 003E 003F 0003 F5 F5
0055 0007 003F 0040 000B F6 F6
0056 0007 0040 0041 0083 F7 F7
0057 0007 0041 0042 000A F8 F8
0058 0007 0042 0043 0001 F9 F9
0059 0007 0043 0044 0009 F10 F10
005A NP (
005B NP )
005C 0007 0054 00E035 00E04A NP /
005D 0007 0055 0037 007C NP *
005E 0007 0057 004E 0079 NP +
005F 0007 0075 0046 007E HELP Help (maps to ScrollLock on PS/2)
0060 0007 00E1 002A 0012 LSHIFT LShift
0061 0007 00E5 0036 0059 RSHIFT RShift
0062 0007 0039 003A 0058 CAPSLOCK CapsLock
0063 0007 00E0 001D 0014 CONTROL LControl
0064 0007 00E2 0038 0011 LALT LAlt
0065 0007 00E6 00E038 00E011 RALT RAlt
0066 0007 00E3 00E05B 00E01F LCOMMAND LAmiga, LWin, LApple, LMeta
0067 0007 00E7 00E05C 00E027 RCOMMAND RAmiga, RWin, RApple, RMeta
0068 LBUTTON LMouse reserved
0069 RBUTTON RMouse reserved
006A MBUTTON MMouse reserved
006B 0007 0065 00E05D 00E02F MENU Menu, Windows, Compose (mappable to RAmiga in Firmware)
006C 0007 0085 007E 006D Brazil NP . (named "Keypad ," in USB specs)
006D 0007 0046 00E037 00E07C PRINTSCREEN PrintScreen/SysReq (mappable to Help in Firmware)
006E 0007 0048 00E046 00E07E BREAK Break, Ctrl-Pause on PS/2
006F 0007 0045 0058 0007 F12 F12
0070 0007 004A 00E047 00E06C HOME Home
0071 0007 004D 00E04F 00E069 END End
0072 000C 00B7 00E024 00E03B AUD_STOP Stop, CD32 Blue Stop, CDTV Stop, Port 0 Blue
0073 000C 00CD 00E022 E034 AUD_PLAY_PAUSE Play/Pause, CD32 Grey Play/Pause, CDTV Play/Pause, Port 0 Play
0074 000C 00B6 00E010 E015 AUD_PREV_TRACK Prev Track, CD32 Charcoal Reverse, CDTV << REW, Port 0 Reverse
0075 000C 00B5 00E019 E04D AUD_NEXT_TRACK Next Track, CD32 Charcoal Forward, CDTV >> FF, Port 0 Forward
0076 000C 00B9 AUD_SHUFFLE Random Play, CD32 Green Shuffle, Port 0 Green
0077 000C 00BC AUD_REPEAT Repeat, CD32 Yellow Repeat, Port 0 Yellow
0078 Port 0 Red
0079 Port 0 Joystick Up
007A Port 0 Joystick Down
007B Port 0 Joystick Right
007C Port 0 Joystick Left
007D undefined
007E undefined
007F undefined
0080 - 00F8 Up transition (release or unpress key) (0080 for 0000, 00F8 for 0078)
00F9 Last key code was bad (was sent in order to resynchronize)
00FA Keyboard buffer overflow
00FB (undefined, reserved for keyboard processor catastrophe)
00FC Keyboard selftest failed
00FD Power-up key stream start. Keys pressed or stuck at power-up will be sent between 00FD and 00FE.
00FE Power-up key stream end
00FF No key code defined
0100 0007 0088 0070 0013 Intl 2 Hiragana/Katakana
0101 0007 008A 0079 0064 Intl 4 Henkan
0102 0007 008B 007B 0067 Intl 5 Muhenkan
0103 0007 0068 0064 0008 F13 F13
0104 0007 0069 0065 0010 F14 F14
0105 0007 006A 0066 0018 F15 F15
0180 - 0185 Up transition (release or unpress key) (0180 for 0100)

Function Reference

The following are brief descriptions of the functions covered in this article. See the SDK for details on each function call.

Function Description
AskKeyMapDefault() Ask for a pointer to the current default keymap
CloseKeyMapHandle() Close a keymap handle (V50)
MapANSI() Encode an ANSI string into key codes
MapRawKey() Decode a raw key input event to an ANSI string
ObtainKeyMapInfo() Obtain information about a raw key (V51.7)
OpenKeyMapHandle() Open a keymap handle (V50)
ReleaseKeyMapInfo() Release info obtained from a keymap handle (V50)
SetKeyMapDefault() Set the current default keymap