如何在Spotify歌曲';它最小化了吗? 如何在Spotify歌曲最小化的情况下播放它?
好的,Windows上的Spotify应用程序没有内置的全局热键支持,即使在应用程序窗口当前处于活动状态时,也不支持非常基本的热键。令人沮丧的是,“主演”当前播放的歌曲没有键盘快捷键,即使窗口处于活动状态 因此,我有一个自动热键脚本,它为我提供了全局热键,用于播放控制、音量和复制歌曲标题(包括em破折号修复),但我遇到了一个难题,试图找出如何播放当前歌曲 更糟糕的是,如果这首歌还没有上映,我只想用自动热键脚本来上映。如果它已经主演了,那就别管它了 我希望所有这些都发生在应用程序放在托盘中时,而不打开窗口如何在Spotify歌曲';它最小化了吗? 如何在Spotify歌曲最小化的情况下播放它?,spotify,autohotkey,hotkeys,minimized,Spotify,Autohotkey,Hotkeys,Minimized,好的,Windows上的Spotify应用程序没有内置的全局热键支持,即使在应用程序窗口当前处于活动状态时,也不支持非常基本的热键。令人沮丧的是,“主演”当前播放的歌曲没有键盘快捷键,即使窗口处于活动状态 因此,我有一个自动热键脚本,它为我提供了全局热键,用于播放控制、音量和复制歌曲标题(包括em破折号修复),但我遇到了一个难题,试图找出如何播放当前歌曲 更糟糕的是,如果这首歌还没有上映,我只想用自动热键脚本来上映。如果它已经主演了,那就别管它了 我希望所有这些都发生在应用程序放在托盘中时,而不
编辑:半工作解决方案 因此,我提出了一个合理的解决方案,它打开了一个上下文菜单,即使程序被最小化,并做所有事情,包括不取消播放歌曲。不幸的是,上下文菜单意味着它将在一瞬间最小化像游戏这样的全屏应用程序。取决于游戏,这可能是一个痛苦,但这是我能做的最好的没有花哨的DLL调用和东西
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;|---------------|
;|--[ SOURCES ]--|
;|---------------|
;Base Spotify Script from: http://www.autohotkey.com/board/topic/36239-spotify-global-hotkeys/
;Base Starring Script from: http://superuser.com/questions/324416/any-spotify-tweaks-with-keyboard-shortcut-to-star-tracks
;|------------------|
;|--[ SETTING UP ]--|
;|------------------|
DetectHiddenWindows, On ;Detect Spotify even if it's minimized
#IfWinExist ahk_class SpotifyMainWindow ;Only do the following if Spotify is running
spotify = ahk_class SpotifyMainWindow ;Set variable for Spotify Window Name
;|---------------|
;|--[ HOTKEYS ]--|
;|---------------|
; "CTRL + ALT + PAGEUP" for previous
^!PGUP::
{
ControlSend, ahk_parent, ^{Left}, %spotify%
return
}
; "CTRL + ALT + PAGEDOWN" for next
^!PGDN::
{
ControlSend, ahk_parent, ^{Right}, %spotify%
return
}
; "CTRL + ALT + HOME" for pause
^!Home::
{
ControlSend, ahk_parent, {Space}, %spotify%
return
}
; "CTRL + ALT + END" for track-name
^!End::
{
WinGetTitle, spotify_playing, %spotify% ;Get the title of Spotify which contains the track-name
StringTrimLeft, trimmed_playing, spotify_playing, 10 ;Get rid of extra text and place into 'trimmed_playing'
StringReplace, replaced_playing, trimmed_playing, –, -, All ;Replace en dash with normal dash and place into 'replaced_playing'
clipboard = %replaced_playing% ;Copy the fixed text to clipboard
return
}
; "CTRL + ALT + UP" for volume up
^!Up::
{
ControlSend, ahk_parent, ^{Up}, %spotify%
return
}
; "CTRL + ALT + DOWN" for volume down
^!Down::
{
ControlSend, ahk_parent, ^{Down}, %spotify%
return
}
; "CTRL + ALT + INSERT" for starring the current song
^!Insert::
{
;Store active window and mouse position.
MouseGetPos, , , winID
;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
clickX := 100
clickY := spotifyHeight-70
ControlClick, x%clickX% y%clickY% , %spotify%, , Right, , NA
;Get the contents of the context menu.
WinWait, ahk_class #32768
SendMessage, 0x1E1 ;MN_GETHMENU
allContextMenuInfo := ErrorLevel
;The "Star" command is the 2nd menu item.
;If the song is Unstarred the text is Star, and vice versa. But sometimes some wierd characters are included.
;The only reliable way I found is to check if the first letter is S.
menuText_StarUnstar := GetContextMenuItemText(allContextMenuInfo, 2)
StringGetPos, positionOfS, menuText_StarUnstar, S
;If S is the first letter, star the song.
notStarred := (%positionOfS% = 0)
If notStarred
{
;Arrow down to the Star menu item and press enter.
ControlSend, ahk_parent, {Down}{Down}{Enter}, %spotify%
}
Else
{
;Just close the context menu.
ControlSend, ahk_parent, {Escape}, %spotify%
}
;Restore original window and mouse position.
WinActivate ahk_id %winID%
return
}
;|-----------------|
;|--[ FUNCTIONS ]--|
;|-----------------|
;Context menu helper function.
GetContextMenuItemText(hMenu, nPos)
{
length := DllCall("GetMenuString"
, "UInt", hMenu
, "UInt", nPos
, "UInt", 0 ; NULL
, "Int", 0 ; Get length
, "UInt", 0x0400) ; MF_BYPOSITION
VarSetCapacity(lpString, length + 1)
length := DllCall("GetMenuString"
, "UInt", hMenu
, "UInt", nPos
, "Str", lpString
, "Int", length + 1
, "UInt", 0x0400)
return lpString
}
我修改了一些隐藏在互联网上的现有脚本。源代码可以在源代码的顶部找到,如果有人想在上下文菜单不出现的情况下尝试让它完全工作,可能会有所帮助
在正常使用应用程序时,如何播放歌曲? 在Spotify中播放一首歌似乎只有两条途径
Star -> WM_MENUSELECT (0x11F) | item identifier = 11 | flags = NONE | MF_HILITE
Unstar -> WM_MENUSELECT (0x11F) | item identifier = 12 | flags = NONE | MF_HILITE
但是,我不知道如何将PostMessages/SendMessages链接在一起,打开菜单,然后只选择第11项,然后按enter键
Spotify在主演某个节目时收到的消息列表
以防万一,这有助于确定是否可以执行PostMessage/SendMessage路由
->WM_RBUTTONDOWN (0x204)
->WM_RBUTTONUP (0x205)
->WM_MENUSELECT (0x11F)
<-WM_MENUSELECT (0x11F)
->WM_KEYDOWN (0x100)
->WM_MENUSELECT (0x11F)
<-WM_MENUSELECT (0x11F)
->WM_KEYUP (0x101)
我目前在玩游戏时使用的方法非常简单:
MouseGetPos, x, y, origwin
WinActivate, ahk_class SpotifyMainWindow
click 183, 1000 ;
WinActivate, ahk_id %origwin%
MouseMove, %x%, %y%
一个整洁的代码替代品;Spotify对媒体按钮做出响应,因此这些按钮可以发挥作用:
^!Left::Media_Prev
^!Right::Media_Next
^!Up::Volume_Up
^!Down::Volume_Down
^!Space::Media_Play_Pause
编辑:Spotify更改了它们的布局。+随着歌曲标题的长度移动。为了使其工作更加一致,我将功能更改为右键单击和“保存到您的音乐”
FavouriteSpotifySong()
{
WinGetPos, , , SPOTIFY_X_AXIS, SPOTIFY_Y_AXIS, ahk_class SpotifyMainWindow
yPos := SPOTIFY_Y_AXIS - 30
ControlClick, X25 Y%yPos%, ahk_class SpotifyMainWindow,, RIGHT
Sleep 75
yPos -= 54
ControlClick, X33 Y%yPos%, ahk_class SpotifyMainWindow
}
从一个完全不同的方向思考:你有没有想过使用一个现有的API(例如)来启动你的轨迹?我不知道这样做是否容易,但也许有一种方法可以用AHK获取当前曲目的信息,然后用API识别并启动它。通常,您可以尝试在播放曲目时观看spotify生成的请求(例如,使用URL Snooper、WireShark),然后自己制作。如果您不需要知道歌曲是否已经播放,请使用
controlclick x。。y、 .
也可以通过最小化Spotify来完成。现实地思考:当你想手动完成这项工作时,你必须看看这首歌是否已经主演。所以你已经在自动化那里的一切了。如果你不能没有这一点,考虑把这些歌曲添加到一个新的定制播放列表,并在关闭Spotify之前将它们全部添加到您的歌曲中。
FavouriteSpotifySong()
{
WinGetPos, , , SPOTIFY_X_AXIS, SPOTIFY_Y_AXIS, ahk_class SpotifyMainWindow
yPos := SPOTIFY_Y_AXIS - 30
ControlClick, X25 Y%yPos%, ahk_class SpotifyMainWindow,, RIGHT
Sleep 75
yPos -= 54
ControlClick, X33 Y%yPos%, ahk_class SpotifyMainWindow
}