Hi,
what I'd like to achieve is to allow somebody to write a something but give him only 5 seconds to do the writing - so after 5 seconds he cannot write anymore and what he wrote so far is passed to the program.
Thank You.
get user's input but only for 5 seconds
-
- Posts: 267
- Joined: Fri Feb 24, 2012 9:34 am
Re: get user's input but only for 5 seconds
use this
starttimer(1)
repeat
t=gettimer(1)
if t<5000 ;the 5 seconds for write
blahbla......
else
blahblah
endif
if t>20000 then starttimer(1); restart the timer again when the timer reach 20 seconds
forever
starttimer(1)
repeat
t=gettimer(1)
if t<5000 ;the 5 seconds for write
blahbla......
else
blahblah
endif
if t>20000 then starttimer(1); restart the timer again when the timer reach 20 seconds
forever
Re: get user's input but only for 5 seconds
Thanks for your help.
I tried to use that code but have no luck. What I did first was:
but it is not good since INKEYSTR will block the program till ENTER is hit thus there is no time limit in theory.
Then:
which is better but still no perfect - in that version program will not break the REPEAT-FOREVER loop unless I hit a key after 5 seconds. But it is better than first one since the first keystroke after 5 seconds will quit the writing.
I tried to use that code but have no luck. What I did first was:
Code: Select all
str$=""
StartTimer(1)
Repeat
t=GetTimer(1)
If t<5000 ;the 5 seconds for write
str$ = InKeyStr(#ALPHABETICAL)
Else
Break
EndIf
Forever
DebugPrint(str$)
Then:
Code: Select all
str$=""
Function p_HandlerFunc(msg)
str$=str$..msg.key
Cls
TextOut(0,0,str$)
EndFunction
InstallEventHandler({onKeyDown = p_HandlerFunc})
StartTimer(1)
Repeat
t=GetTimer(1)
If t<5000 ;the 5 seconds for write
WaitEvent
Else
Break
EndIf
Forever
DebugPrint(str$)
-
- Posts: 267
- Joined: Fri Feb 24, 2012 9:34 am
Re: get user's input but only for 5 seconds
i dont understand very well your purpose, but i think that is better use CheckEvent() in this case
Re: get user's input but only for 5 seconds
So the whole story looks like this:
you are in the dungeon, if you decide to attack somebody (or somebody attack you) the fight starts.
To win the fight, all you have to do is to write a correct translation of the word which shows on the screen after fight starts - for example you see english word "simultaneously" and you have to write polish "jednoczesnie" - but to make it more difficult there is a time limit for writing (5 seconds) so after that period program closes the "writing window", compares what you wrote to the correct translation and decides if you won or not.
you are in the dungeon, if you decide to attack somebody (or somebody attack you) the fight starts.
To win the fight, all you have to do is to write a correct translation of the word which shows on the screen after fight starts - for example you see english word "simultaneously" and you have to write polish "jednoczesnie" - but to make it more difficult there is a time limit for writing (5 seconds) so after that period program closes the "writing window", compares what you wrote to the correct translation and decides if you won or not.
-
- Posts: 267
- Joined: Fri Feb 24, 2012 9:34 am
Re: get user's input but only for 5 seconds
i think that CheckEvent() will be better than WaitEvent() for do this, you can control the time exactly with checkevent
Re: get user's input but only for 5 seconds
You are right! CHECKEVENT works perfectly.
Thank You !
Thank You !