Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: How To (Forms, Reports, and more) > Forms > Technical Documents > Capturing Keyboard Events

On Key Press EEP

Scroll Prev Top Next More

The On Key Press EEP will execute when the user presses an alphanumeric or character-generating key. Within the On Key Press EEP, the GETPROPERTY LastKeyPressed parameter is accepted to recognize what key is pressed.

 

Syntax:

 

GETPROPERTY FormComponentID| 'LastKeyPressed' 'vKey'

 

Where:

 

The returned text value for vKey is the last alphanumeric/printable key that was pressed.

 

Notes:

 

The key value returned by the LastKeyPressed syntax is only recognized within the On Key Press EEP.

 

The syntax cannot capture key combinations or special keys like function (Fn), arrow, Home, Page Up, etc. However, some special key combinations can be captured such as Ctrl+A, Ctrl+Z, and Ctrl+Enter which result to ASCII character #1 up to character #26. Ctrl+Enter is equal to Ctrl+J.

 

It is highly recommended to create a catch mechanism within the On Key Press EEP in order to prevent a condition where the EEP will continually fire if a key is held down for a long time period. See the example below where the IsKeyDown variable is used.

 

Capturing Shift, Ctrl, and Alt

The GETPROPERTY command also supports the recognition if the Shift, Ctrl, and Alt keys when pressed.

 

GETPROPERTY FormComponentID| 'ShiftIsPressed' 'iShiftIsPressed'

GETPROPERTY FormComponentID| 'CtrlIsPressed' 'iCtrlIsPressed'

GETPROPERTY FormComponentID| 'AltIsPressed' 'iAltIsPressed'

 

The returned integer value for ShiftIsPressed, CtrlIsPressed, and AltIsPressedand is 1 if the appropriate key is pressed. The returned value of 1 by the syntax is recognized within the "On Key Down", "On Key Press", and "On Key Up" EEPs.

 

Example:

-- To catch and prevent a number character for the entire form

 

-- Form "On Before Start" EEP

SET VAR vText TEXT = NULL

SET VAR vIsKeyDown INTEGER = 0

RETURN

 

-- Form "On Key Press" EEP

IF vIsKeyDown = 1 THEN

RETURN

ENDIF

 

SET VAR vIsKeyDown = 1

SET VAR vKey TEXT = NULL

 

GETPROPERTY NoNumForm| 'LastKeyPressed' 'vKey'

 

IF vKey = '0' OR vKey = '1' OR vKey = '2' OR vKey = '3' OR vKey = '4' +

OR vKey = '5' OR vKey = '6' OR vKey = '7' OR vKey = '8' OR vKey = '9' THEN

PROPERTY NoNumForm| 'LastKeyPressed' 'NULL'

PAUSE 2 USING 'No Numbers are accepted.' CAPTION 'On Key Press' +

ICON INFO BUTTON 'OK'

ENDIF

 

SET VAR vIsKeyDown = 0

RETURN