Answers:
当然,请使用AutoHotkey!
安装后,将其放入AutoHotkey.ahk文件:
#*::
WinWait, Spotify,
IfWinNotActive, Spotify, , WinActivate, Spotify,
WinWaitActive, Spotify,
MouseClick, left, 79, 90
Sleep, 100
MouseClick, left, 256, 152
Sleep, 100
return
这将添加一个Win + Asterisk热键,它将为正在播放的曲目加注星标。
您可能也对AutoHotkey的其他Spotify快捷方式感兴趣。
我尝试了另一个Autohotkey快捷方式,但该快捷方式对我不起作用(只是切换为Spotify并单击了两个盲点)。我设计了以下内容,只要您选择了“现在播放大作品”,它就会起作用:
CoordMode, Mouse, Relative
;star currently playing
+^l::
SpotifyWinHeight = 1050 ;set to 1080 - 30 for small taskbar size, just in case WinGetPos doesn't work for some reason
WinGetActiveTitle, CurWindow
WinActivate Spotify
WinWaitActive Spotify
WinGetPos, , , , SpotifyWinHeight, Spotify
; X Y W H, we don't care about anything but height
RightClickTarget := SpotifyWinHeight - 250
ContextMenuTarget := RightClickTarget + 110
MouseMove, 100, %RightClickTarget%
Click Right
Sleep, 50
MouseMove, 180, %ContextMenuTarget%
Sleep, 50
Click
WinActivate %CurWindow%
return
它执行以下操作:
它不是完美的(如果由于某种原因,您发现发现大部分屏幕悬挂在右侧,可能会不满意),但是在大多数情况下都能完成工作。
下面的旧答案...
这是另一个AutoHotkey解决方案。有自由派的评论。此外,如果需要,AutoHotkey文档和论坛也是学习的好地方。
按Control + Shift + *将为活动歌曲加注星标。
该脚本的主要功能是检查歌曲是否已加星标,如果已加星标则将其保留。
^+*::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
WinGetActiveTitle, activeWindow
MouseGetPos x, y, winID
;Activate Spotify.
WinActivate %spotify%
WinWaitActive %spotify%
;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
MouseClick, Right, 100, spotifyHeight - 70, 1, 0
;Get the contents of the context menu.
WinWait, ahk_class #32768
SendMessage, 0x1E1 ; MN_GETHMENU
allContextMenuInfo := ErrorLevel
;The "Star" command is the 5th 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, 5)
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.
Send {Down}{Down}{Down}{Down}{Down}{Enter}
} Else {
;Just close the context menu.
Send {Escape}
}
;Restore original window and mouse position.
WinActivate ahk_id %winID%
MouseMove %x%, %y%
}
Return
;Conext 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
}
我没有代表在GollyJer的答案中添加注释,但我注意到在尝试使用该脚本时,{down}击键存在问题,这会使其以某种方式将播放列表中的突出显示的歌曲下移,而不是在菜单上向下移动。我对其进行了修改,以便在“星”菜单项上单击鼠标而不是使用键,这似乎工作得很好。我还对其进行了编辑,以在将Spotify最小化之前将其最小化,然后再翻转回您使用的窗口。
^+*::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
WinGet, MMX, MinMax, %spotify%
;Store active window and mouse position.
WinGetActiveTitle, activeWindow
MouseGetPos x, y, winID
;Activate Spotify.
WinActivate %spotify%
WinWaitActive %spotify%
;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
MouseClick, Right, 100, spotifyHeight - 70, 1, 0
;Get the contents of the context menu.
WinWait, ahk_class #32768
SendMessage, 0x1E1 ; MN_GETHMENU
allContextMenuInfo := ErrorLevel
;The "Star" command is the 5th 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, 5)
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.
MouseClick, Left, 20, -120, 1, 0,, R
} Else {
;Just close the context menu.
Send {Escape}
}
;Restore original window and mouse position.
IfEqual MMX, -1, WinMinimize, %spotify%
WinActivate ahk_id %winID%
MouseMove %x%, %y%
}
Return
;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应用程序Twinkle,它是一个独立于平台和GUI布局的解决方案,只需单击一下即可为Spotify歌曲加注视标。
依赖于“星号”命令的解决方案不再起作用...不再有星号命令,但是“星号”是可以添加文件夹的项目。该脚本执行此操作。
; Spotify "Star Song"
^+*::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
WinGetActiveTitle, activeWindow
MouseGetPos x, y, winID
;Activate Spotify.
WinActivate %spotify%
WinWaitActive %spotify%
;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
MouseClick, Right, 100, spotifyHeight - 70, 1, 0
;Open Add To... sub-menu
Send {A}
;The "Starred" command is the 2nd menu item. If the song is Starred it will be disabled.
Send {Down}{Enter}
;Restore original window and mouse position.
WinActivate ahk_id %winID%
MouseMove %x%, %y%
}
Return
Spotify不再具有“星号”,而且我似乎也无法再检索上下文菜单的内容,因此此方法将查看上下文菜单中的像素颜色并使用箭头键进行选择。如果最大化,最小化以及专辑封面大小,则适用。
^+*::
{
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
WinGet, MMX, MinMax, %spotify%
WinGetActiveTitle, activeWindow
MouseGetPos x, y, winID
;Activate Spotify.
WinActivate %spotify%
WinWaitActive %spotify%
;Get maximised status
WinGet, isMaximised, MinMax
;Clear any context menus
Send {Escape down}{Escape up}
;Right click near the song title in the "Now Playing" box.
WinGetPos, , , , spotifyHeight, %spotify%
MouseClick, Right, 44, spotifyHeight - (isMaximised = 1 ? 75 : 66), 1, 0
sleep 200
MouseMove 10,0, ,R
sleep 200
; Determine if the song is already added to your library or not
; Look at left edge of the 'S' in Save to Your Library
; or the 'R' in Remove from Your Library
; 0x282828 is the background color of the menu
; if the background color is not present then the song is not in your library
PixelGetColor, pixelColor, 91, spotifyHeight - (isMaximised = 1 ? 129 : 119)
if (pixelColor = 0x282828) {
;Move up to 'Save to Your Library' and hit enter
loop, 1 {
Send {Up down}
sleep 50
Send {Up up}
sleep 50
}
Send {Enter down}
sleep 50
Send {Enter up}
sleep 50
} else {
; Already added, so close context menu
Send {Escape down}
sleep 50
Send {Escape up}
Sleep 50
}
;Restore original window and mouse position.
IfEqual MMX, -1, WinMinimize, %spotify%
WinActivate ahk_id %winID%
MouseMove %x%, %y%
}
Return
}