trying to see if it will work and... running into the multi-timer lockup bug again....
Don't understand why in some cases running 2 timers kills one of them.
Code: Select all
;Spotify Media Shorcuts
;Version: 1.0
;Author: KuroiLight/klomb
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
global script_conditional_param := "ahk_class SpotifyMainWindow"
#Include %A_ScriptDIr%\includes\CommonCode.ahk
;#NoTrayIcon
#UseHook, On
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
global DebugMode := 0, AdList := {}
global SearchArea_X, SearchArea_Y, SearchArea_W, SearchArea_H, sX, sY, sW, sH, PPBtn, VolBtn
Initialize()
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!\::PushButton(PPBtn)
!]::SendSpotify("^{Right}")
![::SendSpotify("^{Left}")
!'::SendSpotify("^{Up}")
!`;::SendSpotify("^{Down}")
!.::
DebugMode += 1
DebugMode := (DebugMode >= 3 ? 0 : DebugMode)
Loop 19
ToolTip,,,, %A_Index%
return
!/::
cTitle := GetTitle()
if(!AdList[cTitle]) {
AdList[cTitle] := true
} else {
AdList.Delete(cTitle)
}
UpdateBlackList()
UpdatePositions()
if(isAd(cTitle) != isSpotifyMuted())
PushButton(VolBtn)
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Initialize() {
MoveOffScreen()
if(FileExist(".\SpotifyAdList.dat")) {
Loop, Read, % ".\SpotifyAdList.dat"
{
AdList[A_LoopReadLine] := true
}
}
SetTimer, AutoMove, -1500
SetTimer, MainLoop, 1000
}
UpdateBlackList() {
FileDelete, ".\SpotifyAdList.dat"
for adName, _ in AdList
FileAppend, %adName%`n, ".\SpotifyAdList.dat"
}
AutoMove() {
Loop {
WinWaitActive, %script_conditional_param%
MoveOnScreen()
WinWaitNotActive, %script_conditional_param%
MoveOffScreen()
Sleep, 100
}
}
MainLoop() {
static pTitle, cMuted
CoordMode, Pixel, Screen
if((cTitle := GetTitle()) != pTitle or isAd(cTitle) != cMuted) {
Notify("[Spotify]`n" . cTitle)
UpdatePositions()
pTitle := cTitle
if(isAd(cTitle) != (cMuted := isSpotifyMuted()))
PushButton(VolBtn)
}
if(DebugMode) {
WinGetTitle, SpotifyTitle, %script_conditional_param%
ToolTip, % "isAd=" . isAd(cTitle) . "`ncMuted=" . cMuted . "`ncSong=" . SpotifyTitle, 1, 1, 11
}
}
GetTitle() {
WinGetTitle, SpotifyTitle, %script_conditional_param%
return SpotifyTitle
}
isAd(title) {
return (AdList[title] ? true : false)
}
PushButton(Btn) {
BtnX := (Btn.x + 10) - sX, BtnY := (Btn.y + 10) - sY
if(DebugMode == 1)
ToolTip, PushButton, % BtnX + sX, % BtnY + sY, 6
ControlClick, x%BtnX% y%BtnY%, %script_conditional_param%
}
isSpotifyMuted() {
PixelGetColor, cColor, % (VolBtn.x + 27), % (VolBtn.y + 7), RGB
if(DebugMode == 1)
ToolTip, %cColor%, % (VolBtn.x + 27) + 3, % (VolBtn.y + 7) + 3, 2
return (!(cColor == 0xB3B3B3 or cColor == 0x1DB954 or cColor == 0xFFFFFF) ? true : false)
}
UpdatePositions() {
static pX, pY, pW, pH
WinGetPos, sX, sY, sW, sH, %script_conditional_param%
if(sX != pX or sY != pY or sW != pW or sH != pH) {
pX := sX, pY := sY, pW := sW, pH := sH
SearchArea_X := sX
SearchArea_Y := sY + sH - 75
SearchArea_W := sX + sW
SearchArea_H := sY + sH
UpdateImgOffsets()
if(DebugMode == 1) {
ToolTip, SearchArea_XY, %SearchArea_X%, %SearchArea_Y%, 7
ToolTip, SearchArea_WH, %SearchArea_W%, %SearchArea_H%, 3
}
}
}
UpdateImgOffsets() {
static img_volbtn := ".\data\spotify\volBtn.png"
static img_play := ".\data\spotify\play.png"
static img_pause := ".\data\spotify\pause.png"
While(!(VolBtn := ImageSearch(img_volbtn))) {
Sleep, 25
}
PPBtn := ((PPBtn := ImageSearch(img_pause)) ? PPBtn : ImageSearch(img_play))
if(DebugMode == 1) {
ToolTip, VolBtn, % VolBtn.x, % VolBtn.y, 4
ToolTip, PPBtn, % PPBtn.x, % PPBtn.y, 5
}
}
ImageSearch(imgfile) {
ImageSearch, fX, fY, %SearchArea_X%, %SearchArea_Y%, %SearchArea_W%, %SearchArea_H%, *100 *Trans0xEC0BE4 %imgfile%
return (ErrorLevel == 0 ? {"x":fX, "y":fY} : false)
}
; ShowWindow() {
; WinGet, sHwnd, ID, %script_conditional_param%
; WinGet, mm, MinMax, %script_conditional_param%
; a := WinActive(script_conditional_param)
; WinGet, aot, Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText]
; if(WinActive(script_conditional_param))
; return 1
; DllCall("User32\ShowWindow", UInt, sHwnd, Int, 4, Int)
; WinSet, AlwaysOnTop, On, %script_conditional_param%
; WinSet, Redraw,, %script_conditional_param%
; Sleep, 25
; if(mm == -1) { ;minimized
; Sleep, 250
; return -1
; }
; return 0
; }
; HideWindow(pMM) {
; if(pMM == 1)
; return
; WinSet, AlwaysOnTop, Off, %script_conditional_param%
; WinSet, Bottom,, %script_conditional_param%
; if(pMM == -1)
; WinMinimize, %script_conditional_param%
; }
SendSpotify(key) {
if(WinActive("ahk_class SpotifyMainWindow"))
Send, %key%
else
ControlSend, ahk_parent, %key%, %script_conditional_param%
}
MoveOffScreen() {
SysGet, Primary, MonitorPrimary
SysGet, M, Monitor, %Primary%
WinGetPos, x, y, w, h, %script_conditional_param%
WinMove, %script_conditional_param%,, % (0 - w), % (MBottom + 1)
}
MoveOnScreen() {
SysGet, Primary, MonitorPrimary
SysGet, M, Monitor, %Primary%
WinGetPos, x, y, w, h, %script_conditional_param%
WinMove, %script_conditional_param%,, % (MRight / 2) - (w / 2), % (MBottom / 2) - (h / 2)
}
I have my doubts that this method will work, I don't think ImageSearch works on offscreen objects and I still need to restore w/ no activate when I accidently hit minimize on spotify.
I'm open to other suggestions though.
Just confirmed ImageSearch doesn't work offscreen.
The funny thing is I'm working on this script despite the fact that Ill be re-subbing to spotify in a week or 2... lol