KEYCODE function
- Last Updated: February 11, 2026
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Evaluates a key label (such as F1) for a key in the predefined set of keyboard keys and returns the corresponding = key code (such as 301) as an INTEGER value. See OpenEdge Programming Interfaces for a list of key codes and key labels.
Note: Does not apply to SpeedScript programming.
Syntax
|
- key-label
- A constant, field name, variable name, or expression that evaluates to a character string that contains a key label. If key-label is a constant, enclose it in quotation marks (" ").
Example
This
procedure displays a menu and highlights different selections on
the menu depending on which key you press. On the first iteration
of the REPEAT block, the COLOR statement tells the AVM to color msg[ix] with
the same color used to display messages. Because the initial value
of ix is 1, msg[ix] is the first
menu selection. Therefore, the first menu selection is colored MESSAGES.
r-keycod.p
|
When you press the cursor-down key, the following occurs:
- The READKEY statement reads the value of the key you pressed.
- The first IF . . . THEN . . . ELSE statement tests to see if
the key code of the key you pressed is CURSOR-DOWN. It also checks
whether the value of
ixis less than 3. Both of these things are true, so the procedure adds one to the value ofnewi, makingnewiequal two. - The next two IF statements are ignored because the condition
in the first IF statement was true. The procedure continues on the
last IF statement: IF
ix<>newiTHEN COLOR DISPLAY NORMAL msg[ix] WITH FRAME menu. - Remember,
ixis still 1 butnewiis now 2. Thus,ixis not equal tonewi. Which means that the IF statement test is true. Therefore, the AVM colorsmsg[ix], which is stillmsg[1](the first menu selection), NORMAL. So the first menu selection is no longer highlighted. - Just before the end of the REPEAT block,
ixis set equal tonewi. Which means thatmsg[ix]] is nowmsg[2], or the second menu selection. - On the next iteration, the COLOR statement colors
msg[ix], that is the second menu selection, MESSAGES. The end result of pressing CURSOR-DOWN is that the highlight bar moves to the second menu selection.