【问题标题】:Can you toggle between apps with powershell您可以使用 powershell 在应用程序之间切换吗
【发布时间】:2019-04-18 14:37:42
【问题描述】:

我希望在多个应用程序之间实现自动轮换,特别是在信息亭模式下打开的 Internet Explorer 窗口。这是用于高架显示器。

我已经尝试了文章 (how to perform a hold ALT+TAB sendkey event in C#) 中的建议,但它对我不起作用。我收到以下错误。

Exception calling "SendWait" with "1" argument(s): "Specified repeat count is not valid."
At line:1 char:35
+ [Windows.Forms.Sendkeys]::SendWait <<<< ("%{Alt Up}")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

通过手动测试,alt+tab 甚至 alt+tab+tab 只会在前两个/三个窗口之间切换,我目前有 6 个,将来可能会更多。看起来我可以尝试按标题拉出窗口,但这似乎不可靠。

#ADD external assemblies here
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
#Sets interval before changing screens
Start-sleep -Seconds 2
[System.Windows.Forms.SendKeys]::SendWait("%{TAB}%{tab}")
[System.Windows.Forms.SendKeys]::SendWait("%{TAB}%{tab}")

我也试过这个:

[System.Windows.Forms.SendKeys]::SendWait("%{alt down}")
[System.Windows.Forms.SendKeys]::SendWait("%{tab}")

【问题讨论】:

  • 在 SendWait 调用中使用单引号。即:SendWait('%{TAB}%{TAB}')
  • 单引号似乎没有区别。
  • 这应该会有所不同,您遇到了什么错误,正在发生什么与您想要发生什么?您发布的代码甚至与您的错误不匹配
  • 单引号或双引号之间没有任何不同,也没有错误消息。双引号似乎在我用来登录网站的其他一些输入代码上工作得很好。 Alt up 错误与我从 alt down 得到的错误相同,我只是复制了一次。 Powershell 不喜欢这些行中的向上或向下。理想情况下,我希望像使用 Alt Tab 一样在应用程序之间自动切换。

标签: powershell powershell-2.0


【解决方案1】:

我想通了。

使用 SendWait("%{TAB}")

在 powershell 中,使用 alt 键的唯一方法似乎是使用 % 符号。

【讨论】:

    【解决方案2】:

    所以我想我想通了。您不想为切换执行 ALT + TAB,因为这是基于 Z 的交换。这意味着它只在运行的第一个和第二个应用程序之间切换。但是,如果您使用 Alt+Shift+ESC,这将告诉系统拉出列表中的最后一项并将其向前移动

    【讨论】:

      猜你喜欢
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 2014-04-22
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 2020-08-23
      相关资源
      最近更新 更多