Key event
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 |
Parameters
Argument |
Description |
---|---|
key |
KeyCode by value. A value of the KeyCode |
keyflags |
UnsignedLong by Values are:
|
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:
1 |
IF keyflags = 0 THEN |
1 |
   IF key = KeyF1! THEN |
1 |
      Beep(1) |
1 |
   ELSEIF key = KeyF2! THEN |
1 |
      Beep(20) |
1 |
   END IF |
1 |
END IF |
This line displays the value of keyflags when
a key is pressed.
1 |
st_1.Text = String(keyflags) |