无论如何我可以用批处理文件模拟按Home + D吗?
我需要它来最小化全屏的IE窗口而不会丢失全屏属性。
由于
答案 0 :(得分:1)
还有另一种方法可以使用vb脚本c:\Windows\System32\cscript.exe //H:CScript
yourscript.vbs
来完成这个技巧。脚本文件只包含两个命令
set objShell = CreateObject("shell.application")
objShell.ToggleDesktop
另外一种方法是调用AutoHotkey.exe winD.ahk
脚本文件WinD.ahk由一行组成
Send, #d
答案 1 :(得分:0)
您的意思是 + D 。 WshShell.SendKeys可以模拟按键。不幸的是,SendKeys无法发送 键。但是,您可以尝试发送 Alt + Space ,然后 N 以最小化活动窗口。您需要在 Alt + Space 和 N 之间稍微暂停,以便为标题栏图标菜单提供呈现的机会 - 否则, N 将被发送到主窗口而不是菜单。
将其另存为.bat
文件并运行以进行演示。
@if (@a==@b) @end /* JScript multiline comment
:: begin batch portion
@echo off
setlocal
for /f "tokens=2" %%I in ('tasklist /v /fi "imagename eq iexplore.exe" ^| find "Internet Explorer"') do set "PID=%%I"
if defined PID goto minimize
:: apparently IE is not running. Launch, then wait for it to appear.
start "" "%programfiles%\Internet Explorer\iexplore.exe"
:ie
ping -n 2 0.0.0.0 >NUL
for /f "tokens=2" %%I in ('tasklist /v /fi "imagename eq iexplore.exe" ^| find "Internet Explorer"') do set "PID=%%I"
if not defined PID goto ie
:minimize
cscript /nologo /e:Jscript "%~f0" "%PID%"
goto :EOF
:: end batch portion / begin JScript */
var oShell = WSH.CreateObject('wscript.shell');
WSH.Echo('Activating window with PID ' + WSH.Arguments(0));
oShell.AppActivate(WSH.Arguments(0));
WSH.Sleep(100);
WSH.Echo('Making full screen');
oShell.SendKeys('{F11}');
WSH.Sleep(1000);
WSH.Echo('Activating titlebar icon menu');
oShell.SendKeys('% ');
WSH.Sleep(100);
WSH.Echo('Minimizing');
oShell.SendKeys('n');
WSH.Sleep(100);
编辑: 为了它的价值, Alt + Esc 也会最小化大多数窗户但它并不适用于F11模式的IE。全屏IE被推到所有窗口的后面而不是被最小化。但是其他任何人都会从Google搜索中找到这个答案,请尝试发送 Alt + Esc 。这对于最小化cmd
窗口特别有用,因为 Alt + 空间不适用于那些。
编辑2:要让脚本最小化自己的窗口,然后最小化IE,然后重新启动,请尝试以下修改:
@if (@a==@b) @end /* JScript multiline comment
:: begin batch portion
@echo off
setlocal
for /f "tokens=2" %%I in ('tasklist /v /fi "imagename eq iexplore.exe" ^| find "Internet Explorer"') do set "PID=%%I"
if defined PID goto minimize
:: apparently IE is not running. Launch, then wait for it to appear.
start "" "%programfiles%\Internet Explorer\iexplore.exe"
:ie
ping -n 2 0.0.0.0 >NUL
for /f "tokens=2" %%I in ('tasklist /v /fi "imagename eq iexplore.exe" ^| find "Internet Explorer"') do set "PID=%%I"
if not defined PID goto ie
:minimize
cscript /nologo /e:Jscript "%~f0" "%PID%"
goto :EOF
:: end batch portion / begin JScript */
var oShell = WSH.CreateObject('wscript.shell');
if (WSH.Arguments.length == 1) {
WSH.Echo('Activating window with PID ' + WSH.Arguments(0));
oShell.SendKeys('%{ESC}')
oShell.AppActivate(WSH.Arguments(0));
WSH.Sleep(100);
WSH.Echo('Making full screen');
oShell.SendKeys('{F11}');
WSH.Sleep(1000);
WSH.Echo('Minimizing');
oShell.SendKeys('% ');
WSH.Sleep(100)
oShell.SendKeys('n');
oShell.Run('cscript /nologo /e:JScript ' + WSH.ScriptFullName + ' ' + WSH.Arguments(0) + ' ' + '1', 1, false);
WSH.Sleep(100);
WSH.Quit(0);
}
else {
WSH.Echo('Done. Hit ENTER to exit.');
WSH.StdIn.ReadLine();
}