Last active
January 18, 2023 10:26
-
-
Save Generhr/3ccd99f0d099fed4319bd4cd78847935 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;* PostMessage(msg, (wParam), (lParam), (winTitle), (excludeTitle), (detectHiddenWindows)) | |
| PostMessage(msg, wParam := 0, lParam := 0, winTitle := "", excludeTitle := "", detectHiddenWindows := "") { | |
| if (!(detectHiddenWindows == "") && !(detectHiddenWindows == (detect := A_DetectHiddenWindows))) { | |
| DetectHiddenWindows, % detectHiddenWindows ;~ No error handling. | |
| } | |
| PostMessage, msg, wParam, lParam, , % winTitle, , % excludeTitle | |
| if (detect) { | |
| DetectHiddenWindows, % detect | |
| } | |
| return (ErrorLevel) ;* ErrorLevel is set to 1 if there was a problem such as the target window or control not existing. Otherwise, it is set to 0. | |
| } | |
| Class Spotify { | |
| Static Handle := 0 | |
| Pause() { | |
| PostMessage(0x319, , 0xD0000, this.GetWindow(1), , "On") ;? 0x319 = WM_APPCOMMAND | |
| } | |
| PlayPause() { | |
| PostMessage(0x319, , 0xE0000, this.GetWindow(1), , "On") | |
| } | |
| Play() { | |
| Local | |
| detect := A_DetectHiddenWindows | |
| DetectHiddenWindows, On | |
| window := this.GetWindow(1) | |
| PostMessage, 0x319, , 0xD0000, , % window | |
| PostMessage, 0x319, , 0xE0000, , % window | |
| DetectHiddenWindows, % detect | |
| } | |
| Prev() { | |
| PostMessage(0x319, , 0xC0000, this.GetWindow(1), , "On") | |
| } | |
| Next() { | |
| PostMessage(0x319, , 0xB0000, this.GetWindow(1), , "On") | |
| } | |
| GetWindow(prefix := true) { | |
| Local | |
| detect := A_DetectHiddenWindows | |
| DetectHiddenWindows, On | |
| if (WinExist("ahk_exe Spotify.exe")) { | |
| if (this.Handle && DllCall("IsWindow", "Ptr", this.Handle, "UInt")) { | |
| window := (prefix) ? ("ahk_ID" . this.Handle) : (this.Handle) | |
| } | |
| else { | |
| for i, hWnd in WinGet("List", "ahk_exe Spotify.exe") { | |
| if (WinGet("Class", "ahk_ID" . hWnd) == "Chrome_WidgetWin_0" && WinGet("Title", "ahk_ID" . hWnd) ~= "^(Spotify.*|.* - .*)$") { | |
| this.Handle := hWnd | |
| , window := (prefix) ? ("ahk_ID" . hWnd) : (hWnd) | |
| break | |
| } | |
| } | |
| } | |
| } | |
| DetectHiddenWindows, % detect ;* Avoid leaving `DetectHiddenWindows` on for the calling thread. | |
| return (window) | |
| } | |
| } |
which version is the AHK?
ErrorLevel was removed in v2, this is old v1 code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
which version is the AHK?