在 powershell 中发送 "tab" 击键

Send a "tab" keystroke in powershell

我正在尝试发送“TAB”按键,等待 2 秒,然后发送“ENTER”按键,但它不起作用。

这是我试过的。

Add-Type -ReferencedAssemblies System.Windows.Forms -UsingNamespace System.Windows.Forms -Namespace demo -Name SendKeyExt  -MemberDefinition  @'
  [DllImport("user32.dll")]
  private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

  private const int KEYEVENTF_EXTENDEDKEY = 1;
  private const int KEYEVENTF_KEYUP = 2;

  public static void SendKeysWithWinKey(string keys = null) {
    keybd_event((byte) Keys.LWin, 0, KEYEVENTF_EXTENDEDKEY, 0);
    if (!String.IsNullOrEmpty(keys)) { SendKeys.SendWait(keys.ToLowerInvariant()); }
    keybd_event((byte) Keys.LWin, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
  }
'@

[demo.SendKeyExt]::SendKeysWithWinKey('{TAB}')

sleep -Seconds 2

[demo.SendKeyExt]::SendKeysWithWinKey('ENTER')

这对你有用吗?

$vb = New-Object -ComObject wscript.Shell

$vb.SendKeys('{TAB}')
Start-Sleep -Seconds 2
$vb.SendKeys('~')