[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
+---------------------------------+
| INKEY |
+---------------------------------+
INKEY([[<expN>] [, <expC>]])
-----------------------------------
Returns a value corresponding to a key press or a mouse click.
Return value - Numeric.
-----------------------------------
INKEY() returns an integer value corresponding to a key press. 0 is
returned if a key has not been pressed. If there are several keys in
the typeahead buffer, the value of the first key entered in the buffer
is returned.
<expN>
INKEY() accepts an optional numeric expression <expN> that specifies
how many seconds INKEY() will wait for a keystroke. If <expN> isn't
included, INKEY() immediately returns a value for a keystroke. INKEY()
will wait indefinitely for a keystroke if <expN> is 0.
<expC>
Include <expC> to show or hide the cursor or check for a click of the
mouse button. To show the cursor, include the character S in <expC>.
To hide the cursor, include the character H in <expC>. If both S and H
are included in <expC>, the last character in <expC> takes precedence.
The cursor is shown by default. You may also turn the cursor on or off
with SYS(2002) and the SET CURSOR command.
By default, INKEY() will not detect a mouse click. To check for a
mouse click include the character M in <expC>. If M is included in
<expC>, INKEY() will return the value 151 for a single mouse click. To
check for a double click, refer to the second program example below.
To check for a mouse click and show the cursor, include both M and S.
To check for a mouse click and hide the cursor, include H and M.
INKEY() Return Values
Key Alone Shift Ctrl Alt
-----------------------------------
F1 28 84 94 104
F2 -1 85 95 105
F3 -2 86 96 106
F4 -3 87 97 107
F5 -4 88 98 108
F6 -5 89 99 109
F7 -6 90 100 110
F8 -7 91 101 111
F9 -8 92 102 112
F10 -9 93 103 113
F11 133 135 137 139
F12 134 136 138 140
1 49 33 - 120
2 50 64 33 121
3 51 35 - 122
4 52 36 - 123
5 53 37 - 124
6 54 94 30 125
7 55 38 - 126
8 56 42 - 127
9 57 40 - 128
0 48 41 - 19
a 97 65 1 30
b 98 66 2 48
c 99 67 3 46
d 100 68 4 32
e 101 69 5 18
f 102 70 6 33
g 103 71 7 34
h 104 72 8 35
i 105 73 9 23
j 106 74 10 36
k 107 75 11 37
l 108 76 12 38
m 109 77 13 50
n 110 78 14 49
o 111 79 15 24
p 112 80 16 25
q 113 81 17 16
r 114 82 18 19
s 115 83 19 31
t 116 84 20 20
u 117 85 21 22
v 118 86 22 47
w 119 87 23 17
x 120 88 24 45
y 121 89 25 21
z 122 90 26 44
INS 22 48 - -
HOME 1 55 29 -
DEL 7 46 - -
END 6 49 23 -
PGUP 18 57 31 -
PGDN 3 51 30 -
UP 5 56 - -
RIGHT 4 54 2 -
LEFT 19 52 26 -
DOWN 24 50 - -
ESCAPE 27 27 27 -
ENTER 13 13 10 -
BSPACE 127 127 127 -
TAB 9 15 148 165
+---------------------------------+
| Program Examples |
+---------------------------------+
In this example, the system displays a window and input fields and will
wait 20 seconds for keyboard input. If a key is not entered or the
mouse is not clicked, you are returned to the Command window.
SET TALK OFF
STORE 0 TO holdkey
STORE SPACE(40) TO mcustomer, maddress
STORE SPACE(24) TO mcity
STORE SPACE(2) TO mstate
STORE SPACE(10) TO mzip
DEFINE WINDOW menter FROM 7,10 TO 17,70 PANEL
ACTIVATE WINDOW menter
@ 1,3 SAY 'Customer: ' GET mcustomer
@ 3,3 SAY 'Address: ' GET maddress
@ 5,3 SAY 'City: ' GET mcity
@ 7,3 SAY 'State: ' GET mstate
@ 7,18 SAY 'Zip: ' GET mzip
@ 1,14 SAY ''
STORE INKEY(20, 'M') TO mkey
IF mkey = 0
DEACTIVATE WINDOW menter
CLEAR GETS
CLOSE ALL
ELSE
IF mkey # 151
KEYBOARD CHR(mkey)
ENDIF
READ
DEACTIVATE WINDOW menter
ENDIF
****************************
*** Mouse click and keyboard detection example ***
*** Establish the program environment ***
SET TALK OFF
SET ESCAPE OFF
CLEAR
*** Create and open a window ***
DEFINE WINDOW mousechk FROM 4,4 TO 20,75 DOUBLE
ACTIVATE WINDOW mousechk
@ 6,16 SAY 'Press a key or click the mouse to start'
@ 8,16 SAY ' or press the Escape key to quit'
inval1 = 0 && Initialize inkey memory variable
*** Main program loop ***
DO WHILE .T.
inval1 = INKEY(.06,'HM') && Get INKEY(), hide cursor, check; mouse
IF inval1 = 0 && No key or mouse press
LOOP
ENDIF
IF inval1 = 27 && Escape key pressed, exit main loop
EXIT
ENDIF
IF inval1 = 151 && Single mouse click
row = MROW() && Get mouse pointer position
col = MCOL()
timelimit = SECONDS() + _DBLCLICK && Time for double click
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson