Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
On Escape
Message
De
28/02/2001 11:14:29
 
 
À
28/02/2001 07:43:58
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Divers
Thread ID:
00480291
Message ID:
00480552
Vues:
13
>Hi ed,
>
>>>
IF CHRSAW() OR MDOWN()
>>>   DOEVENTS
>>>ENDIF
>>
>>Actually, I got this from Dave Frankenbach a while before you proposed it; it works in most cases. Another approach is to call the API to check all the Windows virtual keys using a buffer to detect changes:
>
>AFAIK, I was the first one who came to this solution, David proposed the fastdoevents with the help of moving the mouse which unfortunately has some side-effects and does not work in all cases.
>
>>
DECLARE SHORT GetKeyboardState IN USER32 STRING @ lpKeyState
>>cKeyboardAtRest = REPL(CHR(0),256)
>>cKeyboardStateNow = cKeyboardAtRest
>>=GetKeyboardState(@cKeyboardAtRest)
>>*
>>*  In loop
>>*
>>=GetKeyboardState(@cKeyboardStateNow)
>>IF cKeyboardStateNow # cKeyboardAtRest
>>   *  Something happened
>>   DOEVENTS
>>   =GetKeyboardState(@cKeyboardAtRest)
>>ENDIF
>>
>>I suspect it has less overhead than calling CHRSAW() and MDOWN() - it traps all the virtual keys, not just keystrokes that translate to characters; you can trap pressing Alt, Shift, Ctrl as well, down and up changes.
>
>Good tip! I'll look into this and will do some benchmarking and see if this from a performance point of view is a better solution.
>

OK, to make your testing easier, the keyboard state is an array of 256 bytes - one byte per virtual key. If the high-order bit of a byte is one (128), the key is down. If the low-order bit is one (1), the key is toggled (things like CapsLock, NumLock which hold their state). The list of virtual keys in in the API text file for VBV, as well as in WINUSER.H for C++. Key States change when a thread's event handler removes Windows Messages from a queue, not as messages are added to the queue. You need to be aware that if the user is active in another process, eg Word, typing away there, the keyboard state will be changing constantly; GetKeyboardState renders the observable keyboard state, not just the queued messages for the VFP thread that's active.

There are virtual keys for each separate modifier, so left/right Alt/Shift/Ctrl are differentiated in the keyboard state array. If the user is depressing multiple keys (pressing Left Shift-D-R) all three keys will have their high-order bit set. It does not sequence them in several reported keystates - if they're down, they're reported.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform