SendKeys Method
发送一个或多个击键
到活动窗口
不幸地
Sendkeys()
有时失败,通常是由于
或
时机
,既麻烦又难以解决问题。我试过了
pause
和
timeout
WshShell.AppActivate
最后,我找到了罪犯在清理以前
doskey
历史通过
doskey /REINSTALL
命令:它将安装
多斯基
.我可以推荐更直观(侵入性更小)的方法来清除
多斯基
命令历史缓冲区:
doskey /ListSize=0
doskey /ListSize=50
奖金
:用于循环说明。
-
外面的
%%A
循环以检索
name
所有物
-
内部的
%%a
回车
wmic
行为:每个输出行以
0x0D0D0A
(
<CR><CR><LF>
)而不是普通的
0x0D0A
(
<CR><LF>
).
信用:戴夫·本汉姆
WMIC
and
FOR /F
: A fix for the trailing
<CR>
problem
工作脚本
(Windows 8.1 64位):
@if (@CodeSection == @Batch) @then
@echo OFF
setlocal EnableDelayedExpansion
REM color F0
FOR /F "tokens=2 delims==" %%A IN ('
WMIC csproduct GET Name /VALUE ^| FIND /I "Name="
') DO FOR %%a in ("%%~A") DO SET "_machine=%%~a"
Echo Reset or Continue %_machine%
Set "MenuOptions=%_machine% RESET Continue" expanded merely for debugging purposes
call :ShowMenu
REM pause
exit /B
:ShowMenu
set numOpts=0
for %%a in (%MenuOptions%) do (
set /A numOpts+=1
set "option[!numOpts!]=%%a"
)
rem Clear previous doskey history
REM this causes problems: doskey /REINSTALL
doskey /ListSize=0
doskey /ListSize=50
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~F0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~F0"
set /P "MenuSelected=Option Selected: "
echo/
goto :eof
@end
var wshShell = WScript.CreateObject("WScript.Shell"),
envVar = wshShell.Environment("Process"),
numOpts = parseInt(envVar("numOpts"));
if ( WScript.Arguments.Length ) {
// Enter menu options
for ( var i=1; i <= numOpts; i++ ) {
wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
}
} else {
// Enter a F7 to open the menu
wshShell.SendKeys("{F7}");
}