-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mousemeeter.ahk
309 lines (267 loc) · 7.62 KB
/
Mousemeeter.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
;@Ahk2Exe-Let Version = 1.4
;@Ahk2Exe-IgnoreBegin
;@Ahk2Exe-IgnoreEnd
;@Ahk2Exe-SetMainIcon icon.ico
;@Ahk2Exe-SetVersion %U_Version%
;@Ahk2Exe-SetName Mousemeeter
;@Ahk2Exe-SetDescription Mousemeeter
;@Ahk2Exe-Bin Unicode 64*
;@Ahk2Exe-Obey U_au, = "%A_IsUnicode%" ? 2 : 1 ; .Bin file ANSI or Unicode?
#SingleInstance Force
#Persistent
#NoEnv
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
SendMode Input
#Include VMR.ahk/VMR.ahk
ProcessExists(name) {
Process, Exist, %name%
return ErrorLevel
}
While (!ProcessExists("voicemeeter8.exe") && !ProcessExists("voicemeeter8x64.exe"))
Sleep, 1000
Sleep 5000
global RunAsAdmin := True
global TitleMatchMode := 3
global ResetOnStartup := True
global SetAffinity := True
global SetCracklingFix := True
global OUTPUT_1 := 6
global OUTPUT_2 := 7
global OUTPUT_3 := 8
global VOLUME_CHANGE_AMOUNT := 0.5
global voicemeeter := new Voicemeeter()
global isActivated := True
global HotkeyState := False
global DeactivateOnWindow := False
global default_file := "default.xml"
global profile1_file := "profile1.xml"
global profile2_file := "profile2.xml"
global current_file := default_file
Menu, Tray, DeleteAll
Menu, Tray, NoStandard
Menu, Tray, UseErrorLevel, On
Menu, Tray, Add, Reload, ReloadHandler
Menu, Tray, Add, Refresh Config, RefreshHandler
Menu, Tray, Add,
Menu, Tray, Add, Open Config, OpenConfigHandler
Menu, Tray, Add,
Menu, Tray, Add, Exit, ExitHandler
Start()
Return
ReloadHandler:
Reload
return
RefreshHandler:
If (FileExist("config.ini"))
ReadConfigIni()
return
OpenConfigHandler:
If (FileExist("config.ini")) {
RunWait, config.ini
ReadConfigIni()
}
return
ExitHandler:
ExitApp
return
Start() {
If (FileExist("config.ini"))
ReadConfigIni()
if (!A_IsAdmin && RunAsAdmin) {
Try {
Run *RunAs "%A_ScriptFullPath%"
} catch {
MsgBox % "Declined Elevation, if you want to start this up without Admin Rights, change 'RunAsAdmin' to 0 in config.json"
ExitApp
}
}
SetTitleMatchMode, %TitleMatchMode%
If (SetAffinity)
Process, Priority,, High
If (SetCracklingFix)
Run, powershell "$Process = Get-Process audiodg; $Process.ProcessorAffinity=1; $Process.PriorityClass=""High""",, Hide
If (ResetOnStartup)
voicemeeter.load(default_file)
MainLoop()
}
MainLoop() {
If (DeactivateOnWindow) {
Loop
{
Loop, Parse, DeactivateOnWindow, `n,`r
{
if WinActive(A_LoopField) {
isActivated := False
WinWaitNotActive % A_LoopField
isActivated := True
}
Sleep, 300
}
Sleep, 500
}
}
}
ReadConfigIni() {
IniRead, SettingSectionExist, config.ini, Settings
If (SettingSectionExist) {
IniRead, RunAsAdmin, config.ini, Settings, RunAsAdmin
IniRead, TitleMatchMode, config.ini, Settings, TitleMatchMode
IniRead, ResetOnStartup, config.ini, Settings, ResetOnStartup
IniRead, SetAffinity, config.ini, Settings, SetAffinity
IniRead, SetCracklingFix, config.ini, Settings, SetCracklingFix
}
IniRead, VoicemeeterSectionExist, config.ini, VoicemeeterSettings
If (VoicemeeterSectionExist) {
IniRead, OUTPUT_1, config.ini, VoicemeeterSettings, OUTPUT_1
IniRead, OUTPUT_2, config.ini, VoicemeeterSettings, OUTPUT_2
IniRead, OUTPUT_3, config.ini, VoicemeeterSettings, OUTPUT_3
IniRead, VOLUME_CHANGE_AMOUNT, config.ini, VoicemeeterSettings, VOLUME_CHANGE_AMOUNT
IniRead, default_file, config.ini, VoicemeeterSettings, default_file
IniRead, profile1_file, config.ini, VoicemeeterSettings, profile1_file
IniRead, profile2_file, config.ini, VoicemeeterSettings, profile2_file
}
IniRead, DeactivateOnWindow, config.ini, DeactivateOnWindow
}
;KB-HOTKEYS
^!F4::
WinGet, active_id, PID, A
run, taskkill /PID %active_id% /F,,Hide
return
^+R::
KeyWait, R
KeyWait, R, d t0.250
If (Errorlevel) {
voicemeeter.restart()
}
Else {
voicemeeter.load(default_file)
current_file := default_file
}
Return
;Mouse-HOTKEYS
#If isActivated
XButton1::
While GetKeyState("XButton1", "P") {
HotkeyState := True
Sleep 200
}
HotkeyState := False
Return
XButton2::
While GetKeyState("XButton2", "P") {
HotkeyState := True
Sleep 200
}
HotkeyState := False
Return
XButton1 Up::
HotkeyState := False
If (A_PriorHotkey == "XButton1")
Send, {XButton1}
Return
XButton2 Up::
HotkeyState := False
If (A_PriorHotkey == "XButton2")
Send, {XButton2}
Return
#If isActivated && HotkeyState
LButton::
If (GetKeyState("XButton1","P") && GetKeyState("XButton2","P"))
Send, {LButton}
Else If (GetKeyState("XButton1","P"))
Send, {LButton}
Else If (GetKeyState("XButton2","P"))
Send, {Media_Prev}
Return
RButton::
If (GetKeyState("XButton1","P") && GetKeyState("XButton2","P"))
Send, {RButton}
Else If (GetKeyState("XButton1","P"))
Send, {RButton}
Else If (GetKeyState("XButton2","P"))
Send, {Media_Next}
Return
MButton::
If (GetKeyState("XButton1","P") && GetKeyState("XButton2","P"))
Send, {MButton}
Else If (GetKeyState("XButton1","P"))
Send, {MButton}
Else If (GetKeyState("XButton2","P"))
Send, {Media_Play_Pause}
Return
WheelUp::
If (GetKeyState("XButton1","P") && GetKeyState("XButton2","P")) ;VAIO3
voicemeeter.volumeUp(OUTPUT_3)
Else If (GetKeyState("XButton1","P")) ;VAIO
voicemeeter.volumeUp(OUTPUT_1)
Else If (GetKeyState("XButton2","P")) ;AUX
voicemeeter.volumeUp(OUTPUT_2)
Return
WheelDown::
If (GetKeyState("XButton1","P") && GetKeyState("XButton2","P")) ;VAIO3
voicemeeter.volumeDown(OUTPUT_3)
Else If (GetKeyState("XButton1","P")) ;VAIO
voicemeeter.volumeDown(OUTPUT_1)
Else If (GetKeyState("XButton2","P")) ;AUX
voicemeeter.volumeDown(OUTPUT_2)
Return
#If
F24::
If (GetKeyState("XButton1","P") && GetKeyState("XButton2","P")) ;VAIO3
voicemeeter.volumeMute(OUTPUT_3)
Else If (GetKeyState("XButton1","P")) ;VAIO
voicemeeter.volumeMute(OUTPUT_1)
Else If (GetKeyState("XButton2","P")) ;AUX
voicemeeter.volumeMute(OUTPUT_2)
Else {
KeyWait, %A_ThisHotkey%
KeyWait, %A_ThisHotkey%, d t0.250
If (Errorlevel) {
if (current_file == profile1_file) {
voicemeeter.load(default_file)
current_file := default_file
}
Else {
voicemeeter.load(profile1_file)
current_file := profile1_file
}
}
Else {
if (current_file == profile2_file) {
voicemeeter.load(default_file)
current_file := default_file
}
Else {
voicemeeter.load(profile2_file)
current_file := profile2_file
}
}
}
Return
;Classes
Class Voicemeeter {
vm := ""
__New() {
this.vm := new VMR()
this.vm.login()
}
volumeUp(strip) {
this.vm.strip[strip].gain += VOLUME_CHANGE_AMOUNT
}
volumeDown(strip) {
this.vm.strip[strip].gain -= VOLUME_CHANGE_AMOUNT
}
volumeMute(strip, v = -1) {
if (v != -1)
this.vm.strip[strip].mute := v
Else
this.vm.strip[strip].mute--
}
restart() {
this.vm.command.restart()
}
load(file) {
this.vm.command.load(A_ScriptDir . "\" . file)
}
}