set/p with time?
Moderator: DosItHelp
set/p with time?
hi all
i am creating a game and i was wondring
is it possible to use a timer with set/p
so if the timer equal to 0
and no input has been giving we go to a label or something?
i think its inpossible because of batch interpreter runs the line one by one!
but just wanted to ask!
i am creating a game and i was wondring
is it possible to use a timer with set/p
so if the timer equal to 0
and no input has been giving we go to a label or something?
i think its inpossible because of batch interpreter runs the line one by one!
but just wanted to ask!
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: set/p with time?
If you're using Vista/7/8 and don't need XP support, CHOICE has a timer option you can set.
Re: set/p with time?
can you post a code exmaple plz?
the problem is choice command has some problems for me!
each time i run a program using this command i have to press shift + alt
if i dont do this is only give me beep sound!
(keybord language is english but i dont know why i have to press the shift+alt)
so is better if that can be done with set/p command
the problem is choice command has some problems for me!
each time i run a program using this command i have to press shift + alt
if i dont do this is only give me beep sound!
(keybord language is english but i dont know why i have to press the shift+alt)
so is better if that can be done with set/p command
Re: set/p with time?
Are you aware that you will get a beep sound every time an incorrect response is input?
Re: set/p with time?
Or did you want something like this.
Code: Select all
H:\>timeout /T 10
Waiting for 10 seconds, press a key to continue ...
Re: set/p with time?
@compo
yes i know
look for exmaple we have a choice command with wasd and i run the script now even when my language is english when i press w or s or d or a i get a beep sound but when i press shift+alt and then press one of the wasd there is no problem and its work correctly!
@squashman
look i want to get a input form user but with time!
so if user for exmaple did not enter anything as a input!
and the timer was equal to zero
then for exmaple script goes to label1
yes i know
look for exmaple we have a choice command with wasd and i run the script now even when my language is english when i press w or s or d or a i get a beep sound but when i press shift+alt and then press one of the wasd there is no problem and its work correctly!
@squashman
look i want to get a input form user but with time!
so if user for exmaple did not enter anything as a input!
and the timer was equal to zero
then for exmaple script goes to label1
Re: set/p with time?
Then you need to use the CHOICE command.
Probably something with your code page.
Type CHCP at the command prompt and let us know what it is.
Probably something with your code page.
Type CHCP at the command prompt and let us know what it is.
Re: set/p with time?
720
what is chcp?
sory my intenet speed is very low these days(more like dial up!) i cant serach!
what is chcp?
sory my intenet speed is very low these days(more like dial up!) i cant serach!
Re: set/p with time?
You can't do that with native Batch commands. You need a third party program that allows you the get a keystroke and process it at same time that a clock is keep running. I posted such routine some time ago; this is a copy of that post:
Previous subroutine requires Show.exe and GetKey.exe auxiliary programs; you may download they from this site, besides a description of previous subroutine.
Antonio
Aacini wrote:... the subroutine below perform a timed read line, that is, it limits the time allowed to complete the input to a given number of seconds; if that time is exceeded, "Input timeout" is assigned to the input variable:Code: Select all
@echo off
set Bell=7
set BackSpace=8
set Enter=13
set Space=32
:ReadLineTime var= seconds ["prompt"]
set %1=
set seconds=%2
Show %3 seconds ": "
set lastTime=%time:~0,-3%
:nextKey
GetKey /N
set key=%errorlevel%
if %key% equ 0 (
if %lastTime% equ %time:~0,-3% (
goto nextKey
) else (
set lastTime=%time:~0,-3%
set /A seconds-=1
if !seconds! gtr 0 (
Show 13 %3 seconds ": " %1 " " %BackSpace%
goto nextKey
) else (
StrLen %1
Show 13 %3 "0: " %Space%*!errorlevel! 13 10
set %1=Input timeout
exit /B 1
)
)
)
if %key% geq %Space% (
rem Ascii Character
Show %key%
for /F "delims=" %%a in ('Show %key%') do set "%1=!%1!%%a"
) else if %key% equ %BackSpace% (
if defined %1 (
Show %BackSpace% %Space% %BackSpace%
set "%1=!%1:~0,-1!"
) else (
Show %Bell%
)
) else if %key% equ %Enter% echo/& exit /B
goto nextKey
Previous subroutine requires Show.exe and GetKey.exe auxiliary programs; you may download they from this site, besides a description of previous subroutine.
Antonio
Re: set/p with time?
Aacini wrote:You can't do that with native Batch commands.
I don't see why not. He is just asking to input W,A,S,D. If on of those keys isn't pressed within a certain amount of time it defaults to one of the keys. Then you check the error level to branch to what you want to do. I think that is all they are asking for. The choice command does this just fine.
Re: set/p with time?
thanks!
i will try that aacini
@squashman
yes i want to do that! if i can redirect if no input givven even better but that will do it too!
i changed the chcp to 431(united states) still same problem i need to press shift + alt
its no problem for me pressing it but because i want to give it to other pepole....
i will try that aacini
@squashman
yes i want to do that! if i can redirect if no input givven even better but that will do it too!
i changed the chcp to 431(united states) still same problem i need to press shift + alt
its no problem for me pressing it but because i want to give it to other pepole....
Re: set/p with time?
Squashman wrote:Aacini wrote:You can't do that with native Batch commands.
I don't see why not. He is just asking to input W,A,S,D. If on of those keys isn't pressed within a certain amount of time it defaults to one of the keys. Then you check the error level to branch to what you want to do. I think that is all they are asking for. The choice command does this just fine.
The title of this topic is "set/p with time?" In the first post, the OP said: "is it possible to use a timer with set/p" and later, he adds: "the problem is choice command has some problems for" him, "for exmaple we have a choice command with wasd..." and he must press shift+alt, "so is better if that can be done with set/p command".
Perhaps I misunderstood something?
Antonio
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: set/p with time?
Alt+Shift changes the keyboard language. It sounds like the command prompt doesn't like whatever characters it thinks it's reading in.
-
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: set/p with time?
Also, change your code page to 437 and see what happens.