NvtTranslateMappedKey
BOOL NvtTranslateMappedKey(
HDISPLAY hDisplay,  
UINT nKey,  
UINT nFlags,  
UINT * lpnMappedKey,  
LPTSTR lpszKeyBuffer,  
UINT cchBuffer  
);

The NvtTranslateMappedKey function translates a virtual key press to an escape sequence based on the current terminal emulation that has been selected.

Parameters

hDisplay
Handle to the virtual display.
nKey
The virtual key code for the specified key.
nFlags
The scan code, key-transition code, previous key state, and context code for the specified key.
lpnMappedKey
A pointer to an unsigned integer which will contain the index into the keymap table when the function returns. This is the same value used with the NvtGetMappedKey and NvtSetMappedKey function. If the index into the keymap is not required, this parameter can be NULL.
lpszKeyBuffer
Address of the buffer to receive the escape sequence mapped to the specified key. If the mapped key string is not required, this parameter can be NULL.
cchBuffer
The maximum number of characters that can be copied into the key buffer, including the terminating null byte. If the lpszKeyBuffer parmameter is NULL, this value must be zero.

Return Value

If the virtual key can be mapped to an escape sequence, the function will return a non-zero value. If the key is not mapped, or one of the arguments is invalid, the function will return zero.

Remarks

The NvtTranslateMappedKey function allows an application to map a virtual key code to an escape sequence that is appropriate for the type of terminal that is being emulated. For example, it will return the escape sequence for the F1 function key when passed the VK_F1 key value. This function should be called when the WM_KEYDOWN message is processed by an application so that it may send the correct sequence to the remote host.

This function should only be called in response to a keyboard message such as WM_KEYDOWN. To determine if a specific key has been mapped to an escape sequence, use the NvtGetMappedKey function.

Example

case WM_KEYDOWN:
    /* 
     * If the Num Lock key is pressed, then set the terminal into application 
     * keypad mode. This will change how the NvtTranslateMappedKey function will 
     * translate the keypad keys. 
     * 
     * Note that the terminal may also be placed into application keypad mode 
     * if emulating a DEC VT terminal and the DECNKM escape sequence is sent 
     * by the host. 
     */
    if (wParam == VK_NUMLOCK)
        NvtSetDisplayMode(hDisplay, NVT_MODE_APPKEYPAD, !(GetKeyState(VK_NUMLOCK) & 1));
    else
    {
        BOOL bMapped;
        UINT nMappedKey;
        TCHAR szKey[128];
                        
        bMapped = NvtTranslateMappedKey(hDisplay, wParam, HIWORD(lParam),
                                        &nMappedKey, szKey, 128);

        if (bMapped)
            TelnetWrite(hClient, szKey, lstrlen(szKey));
    } 
    break;

Requirements

Client: Requires Windows Vista, Windows XP or Windows 2000 Professional.
Server: Requires Windows Server 2008, Windows Server 2003 or Windows 2000 Server.
Header: Include cstools6.h.
Library: Use csnvtav6.lib.
Unicode: Implemented as Unicode and ANSI versions.

See Also

NvtGetDisplayMode, NvtGetMappedKey, NvtResetMappedKeys, NvtSetDisplayMode, NvtSetMappedKey


Copyright © 2008 Catalyst Development Corporation. All rights reserved.