Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I tell what the last pressed key is?
Message
De
08/05/2001 08:16:47
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00504620
Message ID:
00504631
Vues:
15
>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() 
&& Above is same as 'lnKeyCode = lastkey()' but clears buffer off last char
keyboard chr(0) && If you have reason to key chr(0) - which would refill buffer
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform