发送 Windows 输入批处理脚本

Send Windows Key in batch script

我最近一直在通过批处理脚本使用 SendKeys 函数。

我已经了解如何将某些键输入 window,例如 Tab 键:

%SendKeys% "{TAB}"

或退格键:

%SendKeys% "{BACKSPACE}"

但我一直在尝试输入 Windows 键而不按它。

不幸的是,我不知道它的批名是什么。 我试过:

WIN
WINDOWS
WINKEY
START
LWIN

但是 none 奏效了。

我到处都找过这个,非常感谢您的帮助。

目前无法在sendkey's中模拟windows主页徽标,但这并不意味着不可能。

如果您看一下 windows shortcut keys,您会发现您可以使用以下组合键模拟 打开开始Ctrl + Esc.

要批量模拟,您可以使用:powershell -c "$wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys('^{ESCAPE}') 或者在您的情况下: %SendKeys% "^{ESCAPE}".

如发送密钥中所述:

  • "^" - 模拟 Ctrl 按键。
  • "{ESCAPE}" - 模拟 Esc 按键。

你可以编写一个程序来模拟 winkey 被按下的过程。

WinKey+R.VB

Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Module SendWinKey

    Const KEYEVENTF_KEYDOWN As Integer = &H0
    Const KEYEVENTF_KEYUP As Integer = &H2

    Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)

       Public Sub Main()    
           keybd_event(CByte(Keys.LWin), 0, KEYEVENTF_KEYDOWN, 0) 'press the left Win key down
           keybd_event(CByte(Keys.R), 0, KEYEVENTF_KEYDOWN, 0) 'press the R key down
           keybd_event(CByte(Keys.R), 0, KEYEVENTF_KEYUP, 0) 'release the R key
           keybd_event(CByte(Keys.LWin), 0, KEYEVENTF_KEYUP, 0) 'release the left Win key
       End Sub
End Module

放在桌面上。

打开命令提示符并键入

C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%userprofile%\desktop\Win+R.vb" /out:"%userprofile%\Desktop\Win+R.exe" /target:winexe

名为 Win+R.exe 的文件将出现在您的桌​​面上。将它移动到路径中的任何位置。

不创建临时文件。 显示 'loop' 只是为了让您可以打开笔记本进行输出。之后删除。

    @echo off
        :loop
            ::------------begin main code------------
            set command=new ActiveXObject('WScript.Shell').SendKeys('WoW{ENTER}{ENTER}');
            for /f "delims=" %%i in ('mshta "javascript:%command%close(new ActiveXObject('Scripting.FileSystemObject'));"') do set
            ::-------------end main code-------------
            timeout /t 1 /nobreak >nul
        goto :loop

已解决 - 首先用代码

创建一个文件 .vbs
Set WshShell = WScript.CreateObject("WScript.Shell")`   
WshShell.AppActivate "notepad"
WshShell.SendKeys "^{pgdn}"

并且在您必须从 .bat 文件调用该文件之后