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 Down EEP

Scroll Prev Top Next More

The On Key Down EEP will execute when the user presses a key. Within the On Key Down EEP, the GETPROPERTY LastKeyDown parameter is accepted to recognize what key is pressed.

 

Syntax:

 

GETPROPERTY FormComponentID| 'LastKeyDown' 'iKeyCode'

 

Where:

 

The returned integer value for LastKeyDown is the virtual-key code of the of physical key on the keyboard.

 

Notes:

 

The virtual-key code is not to be confused with the actual keyboard characters. See Virtual-Key Codes.

 

The key code value returned by the LastKeyDown syntax is only recognized within the On Key Down EEP.

 

It is highly recommended to create a catch mechanism within the On Key Down 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.

 

Examples:

 

--Example 01:

-- To catch and display the pressed Function Key (Fn) within a label

 

-- Form "On Before Start" EEP

SET VAR vText TEXT = NULL

SET VAR vIsKeyDown INTEGER = 0

RETURN

 

-- Form "On Key Down" EEP

IF vIsKeyDown = 1 THEN

RETURN

ENDIF

 

SET VAR vIsKeyDown = 1

SET VAR iKeyCode TEXT = NULL

 

GETPROPERTY TrapFunctionKeyForm| 'LastKeyDown' 'iKeyCode'

 

SWITCH (.iKeyCode)

 CASE '112'

   PROPERTY FKeyLabel CAPTION 'F1'

   BREAK

 CASE '113'

   PROPERTY FKeyLabel CAPTION 'F2'

   BREAK

 CASE '114'

   PROPERTY FKeyLabel CAPTION 'F3'

   BREAK

 CASE '115'

   PROPERTY FKeyLabel CAPTION 'F4'

   BREAK

 CASE '116'

   PROPERTY FKeyLabel CAPTION 'F5'

   BREAK

 CASE '117'

   PROPERTY FKeyLabel CAPTION 'F6'

   BREAK

 CASE '118'

   PROPERTY FKeyLabel CAPTION 'F7'

   BREAK

 CASE '119'

   PROPERTY FKeyLabel CAPTION 'F8'

   BREAK

 CASE '120'

   PROPERTY FKeyLabel CAPTION 'F9'

   BREAK

 CASE '121'

   PROPERTY FKeyLabel CAPTION 'F10'

   BREAK

 CASE '122'

   PROPERTY FKeyLabel CAPTION 'F11'

   BREAK

 CASE '123'

   PROPERTY FKeyLabel CAPTION 'F12'

   BREAK

ENDSW

 

SET VAR vIsKeyDown = 0

RETURN

 

Example 02:

-- To catch and display if [Ctrl]+[Alt]+[F5] is pressed

 

-- Form "On Before Start" EEP

SET VAR vIsKeyDown INTEGER = 0

RETURN

 

-- Form "On Key Down" EEP

IF vIsKeyDown = 1 THEN

RETURN

ENDIF

 

SET VAR vIsKeyDown = 1

SET VAR iCtrlIsPressed TEXT = NULL

SET VAR iAltIsPressed TEXT = NULL

SET VAR iKeyCode TEXT = NULL

 

GETPROPERTY CtrlAltF5Form| 'CtrlIsPressed' 'iCtrlIsPressed'

GETPROPERTY CtrlAltF5Form| 'AltIsPressed' 'iAltIsPressed'

GETPROPERTY CtrlAltF5Form| 'LastKeyDown' 'iKeyCode'

 

IF iCtrlIsPressed = '1' AND iAltIsPressed = '1' AND iKeyCode = '116' THEN

PAUSE 2 USING 'Ctrl + Alt + F5 was pressed.' ICON INFO BUTTON 'OK'

ENDIF

 

SET VAR vIsKeyDown = 0

RETURN