Function fgl_keyval() returns the integer code of a logical or physical key.
The fgl_keyval( ) function returns NULL unless its argument specifies one of the following physical or logical keys:
any of the keywords shown below, whether typed in upper or lowercase:
ACCEPT, CONTROL-char (except A, D, H, I, J, M, L, R or X)
DELETE, DOWN, ESC or ESCAPE, F1 to F64
HELP, INSERT, INTERRUPT, LEFT, NEXT or NEXTPAGE
PREVIOUS, PREVIOUSPAGE, RETURN, RIGHT, TAB, UP
The argument should always be placed between speech marks. If a single letter is specified,
fgl_keyval() becomes case-sensitive. When more than one character is used as the argument the case is not considered.
If the argument is invalid, fgl_keyval() returns NULL.
This code sample presents a message console that displays the integer value of the Escape key.
MAIN
DISPLAY "fgl_keyval(\"escape\") - Escape Key has the following value: ", fgl_keyval("escape")
SLEEP 10
END MAIN
This code sample presents a message console that displays the integer value of any keyboard key that the user presses:
MAIN
DEFINE key_press int
LET key_press = 0
OPEN WINDOW w_test WITH FORM "fgl_keyval_form"
WHILE key_press != fgl_keyval("escape")
LET key_press = fgl_getkey()
DISPLAY key_press TO f_key
END WHILE
CLOSE WINDOW w_test
END MAIN
DATABASE formonly
SCREEN
{
*** FGL_KEYVAL() Example ***
Press ACCEPT button to start
reading its value or
press Escape to quit.
You have pressed: [f001 ]
}
ATTRIBUTES
f001=formonly.f_key;
The screen shot taken from the fgl_keyval2_function program shows the result of the user pressing the ‘f’ key on the keyboard.
fgl_keyval() can be used in form-related statements to examine a value returned by fgl_getkey() or fgl_lastkey(). By comparing the values returned by fgl_keyval() with what fgl_getkey() or fgl_lastkey() returns, you can determine whether the last key that the user pressed was a specified logical or physical key. Typically, you are most likely to use the fgl_keyval() function in conditional statements and Boolean comparisons:
MAIN
DEFINE x CHAR
DEFINE msg CHAR(100)
DISPLAY "*** fgl_lastkey() Example 1 ***" at 1,5
PROMPT "Press any key" FOR CHAR x
LET msg = "You pressed a key with value: ", fgl_lastkey()
CALL fgl_message_box(msg)
END MAIN
To determine whether the user performed some action, such as inserting a row, specify the logical name of the action (such as INSERT) rather than the name of the physical key (such as F1). For example, the logical name of the default Accept key is ESCAPE. To test if the key most recently pressed by the user was the Accept key, specify fgl_keyval("ACCEPT") rather than fgl_keyval("escape") or fgl_keyval("ESC"). Otherwise, if a key other than ESCAPE is set as the Accept key and the user presses that key, fgl_lastkey() does not return a code equal to fgl_keyval("ESCAPE"). The value returned by fgl_lastkey() is undefined in a MENU statement.