Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8880 > unrolled thread

WSH JScript single-character input ?

Started byDr J R Stockton <reply1148@merlyn.demon.co.uk>
First post2011-12-04 22:18 +0000
Last post2011-12-05 12:33 -0800
Articles 5 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  WSH JScript single-character input ? Dr J R Stockton <reply1148@merlyn.demon.co.uk> - 2011-12-04 22:18 +0000
    Re: WSH JScript single-character input ? "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-05 08:26 +0000
      Re: WSH JScript single-character input ? Dr J R Stockton <J.R.Stockton@physics.org> - 2011-12-05 07:38 -0800
        Re: WSH JScript single-character input ? "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-05 18:05 +0000
          Re: WSH JScript single-character input ? Tom Lavedas <tglbatch@verizon.net> - 2011-12-05 12:33 -0800

#8880 — WSH JScript single-character input ?

FromDr J R Stockton <reply1148@merlyn.demon.co.uk>
Date2011-12-04 22:18 +0000
SubjectWSH JScript single-character input ?
Message-ID<uoakTIUJH$2OFwlT@invalid.uk.co.demon.merlyn.invalid>

Can command-line JScript, running in Windows script Host, read a
*single* character from the keyboard without needing Enter?  My old
16-bit Pascal directory program HUNT accepts single-character responses
for Yes/No/Quit, and it would be nice to have my 32-bit WSH version of
it do the same.

If anyone wants to look, the WSH is SEAKFYLE.JS ("documentation" is
SEAKFYLE.HTM), which is called by SEEK.BAT, all linked from
<http://www.merlyn.demon.co.uk/programs/32-bit/00index.htm>.

-- 
 (c) John Stockton, nr London UK  ?@merlyn.demon.co.uk  IE8 FF8 Op11 Sf5 Cr15
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

[toc] | [next] | [standalone]


#8887

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2011-12-05 08:26 +0000
Message-ID<Xns9FB25FFDC43A0eejj99@194.109.133.133>
In reply to#8880
Dr J R Stockton wrote on 04 dec 2011 in microsoft.public.scripting.jscript:

> Can command-line JScript, running in Windows script Host, read a
> *single* character from the keyboard without needing Enter?  My old
> 16-bit Pascal directory program HUNT accepts single-character responses
> for Yes/No/Quit, and it would be nice to have my 32-bit WSH version of
> it do the same.

StIn without pipe will read from the keyboard.

========== test.js ===========
var input = '';
while (!WScript.StdIn.AtEndOfLine) {
   input += WScript.StdIn.Read(1) + '-';
}
WScript.Echo(input);
==============================

run with cscript [wscript has no StIn] in the cmd-console:

cscript test.js



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#8890

FromDr J R Stockton <J.R.Stockton@physics.org>
Date2011-12-05 07:38 -0800
Message-ID<77d70311-87b1-48ba-b8ce-4d9c69b4f5ad@gl2g2000vbb.googlegroups.com>
In reply to#8887
On Dec 5, 8:26 am, "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:
> Dr J R Stockton wrote on 04 dec 2011 in microsoft.public.scripting.jscript:
>
> > Can command-line JScript, running in Windows script Host, read a
> > *single* character from the keyboard without needing Enter?  My old
> > 16-bit Pascal directory program HUNT accepts single-character responses
> > for Yes/No/Quit, and it would be nice to have my 32-bit WSH version of
> > it do the same.
>
> StIn without pipe will read from the keyboard.
>
> ========== test.js ===========
> var input = '';
> while (!WScript.StdIn.AtEndOfLine) {
>    input += WScript.StdIn.Read(1) + '-';}
>
> WScript.Echo(input);
> ==============================
>
> run with cscript [wscript has no StIn] in the cmd-console:
>
> cscript test.js


Requires Enter.

--
  (c) John Stockton, near London, UK.  Using Google, no spell-check.
 Mail: J.R.""""""""@physics.org or (better) via Home Page at
 Web:  <http://www.merlyn.demon.co.uk/>
 FAQish topics, acronyms, links, etc.; Date, Pascal, JavaScript, ....|

[toc] | [prev] | [next] | [standalone]


#8911

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2011-12-05 18:05 +0000
Message-ID<Xns9FB2C2236F6CEeejj99@194.109.133.133>
In reply to#8890
Dr J R Stockton wrote on 05 dec 2011 in comp.lang.javascript:

