## Display Device Driver Reference for OS/2

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

### Keyboard Key Reassignment

The ANSI system can be used to reassign keys on the keyboard. When an application calls KbdStringIn, the reassigned key's ASCII code is converted to the specified string and is passed back to the calling application. For example, replace a with q so that whenever the a key is pressed, a q is passed to the application that is reading input.

In OS/2 2.1, keyboard remapping can be done only from an application calling KbdStringIn. In DOS, keyboard remapping must be done from the command line.

Note: Keyboard reassignment works only with OS/2 applications that use the KbdStringIn call to get input.

OS/2 mode ANSI is affected when keys are reassigned in a code-page environment. ANSI "remembers" the code page under which a key is reassigned . The keyboard subsystem checks for reassigned keys when the application calls the KbdStringIn function. When a reassigned key is detected, the ANSI support:

1.Checks to see what code page the requestor is running under
2.Looks internally to see if the key has been reassigned under that code page
3.If there is a key reassignment for that code page, gives the reassignment string
4.Otherwise, gives the original ASCII codes.

A maximum storage of 64KB can be allocated to OS/2 mode ANSI-reassigned key definitions. The table shown below contains the control sequences used to redefine the meaning of keyboard keys:

    /--------------------------------------------------------------\

    | The control sequence is:     |Function                       |

    |------------------------------+-------------------------------|

    |    ESC [#;#;...#p            |The first ASCII code in the    |

    |or  ESC ["string"p            |control sequence defines which |

    |or  ESC [#;"string";#;#;      |code is being mapped.  The     |

    |    "string";#p               |remaining numbers define the   |

    |or  any other combination     |sequence of ASCII codes        |

    |    of strings and decimal    |generated when this key is     |

    |    numbers                   |intercepted.  However, if the  |

    |                              |first code in the sequence is  |

    |                              |0 (NULL), the first and second |

    |                              |code make up an extended ASCII |

    |                              |redefinition.                  |

    \--------------------------------------------------------------/

To execute the examples below, either create a file that contains the following statements and then use the TYPE command to display the file that contains the statement, or execute the command at the OS/2 prompt:

Assign the A and a key to the Q and q key, respectively.

Assign the Q and q key to the A and a key, respectively:

Using a File:

    ESC [65;8lp          A becomes Q
    ESC [97;113p         a becomes q
    ESC [81;65p          Q becomes A
    ESC [113;97p         q becomes a

At the OS/2 Prompt:

    prompt $e[65;8lp     A becomes Q
    prompt $e[97;113p    a becomes q
    prompt $e[81;65p     Q becomes A
    prompt $e[113;97p    q becomes a

Reassign the F10 key to a DIR command followed by a carriage return:

Using a File:

    ESC [0;68;"dir";13p

At the OS/2 Prompt:

      prompt $e[0;68;"dir";13p

The $e is the prompt command characters for ESC. The 0;68 is the extended ASCII code for the F10 key; 13 decimal is a carriage return.

The following example sets the prompt to display the current directory on the top of the screen and the current drive on the current line:

        prompt $e[s$e[1;30f$e[K$p$e[u$n$g

If the current directory is C:\FILES, and the current drive is C, this example would display:

                 C:\FILES
    C>

The following DOS-compatible assembly language program reassigns the F10 key to a DIR B: command followed by a carriage return:

            TITLE SET ANSI.ASM - SET F10 TO STRING FOR ANSI.SYS

    CSEG      SEGMENT   PARA   PUBLIC   ' CODE '
             ASSUME   CS : CSEG , DS : CSEG
             ORG       100H
    ENTPT :    JMP       SHORT   START
    STRING    DB        27 , ' [ 0 ; 68 ; " DIR   B : " ; 13P '   ; Redefine   F10   key
    STRSIZ    EQU       $ - STRING                   ; Length   of   above   message
    HANDLE    EQU       1                           ; Pre - defined   file .
                                                ; Handle   for   standard   output

    START     PROC      NEAR
             MOV       BX , HANDLE                  ; Standard   output   device
             MOV       CX , STRSIZ                  ; Get   size   of   text   to   be   sent
             MOV       DX , OFFSET   STRING          ; Pass   offset   of   string
                                                ; To   be   sent
             MOV       AH , 40H                     ; Function = " write   to   device "
             INT       21h                         ; Call   DOS
             RET                                 ; Return   to   DOS
    START     ENDP

    CSEG      ENDS
             END       ENTPT