【发布时间】: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 一样在应用程序之间自动切换。