> On Dec 5, 8:26ÿam, "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:
>> Dr J R Stockton wrote on 04 dec 2011 in
>> microsoft.public.scripting.jscrip 
> t:
>>
>> > Can command-line JScript, running in Windows script Host, read a
>> > *single* character from the keyboard without needing Enter? ÿMy old
>> > 16-bit Pascal directory program HUNT accepts single-character
>> > responses for Yes/No/Quit, and it would be nice to have my 32-bit
>> > WSH version of it do the same.
>>
>> StIn without pipe will read from the keyboard.
>>
>> ========== test.js ==========
>> var input = '';
>> while (!WScript.StdIn.AtEndOfLine) {
>> ÿ ÿinput += WScript.StdIn.Read(1) + '-';}
>>
>> WScript.Echo(input);
>> ========================
> =====>
>> run with cscript [wscript has no StIn] in the cmd-console:
>>
>> cscript test.js
> 
> 
> Requires Enter.
> 

Then I guess it cannot be done, as shown by scriptingguy in 2004:

<http://blogs.technet.com/b/heyscriptingguy/archive/2004/10/05/how-can-i-
pause-a-script-and-then-resume-it-when-a-user-presses-a-key-on-the-
keyboard.aspx>



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#8913

FromTom Lavedas <tglbatch@verizon.net>
Date2011-12-05 12:33 -0800
Message-ID<80b07aa3-b04a-4649-8beb-b67f6ad88a52@k23g2000yqa.googlegroups.com>
In reply to#8911
On Dec 5, 1:05 pm, "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:
> Dr J R Stockton wrote on 05 dec 2011 in comp.lang.javascript:
>
>
>
>
>
> > On Dec 5, 8:26 am, "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:
> >> Dr J R Stockton wrote on 04 dec 2011 in
> >> microsoft.public.scripting.jscrip
> > t:
>
> >> > Can command-line JScript, running in Windows script Host, read a
> >> > *single* character from the keyboard without needing Enter? My old
> >> > 16-bit Pascal directory program HUNT accepts single-character
> >> > responses for Yes/No/Quit, and it would be nice to have my 32-bit
> >> > WSH version of it do the same.
>
> >> StIn without pipe will read from the keyboard.
>
> >> ========== test.js ==========
> >> var input = '';
> >> while (!WScript.StdIn.AtEndOfLine) {
> >> input += WScript.StdIn.Read(1) + '-';}
>
> >> WScript.Echo(input);
> >> ========================
> > =====>
> >> run with cscript [wscript has no StIn] in the cmd-console:
>
> >> cscript test.js
>
> > Requires Enter.
>
> Then I guess it cannot be done, as shown by scriptingguy in 2004:
>
> <http://blogs.technet.com/b/heyscriptingguy/archive/2004/10/05/how-can-i-
> pause-a-script-and-then-resume-it-when-a-user-presses-a-key-on-the-
> keyboard.aspx>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)- Hide quoted text -
>
> - Show quoted text -

I wrote a JScript routine a little while back that used Sendkeys to
implement a one-letter routine that didn't need an enter key and
supported a timeout.  Unfortunately, Win7 disables Sendkeys in a
command window, so it's now broken.  On the other hand, Win7 added
Choice.exe back to the utility list.  It supports single keystroke
entry.

I also wrote this little batch kludge that receives single key strokes
Y/N and control-C for cancel ...

:: YN.cmd - Yes/No/Cancelled test
 @echo off
  setlocal>%temp%.\1
  SET /P =Your answer (Y/N)?<nul
  for /f "tokens=2 delims=?" %%a in (
    'xcopy %temp%.\1 %temp%.\1 /p /y ^< con 2^>NUL ^|find "?"'
  ) do set "Answer=%%a"
  del %temp%.\1
  ECHO.%Answer% % optional %
  if "%Answer%"==" " ECHO Cancelled % optional % & exit /b 255
  echo %Answer%| find /i "y" >NUL
  if errorlevel 1 ECHO No % optional % & exit /b 1
  echo Yes % optional %

It is not case sensitive.  It returns three Errorlevels: Y = 0, N = 1,
Cancel = 255.
______________________________
Tom Lavedas

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web