Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help! How to implement this?
Message
De
31/12/1999 06:34:27
 
 
À
31/12/1999 01:03:16
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00310827
Message ID:
00310855
Vues:
22
>Hi,
>I have a form that I am using as splash screen. When it comes up, it stays for 2 secs and goes away. If user presses SPACEBAR key down then it should stay even after 2secs until user finally leaves SPACEBAR key up.
>
>In Foxpro I don't see any events for key down and key up. Only event that is available is Keypress for keyboard events.
>
>I am able to implement the 2secs delay, but don't know how to implement the other part.
>
>One implementation of spacebar functionality didn't work. This is what I tried.
>In my 2sec event handler of a timer, I am calling InKey() and checking whether user currently pressed SPACEBAR. If yes, then don't hide the splash else hide it. But Inkey() is always returning 0(i.e. no key was down instead of 32) even though I pressed SPACEBAR key down.
>

I've never done this, but I'd probably take the approach of if the space character was pressed, I'd start a timer with an interval of ~ 1/20th of a second, and use the Win32 API GetKeyState call to check if the space is depressed for an appropriate period of time. I don't have code to give you, but the GetKeyState API call is in the MSDN documentation.

The API call is declared as:

DECLARE SHORT GetKeyState IN User32.DLL INTEGER nVirtualKey

The virtual key code for the spacebar is 32. A returned value < 0 indicates the key is down. Something like:

DEFINE CLASS KeyTimer AS Timer

PROTECTED lKeyIsDown, nKeyToMonitor, nTimeToWait
lKeyIsDown = .F.
nKeyToMonitor = NULL
nTicksToWait = 100 && time to wait in ticks
nTicksElapsed = 0
Enabled = .F.

PROCEDURE INIT
LPARAMETER tnKeyCodeToWatch, tnTicksToWatch
IF VARTYPE(tnTicksToWatch) = 'N'
this.nTicksToWait = tnTicksToWatch
ENDIF
IF VARTYPE(tnKeyCodeToWatch) # 'N' OR ! BETWEEN(tnKeyCodeToWatch,1,255)
RETURN .F.
ELSE
this.nKeyToMonitor = INT(tnKeyCodeToWatch)
ENDIF
this.Interval = 50
this.Enabled = .T.
RETURN
ENDPROC

PROCEDURE Timer
DECLARE SHORT GetKeyState IN User32.DLL INTEGER nVirtualKey
LOCAL nStatus
nStatus = GetKeyState(32)
DO CASE
CASE ! this.lKeyIsDown AND nStatus >= 0
this.nTicksElapsed = this.nTicksElapsed + 1
IF this.nTicksToWait = this.nTicksElapsed
thisform.Release
ENDIF
CASE ! this.lKeyIsDown
this.lKeyIsDOwn = .T.
CASE nStatus >= 0
thisform.Release
ENDCASE
RETURN
ENDPROC
ENDDEFINE
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