我想写一个Windows服务(在c#中)或一个powershell脚本,它将我的笔记本电脑自动连接(在启动或组合键)到我的MS无线显示适配器进行屏幕镜像.在Windows 10中,我只能通过转到通知手动完成,然后单击连接> MS无线适配器>连接.
我发现有一个Miracast API(https://msdn.microsoft.com/en-us/library/windows/hardware/dn265515 ( v= vs.85 ) .aspx )但没有太多关于如何使用它.
我还发现了这个http://filelog.net/file/MiraDisp.dll/2c279c8d57a47a9ca06aa279bd9e0e8e22c7c1c1,它有两个函数OpenMiracastSession和CloseMiracastSession.
问题是我不知道如何在c#中使用这些函数.我知道我可能不得不使用pInvoke.谁能指出我正确的方向?
首先,感谢@CodingGorilla对AutoHotkey的建议.过去几天我一直在玩这个游戏.
我去了AutoHotkey路线,因为我找不到一个简单的地方开始使用任何Windows 10 API.各种各样的文件推送吐司通知,但我找不到任何控制行动中心的东西. 如果有人对此有任何建议,请发布.
以下是我使用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
}
Run Code Online (Sandbox Code Playgroud)
我还附上图像作为我所做的一个例子. 您需要制作自己的搜索图像.在制作这些图像之前,还必须关闭操作中心的透明度,Windows 10中的启动和任务栏 - 设置 - >个性化 - >颜色 - >启动,任务栏和操作中心透明 - >关闭.因为我的图像在图像中列出"Roku Stick",所以重做第二张图像尤为重要.我不得不在我的桌面开发机器和MS Surface 3之间重做我的搜索图像.我正在运行这个脚本.决议等将在设备之间改变.按照如何在此处创建自己的搜索图像的说明操作:
https://autohotkey.com/docs/commands/ImageSearch.htm
最后,如果无线显示器已经连接,这可能不起作用.在我的环境中连接无线显示器会导致平板电脑上的分辨率发生变化,因此无法在屏幕上找到图像.
小智 8
首先,我想说@jaredbaszler提供了一个非常好的解决方案.它的工作就像一个魅力谢谢你:)
我也在玩AutoHotkey因为我想知道是否还有另外一种方法可以做到这一点.过了一会儿,我想出了以下脚本:
Send #k ; Sends Windows button + K to open the Action Center Connect window
Sleep, 3000 ; Wait some time so the wireless display dongle can be found
Send {Enter} ; Send ENTER key to connect to wireless display dongle (works when only 1 is found)
Send {Esc} ; Send ESC key to close the Action Center Connect window
Run Code Online (Sandbox Code Playgroud)
好.现在让我解释一下这个脚本的工作原理:
好吧,就是这样.这没什么特别但它有效.我用我的平板电脑和我的无线显示器加密狗(我在这里有这个)测试了这个脚本几次,它似乎工作得很好.不幸的是,如果您同时启动并运行多个无线显示加密狗,我的脚本将无法按预期工作,因为我的脚本将只选择显示的第一个加密狗.(这对我来说不是问题,因为我只有一个无线显示加密狗)