-
Notifications
You must be signed in to change notification settings - Fork 0
/
speaker controls.ahk
119 lines (111 loc) · 2.52 KB
/
speaker controls.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
#Persistent ; This keeps the script running permanently.
#SingleInstance ; Only allows one instance of the script to run.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
global toggleMic:=false
global mic_source:=6 ;number gathered from soundanalysis.ahk
Loop { ;Validiates microphone status in case it is changed by another application
SoundGet, microphone_mute, MASTER, mute, global mic_source
if microphone_mute = Off
{
Menu, Tray, Icon, mic-on.png
global toggleMic:=true
}
else if microphone_mute = On
{
Menu, Tray, Icon, mic-mute.png
global toggleMic:=false
}
Sleep, 5000
}
^!;:: ; Speaker switcher
toggleSpeaker:=!toggleSpeaker ; This toggles the variable between true/false
if toggleSpeaker
{
Run, nircmd setdefaultsounddevice "Speakers"
soundToggleBox("Speakers")
}
else
{
Run, nircmd setdefaultsounddevice "Headphones"
soundToggleBox("Headphones")
}
Return
^!':: ; Mute mic toggle
if toggleMic
{
micMute()
}
else if !toggleMic
{
micOn()
}
Return
micMute()
{
SoundSet, 1, MASTER, mute, global mic_source
SoundGet, microphone_mute, MASTER, mute, global mic_source
if microphone_mute = On
{
global toggleMic:=false
micToggleBox("Mic Muted")
Menu, Tray, Icon, mic-mute.png
}
}
micOn()
{
SoundSet, +1, MASTER, mute, global mic_source
SoundGet, microphone_mute, MASTER, mute, global mic_source
if microphone_mute = Off
{
global toggleMic:=true
micToggleBox("Mic On")
Menu, Tray, Icon, mic-on.png
}
}
; Display sound toggle GUI
soundToggleBox(Device)
{
IfWinExist, soundToggleWin
{
Gui, destroy
}
Gui, +ToolWindow -Caption +0x400000 +alwaysontop
Gui, Add, text, x35 y8, Default sound: %Device%
SysGet, screenx, 0
SysGet, screeny, 1
xpos:=screenx-275
ypos:=screeny-100
Gui, Show, NoActivate x%xpos% y%ypos% h30 w200, soundToggleWin
SetTimer,soundToggleClose, 2000
}
soundToggleClose:
SetTimer,soundToggleClose, off
Gui, destroy
Return
; Display mic toggle GUI
micToggleBox(Device)
{
IfWinExist, micToggleWin
{
Gui, destroy
}
Gui, +ToolWindow -Caption +0x400000 +alwaysontop
Gui, Add, text, x35 y8, %Device%
SysGet, screenx, 0
SysGet, screeny, 1
xpos:=screenx-275
ypos:=screeny-100
Gui, Show, NoActivate x%xpos% y%ypos% h30 w120, micToggleWin
SetTimer,micToggleClose, 2000
}
micToggleClose:
SetTimer,micToggleClose, off
Gui, destroy
Return
~#l:: ; Mute on screen lock
SoundSet, 1,,Mute
micMute()
WinWait, A
SoundSet, 0,,Mute
Return