-
Notifications
You must be signed in to change notification settings - Fork 0
/
TauonGlobalHotkeys.ahk
104 lines (88 loc) · 2.75 KB
/
TauonGlobalHotkeys.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#Requires AutoHotkey v1
#Warn
#NoEnv
#SingleInstance, Force
SendMode, Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
TauonBaseURL := "http://localhost:7814/api1/"
#If, ProcessExist("tauon.exe")
; Global hotkeys for media control (Has some overhead to initialize after some time)
$Media_Prev::
TauonSendCommand("back")
TauonDisplaySongInfo()
Return
$CapsLock::
TauonDisplaySongInfo()
Return
$Media_Next::
TauonSendCommand("next")
TauonDisplaySongInfo()
Return
$Volume_Down::
TauonSendCommand("setvolumerel/-5")
TauonDisplayVolumeInfo("-")
Return
$Volume_Up::
TauonSendCommand("setvolumerel/5")
TauonDisplayVolumeInfo("+")
Return
$Media_Play_Pause::TauonSwitchPlayState()
#IfWinActive
ToolTip(Text := "", X := "", Y := "", WhichToolTip := 1, Timeout := "") {
; https://www.autohotkey.com/boards/viewtopic.php?t=65494
ToolTip, %Text, X, Y, WhichToolTip
if (Timeout) {
RemoveToolTip := Func("ToolTip").Bind(, , , WhichToolTip)
SetTimer, %RemoveToolTip, % -Timeout
}
}
ProcessExist(Name) {
Process,Exist,%Name%
Return Errorlevel
}
TauonSendCommand(command) {
global HttpObj, TauonBaseURL
URL := TauonBaseURL . command
HttpObj.Open("GET", URL, false)
HttpObj.Send()
}
TauonGetStatus(command) {
global HttpObj, TauonBaseURL
URL := TauonBaseURL . "status"
HttpObj.Open("GET", URL, false)
HttpObj.Send()
HttpObj.WaitForResponse()
Return HttpObj.ResponseText
}
TauonDisplaySongInfo() {
global HttpObj, TauonBaseURL
pattern1 := """artist"": ""(.*?)"","
pattern2 := """title"": ""(.*?)"","
ResponseText := TauonGetStatus()
RegExMatch(ResponseText, pattern1, artist)
RegExMatch(ResponseText, pattern2, title)
ToolTip(artist1 . "`n" . title1, A_ScreenWidth, A_ScreenHeight, , 5000)
}
TauonDisplayVolumeInfo(change) {
global HttpObj, TauonBaseURL
pattern := """volume"": (.*?),"
ResponseText := TauonGetStatus()
RegExMatch(ResponseText, pattern, volume)
ToolTip("Volume set to: " . volume1 . change, A_ScreenWidth, A_ScreenHeight, , 2000)
}
TauonSwitchPlayState() {
global HttpObj, TauonBaseURL
pattern := """status"": ""(.*?)"","
ResponseText := TauonGetStatus()
RegExMatch(ResponseText, pattern, playState)
If (playState1 = "paused" || playState1 = "stopped") {
TauonSendCommand("play")
ToolTip("Playing", A_ScreenWidth, A_ScreenHeight, , 2000)
}
Else {
TauonSendCommand("pause")
ToolTip("Paused", A_ScreenWidth, A_ScreenHeight, , 2000)
}
}