首先,感谢@CodingGorilla 对 AutoHotkey 的建议。过去几天我一直在玩这个。
我选择了 AutoHotkey 路线,因为我找不到从任何 Windows 10 API 开始的简单位置。那里有各种文档来推送 toast 通知,但我找不到任何东西来控制行动中心。 如果有人在这方面有建议,请发表。
这是我使用 AutoHotkey 想到的。非常简单但不是理想的解决方案,因为这有一些变量。下面是我用来打开操作中心的 AutoHotkey 脚本代码,单击连接,然后单击最上面列出的无线显示:
Send #a ;Sends Windows button + A to open the action center
Sleep, 750 ; Give it some time to slide open
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Connect.png ;Try to find the Connect button tile
if ErrorLevel = 2
MsgBox Could not conduct the search for the connect button in action center. Make sure your search image is in the correct location.
else if ErrorLevel = 1
MsgBox Connect button cannot be found on the screen.
else
MoveMouseAndClick(FoundX, FoundY)
Sleep, 1250 ;Delay so the wireless displays have a chance to load into the Action Center window
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\WirelessDisplay.png
if ErrorLevel = 2
MsgBox Could not conduct the search for the wireless display.
else if ErrorLevel = 1
{
;Search image cannot be found. Try 1 more time in case it took a long time for the wireless displays to appear
Sleep, 750
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\WirelessDisplay.png ;try to find the first Wireless Display device listed
if ErrorLevel = 1
MsgBox Wireless display image cannot be found on the screen. Make sure the wireless device is turned on.
else
MoveMouseAndClick(FoundX, FoundY)
}
else
MoveMouseAndClick(FoundX, FoundY)
Send {Esc} ;Send Esc to get rid of the Action Center window
Return
MoveMouseAndClick(x, y) {
MouseMove, x + 25, y + 25 ;Move it down the right a bit to make sure we click the button
Sleep, 250
MouseClick, left
}
我还附上了图像作为我所做的示例。 您需要制作自己的搜索图像。在制作这些图像之前,您还必须在 Windows 10 中关闭操作中心、开始和任务栏的透明度-设置->个性化->颜色->使开始、任务栏和操作中心透明->关闭。重做第二张图像尤其重要,因为我的图像在图像中列出了“Roku Stick”。我不得不在我的桌面开发机器和我正在运行这个脚本的 MS Surface 3 之间重做我的搜索图像。分辨率等将在设备之间改变。按照此处有关如何创建自己的搜索图像的说明进行操作:
https://autohotkey.com/docs/commands/ImageSearch.htm
最后,如果无线显示器已经连接,这可能不起作用。在我的环境中,连接无线显示器会导致平板电脑的分辨率发生变化,因此无法在屏幕上找到图像。