Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 当用户按下按钮时使循环停止_Batch File_Autoit - Fatal编程技术网

Batch file 当用户按下按钮时使循环停止

Batch file 当用户按下按钮时使循环停止,batch-file,autoit,Batch File,Autoit,我在寻找某种方法,当用户按下按钮时,使循环终止。我知道如果你有一个循环,你可以按控制c,但这不是我希望用户必须做的。我不认为这在批处理文件中是可能的,但我期待有人在这里证明我错了 我有另一个想法。使用autoit脚本怎么样?其中,在批处理文件的开头,启动autoit脚本。脚本使用热键功能,当按下热键时,程序关闭。在批处理文件中,经常检查autoit脚本是否正在运行。如果不是,那么你知道热键被按下了我已经对它进行了测试,它可以正常工作,但我不喜欢每次检查tasklist.exe的wkey.exe时

我在寻找某种方法,当用户按下按钮时,使循环终止。我知道如果你有一个循环,你可以按控制c,但这不是我希望用户必须做的。我不认为这在批处理文件中是可能的,但我期待有人在这里证明我错了

我有另一个想法。使用autoit脚本怎么样?其中,在批处理文件的开头,启动autoit脚本。脚本使用热键功能,当按下热键时,程序关闭。在批处理文件中,经常检查autoit脚本是否正在运行。如果不是,那么你知道热键被按下了我已经对它进行了测试,它可以正常工作,但我不喜欢每次检查tasklist.exe的wkey.exe时产生的延迟。如果我能找到一个更有效的方法来做这件事,那就太棒了

批处理文件:

@echo off
start wkey.exe
echo press the w key to stop.
timeout 3
:loop
tasklist /FI "IMAGENAME eq wkey.exe" 2>NUL | find /I /N "wkey.exe">NUL
if %ERRORLEVEL%==1 goto endloop
echo doing stuff . . .
goto loop

:endloop
echo you pressed the w key.
pause
exit
wkey.exe(使用autoit语言编程)

#非彩虹图标
#包括
热键集(“w”,“_输入”)
而1
睡眠(10)
温德
Func_输入()
出口
EndFunc

运行此操作,当您按下control(CTRL)键时,循环将停止执行-它仅在
32位机器上工作
,而且
certutil
不是XP的本机,似乎需要Vista和更高版本

@echo off
>tmp.tmp echo -----BEGIN CERTIFICATE-----
>>tmp.tmp echo uEAAjtigFwC0TM0h
>>tmp.tmp echo -----END CERTIFICATE-----

certutil -decode -f tmp.tmp kbflag.com >nul

for /L %%a in (1,1,10000) do (
echo Press the CTRL key to exit - %%a
kbflag.com
if errorlevel 4 if not errorlevel 5 goto :skip
)
:skip
del kbflag.com
del tmp.tmp
echo Finished.
pause
它使用一个名为
KBFLAG.com
的杂志
.com
文件实用程序(.com文件仅在32位机器上工作),该工具监视键盘并设置一个错误级别,您可以在该级别上进行分支

它是一个12字节的文件,顺序为
B8 40 00 8E D8 A0 17 00 B4 4C CD 21
,批处理文件创建并删除它(它被编码到证书数据中)

对于不是.com文件的
64位系统
,您可能会找到类似的工具

以下是文档文件:

KBFLAG -- by Nico Mark -- from PC Magazine, December 23, 1986 

KBFLAG can be used to cause branching in batch files, so that execution of
different parts of the file can be dependent on the state of toggle and shift
keys.  You can, for example, abort execution of AUTOEXEC.BAT if the CapsLock
key has been toggled while CONFIG.SYS in running.

KBFLAG tests for a keystroke in the buffer, and sets errorlevel to the value of
the key's KBFLAG in the ROM BIOS.  Thus, if the Ins key has been toggled, it
will return an errorlevel of 128.  Other values are:  

    1 = Right Shift 
    2 = Left Shift 
    4 = Ctrl key 
    8 = Alt key
       16 = ScrollLock 
       32 = NumLock 
       64 = CapsLock 
      128 = Ins 

(You can use sums of these values to correspond to combinations of keys, so
96 = CapsLock and NumLock together.) 

If you put these lines at the start of autoexec.bat-- 

    KBFLAG 
    IF ERRORLEVEL 64 GOTO :END 

--and put the label :END at the end of the file, autoexec.bat will then check 
to see if CapsLock has been pressed, and will jump the end of the batch if it
has.   To prevent autoexec.bat from executing on bootup, simply hit CapsLock
while  config.sys is running.     

You can use variations of this technique to cause different sets of programs
to run during autoexec.bat (or any batch file).  For example, Caps Lock could
cause only a few programs to run; Alt + CapsLock could cause others; etc.

我确信它能工作,但运行64位系统,它对我来说不起作用。
KBFLAG -- by Nico Mark -- from PC Magazine, December 23, 1986 

KBFLAG can be used to cause branching in batch files, so that execution of
different parts of the file can be dependent on the state of toggle and shift
keys.  You can, for example, abort execution of AUTOEXEC.BAT if the CapsLock
key has been toggled while CONFIG.SYS in running.

KBFLAG tests for a keystroke in the buffer, and sets errorlevel to the value of
the key's KBFLAG in the ROM BIOS.  Thus, if the Ins key has been toggled, it
will return an errorlevel of 128.  Other values are:  

    1 = Right Shift 
    2 = Left Shift 
    4 = Ctrl key 
    8 = Alt key
       16 = ScrollLock 
       32 = NumLock 
       64 = CapsLock 
      128 = Ins 

(You can use sums of these values to correspond to combinations of keys, so
96 = CapsLock and NumLock together.) 

If you put these lines at the start of autoexec.bat-- 

    KBFLAG 
    IF ERRORLEVEL 64 GOTO :END 

--and put the label :END at the end of the file, autoexec.bat will then check 
to see if CapsLock has been pressed, and will jump the end of the batch if it
has.   To prevent autoexec.bat from executing on bootup, simply hit CapsLock
while  config.sys is running.     

You can use variations of this technique to cause different sets of programs
to run during autoexec.bat (or any batch file).  For example, Caps Lock could
cause only a few programs to run; Alt + CapsLock could cause others; etc.