Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recognize INKEY() 1

Status
Not open for further replies.

Rosciano

Technical User
Jun 16, 2003
64
0
0
IT
Hi,

There is another thing I couldn’t do: using/checking the Environment Function INKEY()

I did all I now to check this function, but it always return me a 0 (zero).
I’m trying to recognize the ENTER key when pressed. INKEY()returns a zero and it should be (as far as I know) a 13.

Sorry to ask this banalities, but I’m fixing a very old dbase program and my knowledge about this program language is very scarce, that’s why I asking you, people that know exactly how to cut the cheese [wink]

(Any other way of recognize when press the ENTER key would be appreciated)

Thanks [smile]
Antonio

P.S.
My program is dBase III Plus V 1.1 - The Function READKEY() returns ALWAYS 271 - What am I doing wrong?
 
It's been a while since I worked with dBase. (One reason is that the version I had, dBase 5.0 for DOS only worked up to Windows XP operating systems. When I jumped from XP to Win 7, it stopped working.) Probably you need to find a DBASE language manual. Somewhat similar Visual FoxPro probably hasn't changed it much since it branched off.

In VFP the INKEY() function without a value as parameter returns the current key pressed. Using INKEY(0) forces it to wait for a keypress.

The codes can be found here:

Code:
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 127 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 22 146 162
HOME 1 1 29 151
DEL 7 7 147 163
END 6 6 23 159
PGUP 18 18 31 153
PGDN 3 51 30 161
UP 5 5 141 152
RIGHT 4 4 2 157
LEFT 19 19 26 155
DOWN 24 24 145 160
ESCAPE 27 27 27 1
ENTER 13 13 10 28
BSPACE 127 127 127 14
TAB 9 15 148 165
 
Thank you dbMark, but nothing to do...

Could you explain me how to check the pressed key from the beginning, from the dBase dot prompt?

I got two books: “Using dBase III Plus” writing by E. Jones - 1987 where INKEY() doesn’t exist (see attached index image), and “dBase III / III Plus - Instant Reference” by Alan Simpson - 1988, where INKEY() do appear, but I wasn’t able to check… [evil]

IndexA_kg7rn6.jpg


Thanks.
 
 http://files.engineering.com/getfile.aspx?folder=ca874379-4de4-4165-9a64-19982b654673&file=Index.jpg
Here's another link:
INKEY([<seconds expN>] [, <mouse expC>])

<seconds expN>

The number of seconds INKEY( ) waits for a keystroke. Fractional times are allowed. If <expN> is zero, INKEY( ) waits indefinitely for a keystroke. If <expN> is less than zero, the parameter is ignored.

<mouse expC>

Determines whether INKEY( ) returns a value when you click the mouse. If <expC> is "M" or "m", INKEY( ) returns –100. If <expC> is not "M" or "m", INKEY( ) ignores a mouse click and waits for a keystroke.

The above is probably current behavior. I can't verify how your earlier version from the 1980s handled it. Try this at the dot prompt:
Code:
? INKEY(0)
 
Hi dbMark,

in response to your post, I had attached two images that talk by themselves.
inkey2_njwut6.jpg

inkey_z7wgyl.jpg


Thank you anyway.

Antonio
 
Time ago, I did the following code to know the accented letters to use with CHR().
Notice that Inkey NEVER change. ('x' lower case to exit)

*AS.PRG
set talk off
wrow=1
wcol=1
ab=0
clear
do while ab<255
set color to r+
@ wrow,wcol say ab pict '999'
set color to
@ wrow,wcol+4 say chr(ab) pict 'aa'
ab=ab+1
wrow=wrow+1
if wrow=25
wrow=1
wcol=wcol+7
endif
if ab=255
set color to r
@ wrow,wcol say 'TheEnd'
wrow=wrow+2
endif
enddo
re=' '
set color to b
@ wrow,wcol-1 say 'READKEY()'
wrow=wrow+1
@ 24,wcol-1 say 'x to exit'
do while re<>'x'
set color to w
@wrow,wcol-1 say 'Key:' get re
read
if readkey()=15
set color to r
@ wrow+1,wcol say '15! '
@ wrow+2,wcol-1 say 'Inkey():'
@ wrow+3,wcol say INKEY()
else
set color to gr+
@ wrow+1,wcol say 'Not 15!'
@ wrow+2,wcol-1 say 'Inkey():'
@ wrow+3,wcol say INKEY()
endif
enddo
 
Place a space after the '?' and try that.

? INKEY(0)

If that minor change does not work then it is possible your function's early version will not accept a parameter. How about this? Understand that it is an endless loop that will display the number of the key combinations pressed until the ESC key is pressed.

Code:
DO WHILE LASTKEY() <> 27  && Exit loop if ESC key was pressed
   nVal = INKEY()
   IF nVal <> 0
      ? nVal
   ENDIF
ENDDO
 
With SPACE (it also works without):

inkey_rhtpri.jpg


Your code:

inkey1_tsneen.jpg


inkey2_w3uhn8.jpg


In my dBase, LASTKEY() doesn't exist:

inkey3_ujq1hh.jpg
 
Try this:
Code:
DO WHILE .T.  && potentially endless loop
   nVal = INKEY()
   IF nVal <> 0
      ? nVal
      IF nVal = 27
         EXIT  && Exit loop if ESC key was pressed
      ENDIF
   ENDIF
ENDDO
 
Nothing...

Loops with 0's.
Doesn't respond to any key pressed.

inkey1_yt3pxb.jpg


inkey_qxbzyf.jpg


[sad]
 
What you saw was the looping while waiting for input. I have added SET TALK ON|OFF lines to avoid that. SET TALK ON is helpful at the dot prompt but is usually set OFF within applications.

Code:
DO WHILE .T.  && potentially endless loop
   SET TALK OFF  && hides variable assignments
   nVal = INKEY()
   SET TALK ON
   IF nVal <> 0
      ? nVal
      IF nVal = 27  && Not needed if SET ESCAPE ON
         EXIT       && Exit loop if ESC key was pressed
      ENDIF
   ENDIF
ENDDO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top