Function TBApplyKey() Foundation
Processes a key code (Inkey() value) for a TBrowse object.
TBApplyKey( <oTbrowse>, <nKey> ) --> nBrowseDirection
The function TBApplyKey() returns a numeric code which identifies the direction in which the TBrowse cursor is to be moved in the next stabilization cycle. The return value orients itself to the numeric keypad (2 means "down", 6 means "to the right" etc). When the Inkey code is not processed, the return value is zero and the Tbrowse cursor is not moved. If the key with the Inkey code <nKey> is linked to a code block via the function SetKey(), the code block is evaluated and the function returns -1.
The TBrowse function TBApplyKey() implements the default behavior of TBrowse objects for processing key codes such as those returned by the function Inkey(). It is a service function for programming with TBrowse objects and its source code is contained in the file BROWUTIL.PRG.
The default behavior for keyboard navigation of TBrowse objects implemented by the function TBApplyKey() is shown in the following table:
Key | Inkey constant | Action |
---|---|---|
Up Arrow | K_UP | Previous row |
Down Arrow | K_DOWN | Next row up |
Left Arrow | K_LEFT | One column to the left |
Right Arrow | K_RIGHT | One column to the right |
Home | K_HOME | Left column in the window |
End | K_END | Right column in the window |
Page Up | K_PGUP | One screen up |
Page Down | K_PGDN | One screen down |
Ctrl+Left Arrow | K_CTRL_LEFT | Scrolls columns to the left |
Ctrl+Right Arrow | K_CTRL_RIGHT | Scrolls columns to the right |
Ctrl+Home | K_CTRL_HOME | First column |
Ctrl+End | K_CTRL_END | Last column |
Ctrl+Page Up | K_CTRL_PGUP | First row of the table |
Ctrl+Page Down | K_CTRL_PGDN | Last row of the table |
The return value of TBApplyKey() contains information about the direction in which the TBrowse cursor will be moved in the next stabilization cycle. Possible return values are as follows:
Return value | Direction for TBrowse cursor |
---|---|
8 | Up |
6 | To the right |
4 | To the left |
2 | Down |
0 | TBrowse cursor is not moved |
-1 | TBrowse cursor is not moved, because a SetKey() code block was evaluated |
// The example generates a TBrowse object and illustrates how
// TBApplyKey() can be used for the navigating a TBrowse
// object with the keyboard.
#include "Inkey.ch"
PROCEDURE Main
LOCAL oTB, nDirection, nKey
USE Address // open file
oTB := TBrowseDB( 2, 2, 22, 78 ) // produce TBrowse
AEval( DbStruct(), {|a| oTB:AddColumn( ;
TBColumn():new( a[1], ;
FieldBlock(a[1]) ) ) } )
CLS
@ 1,1 TO 23,79 DOUBLE
oTB:forceStable() // display complete TBrowse
nKey := 0
DO WHILE nKey <> K_ESC // terminate on Esc
DO WHILE ! oTB:stabilize() // incremental display
IF (nKey := Inkey()) <> 0
EXIT
ENDIF
ENDDO
IF oTB:stable // TBrowse is stable
nKey := Inkey(0) // wait for keystroke
ENDIF
// process key
nDirection := TBApplyKey( oTB, nKey )
@ MaxRow(), 0 // display browse direction
?? "Browse direction:", nDirection
ENDDO
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.