Key

Description

Occurs when the user presses a key.

Event ID

Event ID

Objects

pbm_lvnkeydown

ListView

pbm_renkey

RichTextEdit

pbm_tcnkeydown

Tab

pbm_tvnkeydown

TreeView

pbm_keydown

Window


Arguments

Argument

Description

key

KeyCode by value. A value of the KeyCode enumerated datatype indicating the key that was pressed (for example, KeyA! or KeyF1!).

keyflags

UnsignedLong by value (the modifier keys that were pressed with the key).

Values are:

1 Shift key

2 Ctrl key

3 Shift and Ctrl keys


Return Values

Long.

Return code choices (specify in a RETURN statement):

0 -- Continue processing

1 -- Do not process the key (RichTextEdit controls only)

Usage

Some PowerBuilder controls capture keystrokes so that the window is prevented from getting a Key event. These include ListView, TreeView, Tab, RichTextEdit, and the DataWindow edit control. When these controls have focus you can respond to keystrokes by writing a script for an event for the control. If there is no predefined event for keystrokes, you can define a user event and associate it with a pbm code.

For a RichTextEdit control, pressing a key can perform document formatting. For example, Ctrl+b applies bold formatting to the selection. If you specify a return value of 1, the document formatting associated with the key will not be performed.

If the user presses a modifier key and holds it down while pressing another key, the Key event occurs twice: once when the modifier key is pressed and again when the second key is pressed. If the user releases the modifier key before pressing the second key, the value of keyflags will change in the second occurrence.

When the user releases a key, the Key event does not occur. Therefore, if the user releases a modifier key, you do not know the current state of the modifier keys until another key is pressed.

Examples

This example causes a beep when the user presses F1 or F2, as long as Shift and Ctrl are not pressed:

IF keyflags = 0 THEN
   IF key = KeyF1! THEN
      Beep(1)
   ELSEIF key = KeyF2! THEN
      Beep(20)
   END IF
END IF

This line displays the value of keyflags when a key is pressed.

st_1.Text = String(keyflags)

See also

SystemKey