PC Review


Reply
Thread Tools Rate Thread

wait for user choice by pressing keyboard, select the default one if timeout

 
 
jjm
Guest
Posts: n/a
 
      11th Feb 2011
i'm writing a batch file to mimic a simple menu system

in my batch file i want to wait for user input for seconds, if user
doesn't press any key during this period then make the default choice.
i have googled for a while, what i know now is i could use ping to
achieve the delay function , but i don't know how to get the user
input during this period?
 
Reply With Quote
 
 
 
 
Tom Lavedas
Guest
Posts: n/a
 
      12th Feb 2011
On Feb 11, 2:44*am, jjm <twicethink...@gmail.com> wrote:
> i'm writing a batch file to mimic a simple menu system
>
> in my batch file i want to wait for user input for seconds, if user
> doesn't press any key during this period then make the default choice.
> i have googled for a while, what i know now is i could use ping to
> achieve the delay function , but i don't know how to get the user
> input during this period?


The closest I can think of is the old Choice.exe program, but it is no
longer supplied with later versions of windows. I think Win NT was
the last one that cam with it.

Or you can try my little home brew that uses a hybrid JScript/batch
approach ...

@set @x=0 /* Batch part
@echo off
setlocal
set "Input="&set delay=10000 %/ milliseconds /%
set /p Input=Enter data here: < nul
for /f "delims=" %%I in (
'cscript //nologo //e:jscript "%~f0" %delay%'
) do endlocal & set "Input=%%I"
if not defined input echo.
echo.For example: "%Input%"
goto :EOF

Jscript part */
var d=WSH.Arguments(0);var t=0;
with(new ActiveXObject("WScript.Shell")){
with(Exec('%comspec% /c(set /p _#=<con&set _#)')){
while(Status==0){
WSH.Sleep(50);t+=50;if(t>d)Terminate()};
if (!StdOut.AtEndofStream) {
WSH.Echo(StdOut.ReadLine().substr(3))}}}
_______________________
Tom Lavedas
 
Reply With Quote
 
 
 
 
127.0.0.1
Guest
Posts: n/a
 
      14th Mar 2011
On 11 фев, 10:44, jjm <twicethink...@gmail.com> wrote:
> i'm writing a batch file to mimic a simple menu system
>
> in my batch file i want to wait for user input for seconds, if user
> doesn't press any key during this period then make the default choice.
> i have googled for a while, what i know now is i could use ping to
> achieve the delay function , but i don't know how to get the user
> input during this period?


Try choice.(exe|com)
 
Reply With Quote
 
Timo Salmi
Guest
Posts: n/a
 
      19th Mar 2011
On 11.02.2011 09:44 jjm <(E-Mail Removed)> wrote:
> i'm writing a batch file to mimic a simple menu system
>
> in my batch file i want to wait for user input for seconds, if user
> doesn't press any key during this period then make the default choice.
> i have googled for a while, what i know now is i could use ping to
> achieve the delay function , but i don't know how to get the user
> input during this period?


If you can find a choice.com (or a similar program) use it with
/t[:]c,nn switch

See http://www.netikka.net/tsneti/info/tscmd014.htm

All the best, Timo

--
Prof. Timo Salmi private.php?do=newpm&u= ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/en...nel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php
 
Reply With Quote
 
Bill Stewart
Guest
Posts: n/a
 
      28th Mar 2011
On Feb 11, 1:44*am, jjm <twicethink...@gmail.com> wrote:

> i'm writing a batch file to mimic a simple menu system
>
> in my batch file i want to wait for user input for seconds, if user
> doesn't press any key during this period then make the default choice.
> i have googled for a while, what i know now is i could use ping to
> achieve the delay function , but i don't know how to get the user
> input during this period?


Hi,

You can also use editvar/editv32/editv64 or choose/choose32/choose64

editvar/choose - MS-DOS versions
editv32/choose32 - Windows console x86 versions
editv64/choose64 - Windows console x64 versions

editvar/editv32/editv64 is a utility that lets you interactively edit
environment variables. It has several features many have told me they
have found useful, such as timeout and masked input (displays '*' for
typed characters, useful for entering passwords).

choose/choose32/choose64 is an alternative to the Microsoft 'choice'
program and offers the same feature set with a couple of enhancements.

All programs are freeware, available from my web site:
http://www.westmesatech.com/editv.html

--
Bill Stewart
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IIS Timeout , Web Config Timeout, Page Timeout. =?Utf-8?B?TWlrZSBNb29yZQ==?= Microsoft Dot NET 0 17th Jan 2006 07:52 PM
Console replication of old CHOICE DOS command - how to timeout? - choice.vb (0/1) Mark A. Nadig Microsoft VB .NET 13 17th Mar 2005 04:40 PM
XP SP2 Please wait ... please wait ... please wait ... please wait ... PK Windows XP General 0 27th Aug 2004 12:02 AM
"Please wait while Microsoft Outlook Exits" - and wait, and wait, and wait... ste© Microsoft Outlook Discussion 5 4th Jul 2004 05:34 PM
Pressing Spacebar keeps muting speakers, how do i disable??? PLEASE HELP!Pressing Spacebar keeps muting speakers, how do i disable??? PLEASE HELP! =?Utf-8?B?cG9vcHkgbWNkdWZm?= Windows XP Basics 1 26th May 2004 04:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:33 PM.