【问题标题】:Send a "tab" keystroke in powershell在 powershell 中发送“tab”键击
【发布时间】:2021-12-17 10:22:40
【问题描述】:

我正在尝试发送“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')

【问题讨论】:

  • 您的大部分代码似乎来自this answer,在这种情况下您应该提供出处。但是,请注意,该代码是关于发送击键按住 Windows 键

标签: powershell sendkeys keystroke


【解决方案1】:

这对你有用吗?

$vb = New-Object -ComObject wscript.Shell

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 2016-05-24
    • 2018-09-23
    • 1970-01-01
    相关资源
    最近更新 更多