我正在构建一个脚本,如果锁定工作站时正在播放音乐,它将暂停我的音乐。我使用Spotify,通过查看窗口标题可以很容易地获得播放状态。当不播放任何内容时,其标题只是“ Spotify”,而在播放媒体时,窗口标题将更改为当前播放的曲目的标题。我可以使用Window Spy看到它。
我试图找到Spotify窗口并读取其标题,使用WinGetTitle, title, ahk_exe Spotify.exe
它应该将标题写入var title
。这不起作用,title
是一个空字符串。有趣的是,如果将Spotify窗口最小化,它将起作用。
#L::
{
WinGetTitle, title, ahk_exe Spotify.exe
if(title != "Spotify")
{
Send {Media_Play_Pause}
}
DllCall("LockWorkStation")
return
}
这是在Windows 10上WinGetClass, c, ahk_exe Spotify.exe
正确找到的窗口,但是类名是Chrome_WidgetWin0
因为我猜该应用程序是用Electron编写的。其他电子应用似乎具有相同的类名,只是在末尾增加数字。
我最喜欢的是一种挂接到Windows Spotify用于报告其当前播放状态的Windows API上的方法,因为Windows 10将其识别为媒体应用程序,并在任务栏和Windows的选项卡中添加了播放/暂停按钮。音量控制叠加。
谢谢
属于进程“ Spotify.exe”的类“ Chrome_WidgetWin0”可能有多个窗口。
尝试这个:
#IfWinExist ahk_exe Spotify.exe
#l::
WinGet, id, list, ahk_exe Spotify.exe
Loop, %id%
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
If (title != "Spotify")
{
Send {Media_Play_Pause}
break
}
}
DllCall("LockWorkStation")
return
#IfWinExist
编辑:要找出它是否真的有效,请运行以下测试:
#IfWinExist ahk_exe Spotify.exe
#q:: ; Win+Q
WinGet, id, list, ahk_exe Spotify.exe
Loop, %id%
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
; MsgBox, "%title%"
If (title = "")
continue
MsgBox, "%title%"
If (title != "Spotify")
{
Send {Media_Play_Pause}
break
}
}
return
#IfWinExist
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句