KeyCode()

Syntax

KeyCode(Count [Context] [FirstOrSecond])

Remarks

Returns a number representing a key assignment that differs from the default assignment. For tables of key codes and the keys they represent, see ToolsCustomizeKeyboard.

Argument

Explanation

Count

A number in the range 1 to CountKeys() specifying the custom key assignment for which you want to return a key code

Context

The template containing the custom key assignment:

0 (zero) or omitted Normal template

1 Active template

FirstOrSecond

If the key assignment is a sequence of two key combinations (for example, if you've assigned CTRL+S, N to NormalStyle), specifies which key combination to return a code for:

1 The first key combination in the sequence

2 The second key combination in the sequence

If you specify 2 and the key assignment is not a key sequence, KeyCode() returns 255 (the null key code).


Example

This example inserts a table of key codes and macro names for key assignments in the active template that differ from the default assignments:


If CountKeys(1) = 0 Then
    MsgBox "No custom key assignments in active template."
    Goto bye
End If
FormatTabs .ClearAll
FormatTabs .Position = "1in", .Set
Bold 1 : Underline 1
Insert "Key Code" + Chr$(9) + "Macro"
Bold 0 : Underline 0
For i = 1 To CountKeys(1)
    Insert Chr$(13) + Str$(KeyCode(i, 1))
    combo2 = KeyCode(i, 1, 2)
    If combo2 <> 255 Then Insert "," + Str$(combo2)
    Insert Chr$(9) + KeyMacro$(i, 1)
Next i
bye:

See Also

CountKeys(), KeyMacro$()