>We have a foxprogram that talks to a weighing-scale. At this point we have been using the inkey to make sure the scale weight is read at regular intervals but it is clear that the inkey has somewhat strange behavior.
>
>In order to make sure that we are talking to a scale on a 1/10 of a second basis we used the inkey(0.1) to make sure this worked.
>Testing has showed us that the 0.1 interval is not strictly enforced. It may fluctuate from 0.05 to 0.25 even when we are not doing anything else on the pc.
>
>Thinking that the inkey is nothing but a loop we decided to replace inkey with a while-loop. This is what is looks like:
>
>CLEAR
>pntimeout = 0.1
>
>?'Timeout ' + STR(pntimeout ,5, 3)
>pnSeconds = seconds()
>plContinue = .T.
>DO WHILE plContinue
> DO WHILE .T. and plcontinue and CHRSAW() = .F.
> ?'waiting...'
> IF SECONDS() - pnseconds > pntimeout
> EXIT
> ENDIF
> ENDDO
>
> IF CHRSAW() = .T.
> ?lastkey() + asc(lastkey() )
> * plContinue = .F.
> keyboard chr(0) clear
> ELSE
> ENDIF
>ENDDO
>
>The problem I'm now running into is the following.
>I want to test if the user is pressing any keys in between and accordingly I want to do some other stuff as well.
>I have no problems determining that the user pressed 'a' key. What I can't figure out is 'What key did he/she push'. The lastkey() is not returning what I expect.
>
>Can anyone share light into this.
>Thanks in advance,
>
>Ron Brahma
Ron,
inkey(0.1) means wait for a key for 0.1 seconds at max, not wait 0.1 secs before checking a key. You'd need a loop as you did to enforce it, however using seconds() is dangerous if this routine could be running around midnight (SECONDS() - pnseconds > pntimeout would be true about 24 hrs later).
LastKey() returns same but you might as well use inkey() to read and clear buffer in one step :
? lastkey() + asc(lastkey() ) && typo ? lastkey() returns numeric keycode
lnKeyCode = inkey()
keyboard chr(0)
Cetin