The bat. Adding a timer with set / p

I am creating a .bat game, and currently when I enter the command code

set /p command=

What I want to know is that you can somehow limit the time you enter commands. For example, if you fight with a guard, and you did not write a command in 5 seconds, the attack guards.

This is not something sharp, I'm just interested to know about the limitations that I'm connected with, and I think I know an analogue anyway (an answer you can't)

thank

+5
source share
4 answers

This can also be done with batch download only.

( ) start /b.
set /p , .
5 , , , .

@echo off
setlocal EnableDelayedExpansion
if "%1" NEQ "" goto %1

del enter.tmp 2>nul >nul
start /b cmd /c %0 :secondThread

:FirstThread
set n=0
echo Enter Text (5 seconds timeout):

:loop
set /a n+=1
ping -n 2 localhost > nul
if !n! LSS 5 (
    if not exist entER.tmp goto :loop
    < Enter.tmp (
        set /p input=
    )
    echo !input!
) ELSE (
    echo Timeout for input
)

exit /b

:secondThread
set /p var=
> enter.tmp echo !var!
exit /b
+3

- , #. .net Windows , .

3- , . , , %result% .

/* 2>NUL
@echo off 
REM cls
set WinDirNet=%WinDir%\Microsoft.NET\Framework
IF EXIST "%WinDirNet%\v2.0.50727\csc.exe" set csc="%WinDirNet%\v2.0.50727\csc.exe"
IF EXIST "%WinDirNet%\v3.5\csc.exe" set csc="%WinDirNet%\v3.5\csc.exe"
IF EXIST "%WinDirNet%\v4.0.30319\csc.exe" set csc="%WinDirNet%\v4.0.30319\csc.exe"
%csc% /nologo /out:"%~0.exe" %0



echo enter some text:

set result=
for /F "tokens=*" %%a in ('"%~0.exe"') do set result=%%a

echo you have entered:%result%




del "%~0.exe"
goto :eof
*/
using System;
using System.Text;
using System.IO;
using System.Threading;

class Program
{
    static void Main (string[] args)
    {
        byte[] buffer=new byte[80];

        using (Stream s = Console.OpenStandardInput ()) {
            ManualResetEvent e=new ManualResetEvent(false);
            s.BeginRead (buffer, 0, buffer.Length, x => e.Set(), null);

            e.WaitOne (3000);
        }

        Console.WriteLine (Encoding.UTF8.GetString (buffer));
    }
}

, # , . , .

. - Console.ReadLine()? #.

( #)

+3

, , :

@ECHO OFF
(
ECHO A100
ECHO MOV AH,B
ECHO INT 21
ECHO MOV AH,4C
ECHO INT 21
ECHO/
ECHO RCX
ECHO 8
ECHO W
ECHO Q
) | DEBUG CHKKEY.COM

CHKKEY.COM 8 , , , ERRORLEVEL 255, , , . :

:waitforkey
echo Waiting for a key to be pressed...
chkkey
if not errorlevel 1 goto waitforkey
echo A key was pressed!

DEBUG.COM, . , 5 :

for /F "tokens=3 delims=:." %%a in ("%time%") do set /A second=%%c+5
if %second% geq 60 set /A second-=60
:waitforkey
for /F "tokens=3 delims=:." %%a in ("%time%") do if %%c == %second% goto timeexceeded
chkkey
if not errorlevel 1 goto waitforkey
set /P command=

B 1 MOV AH, B, ASCII ERRORLEVEL; . 8, ; , : ( ), . , F1 0 59.

+1
source

If the commands have a unique initial letter, perhaps you can use the CHOICE ? (Available again on Windows 7)

+1
source

All Articles