Skip to content

Commit 8a82bf3

Browse files
authored
Add PTT function from AHK_MicMute:rewrite (#2)
1 parent dbf3649 commit 8a82bf3

14 files changed

+110
-93
lines changed

Lib/OSD.ahk

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
Global OSD_state:= 0
22
Global OSD_txt:=
3+
Global OSD_sysTheme:=
4+
OSD_getSysTheme()
35
OSD_spawn(txt, OSD_Accent, exclude_fullscreen:=0){
46
if (exclude_fullscreen && isActiveWinFullscreen())
57
return
68
if (OSD_state = 0){
79
SetFormat, integer, d
8-
Gui, Color, 191919, %OSD_Accent%
10+
Gui, Color,% OSD_sysTheme? "E6E6E6":"191919" , OSD_Accent
911
Gui, +AlwaysOnTop -SysMenu +ToolWindow -caption -Border
10-
Gui, Font, s11, Segoe UI
12+
Gui, Font, s11 w500, Segoe UI
1113
Gui, Add, Text, c%OSD_Accent% vOSD_txt W165 Center, %txt%
1214
SysGet, MonitorWorkArea, MonitorWorkArea, 0
1315
OSD_yPos:= MonitorWorkAreaBottom * 0.95
@@ -23,6 +25,10 @@ OSD_destroy(){
2325
OSD_state := 0
2426
SetTimer, OSD_destroy, Off
2527
}
28+
OSD_getSysTheme(){
29+
RegRead, OSD_sysTheme
30+
, HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
31+
}
2632
isActiveWinFullscreen(){ ;returns true if the active window is fullscreen
2733
winID := WinExist( "A" )
2834
if ( !winID )

MicMute.ahk

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,50 @@
11
#Include, <VA>
22
#Include, <OSD>
3-
OSD_spawn("Loading config...", "4BB04F")
4-
#Include, resources.ahk
3+
#Include, config.ahk
4+
#Include, assets.ahk
5+
OSD_spawn("MicMute", "4BB04F")
56
global global_mute:= ;1 muted
7+
global keys:= StrSplit(hotkey_mute, [" ","#","!","^","+","&",">","<","*","~","$","UP"], " `t")
68
init_tray()
79
update_state()
810
if (sys_update){
911
SetTimer, update_state, 500
1012
}
1113
if (hotkey_mute=hotkey_unmute){
12-
Hotkey, %hotkey_mute%, toggle_hotkey
14+
Hotkey,%hotkey_mute% ,% push_to_talk? "ptt_hotkey" : "toggle_hotkey"
1315
}else{
1416
Hotkey, %hotkey_mute%, mute_hotkey
1517
Hotkey, %hotkey_unmute%, unmute_hotkey
1618
}
1719
;Hotkey Functions
1820
toggle_hotkey(){
19-
VA_SetMasterMute(!global_mute, device_name . ":1")
21+
VA_SetMasterMute(!global_mute, device_name)
2022
update_state()
21-
show_feedback(global_mute)
23+
show_feedback(global_mute, sound_feedback, OSD_feedback)
24+
}
25+
ptt_hotkey(){
26+
unmute_hotkey()
27+
KeyWait, % keys[keys.Length()]
28+
mute_hotkey()
2229
}
2330
mute_hotkey(){
2431
if (global_mute)
2532
return
26-
VA_SetMasterMute(1, device_name . ":1")
33+
VA_SetMasterMute(1, device_name)
2734
update_state()
28-
show_feedback(global_mute)
35+
show_feedback(global_mute, sound_feedback, OSD_feedback)
2936
}
3037
unmute_hotkey(){
3138
if (!global_mute)
3239
return
33-
VA_SetMasterMute(0, device_name . ":1")
40+
VA_SetMasterMute(0, device_name)
3441
update_state()
35-
show_feedback(global_mute)
42+
show_feedback(global_mute, sound_feedback, OSD_feedback)
3643
}
37-
;
3844
update_state(){
39-
state:=VA_GetMasterMute(device_name . ":1")
45+
state:=VA_GetMasterMute(device_name)
4046
if (state!=global_mute){
4147
global_mute:=state
4248
update_tray(global_mute)
4349
}
44-
}
45-
update_tray(state){
46-
Menu, Tray, Icon, % state? mute_ico : default_ico
47-
Menu, Tray, Tip, % state? "Microphone Muted" : "Microphone Online"
48-
}
49-
show_feedback(state){
50-
if (sound_feedback){
51-
SoundPlay,% state? "resources\mute.mp3" : "resources\unmute.mp3"
52-
}
53-
if (OSD_feedback){
54-
OSD_destroy()
55-
if (state)
56-
OSD_spawn("Microphone Muted", "DC3545", exclude_fullscreen)
57-
else
58-
OSD_spawn("Microphone Online", "007BFF", exclude_fullscreen)
59-
}
60-
}
61-
;tray initialization functions
62-
init_tray(){
63-
RegRead, sysTheme
64-
, HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
65-
default_ico:= sysTheme? "resources\default_black.ico" : "resources\default_white.ico"
66-
mute_ico:= sysTheme? "resources\mute_black.ico" : "resources\mute_white.ico"
67-
if (FileExist(default_ico)) {
68-
Menu, Tray, Icon, %default_ico%
69-
}
70-
Menu, Tray, Tip, MicMute
71-
Menu, Tray, NoStandard
72-
Menu, Tray, Add, Edit Config, edit_config
73-
Menu, Tray, Add, Help, launch_help
74-
Menu, Tray, Add, Exit, exit
75-
}
76-
launch_help(){
77-
Run, https://github.com/SaifAqqad/AHK_MicMute#usage
78-
}
79-
exit(){
80-
ExitApp
8150
}

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
</p>
77

88
## Usage
9-
A config file will open the first time you run the application:
9+
A config file will be created the first time you run the Script:
1010
```ini
1111
[settings]
1212
Microphone=""
1313
MuteHotkey=""
1414
UnmuteHotkey=""
15+
PushToTalk=
1516
SoundFeedback=
1617
OnscreenFeedback=
1718
ExcludeFullscreen=
@@ -21,25 +22,30 @@ UpdateWithSystem=
2122
1. `Microphone` can be any substring of your microphone's name or the controller's name as shown in this image:
2223
<details><summary>image</summary>
2324

24-
![](./resources/Controlpaneldialog.png)
25+
![](./assets/Controlpaneldialog.png)
2526

2627
</details>
27-
28+
29+
you can also leave it as `""` to select the default microphone
2830
###
2931
2. Both `MuteHotkey` and `UnmuteHotkey` can be any hotkey supported by AHK, use this [List of keys](https://www.autohotkey.com/docs/KeyList.htm) as a reference, you can also combine them with [hotkey modifiers](https://www.autohotkey.com/docs/Hotkeys.htm#Symbols).
3032

33+
You can set both to the same hotkey to make it a toggle.
34+
35+
3136
Examples: `"<^M"`: left ctrl+M, `"RShift"`: right shift, `"^!T"`: ctrl+alt+T, `"LControl & XButton1"`: left ctrl+ mouse 4
3237

33-
Note: If both are set to the same hotkey, it will act as a toggle
3438

35-
3. Both `SoundFeedback` and `OnscreenFeedback` can be set to either `0` or `1`, you can also set `ExcludeFullscreen` to 1 to stop the OSD from showing on top of fullscreen applications
39+
3. Set `PushToTalk` to `1` to enable PTT, `MuteHotkey` and `UnmuteHotkey` need to be set to the same hotkey first.
40+
41+
4. Both `SoundFeedback` and `OnscreenFeedback` can be set to either `0` or `1`, you can also set `ExcludeFullscreen` to 1 to stop the OSD from showing on top of fullscreen applications
3642
<details><summary>On screen feedback</summary>
3743

38-
![](./resources/OSD.gif)
44+
![](./assets/OSD.gif)
3945

4046
</details>
4147

42-
4. If `UpdateWithSystem` is set to 1, the tray icon will update whenever the microphone is muted/unmuted by the OS or other applications, it increases CPU usage by 1% at most
48+
5. If `UpdateWithSystem` is set to 1, the tray icon will update whenever the microphone is muted/unmuted by the OS or other applications, it increases CPU usage by 1% at most
4349

4450

4551
###
@@ -50,6 +56,7 @@ UpdateWithSystem=
5056
Microphone="amazonbasics"
5157
MuteHotkey="*RShift"
5258
UnmuteHotkey="*RShift"
59+
PushToTalk=0
5360
SoundFeedback=1
5461
OnscreenFeedback=1
5562
ExcludeFullscreen=0

assets.ahk

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FileCreateDir, assets
2+
FileInstall, .\assets\mute.mp3, assets\mute.mp3
3+
FileInstall, .\assets\unmute.mp3, assets\unmute.mp3
4+
FileInstall, .\assets\default_white.ico, assets\default_white.ico
5+
FileInstall, .\assets\default_black.ico, assets\default_black.ico
6+
FileInstall, .\assets\mute_white.ico, assets\mute_white.ico
7+
FileInstall, .\assets\mute_black.ico, assets\mute_black.ico
8+
show_feedback(state, sound_feedback:=0, OSD_feedback:=0){
9+
if (sound_feedback){
10+
SoundPlay,% state? "assets\mute.mp3" : "assets\unmute.mp3"
11+
}
12+
if (OSD_feedback){
13+
OSD_destroy()
14+
if (state)
15+
OSD_spawn("Microphone Muted", "DC3545", exclude_fullscreen)
16+
else
17+
OSD_spawn("Microphone Online", "007BFF", exclude_fullscreen)
18+
}
19+
}
20+
update_tray(state){
21+
Menu, Tray, Icon, % state? mute_ico : default_ico
22+
Menu, Tray, Tip, % state? "Microphone Muted" : "Microphone Online"
23+
}
24+
init_tray(){
25+
RegRead, sysTheme
26+
, HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
27+
default_ico:= sysTheme? "assets\default_black.ico" : "assets\default_white.ico"
28+
mute_ico:= sysTheme? "assets\mute_black.ico" : "assets\mute_white.ico"
29+
if (FileExist(default_ico)) {
30+
Menu, Tray, Icon, %default_ico%
31+
}
32+
Menu, Tray, Tip, MicMute
33+
Menu, Tray, NoStandard
34+
Menu, Tray, Add, Edit Config, edit_config
35+
Menu, Tray, Add, Help, launch_help
36+
Menu, Tray, Add, Exit, exit
37+
}
38+
launch_help(){
39+
Run, https://github.com/SaifAqqad/AHK_MicMute#usage
40+
}
41+
exit(){
42+
ExitApp
43+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

config.ahk

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if (!FileExist("config.ini") || isFileEmpty("config.ini")) {
2+
IniWrite, Microphone=""`nMuteHotkey=""`nUnmuteHotkey=""`nPushToTalk=`nSoundFeedback=`nOnscreenFeedback=`nExcludeFullscreen=`nUpdateWithSystem=`n, config.ini, settings
3+
edit_config()
4+
}
5+
global device_name:="", global hotkey_mute:="", global hotkey_unmute:="", global push_to_talk:=""
6+
global sound_feedback:="", global OSD_feedback:=""
7+
global exclude_fullscreen:="", global sys_update:=""
8+
global mute_ico:="", global default_ico:=""
9+
IniRead, device_name, config.ini, settings, Microphone, %A_Space%
10+
IniRead, hotkey_mute, config.ini, settings, MuteHotkey, %A_Space%
11+
IniRead, hotkey_unmute, config.ini, settings, UnmuteHotkey, %A_Space%
12+
IniRead, push_to_talk, config.ini, settings, PushToTalk, 0
13+
IniRead, sound_feedback, config.ini, settings, SoundFeedback, 0
14+
IniRead, OSD_feedback, config.ini, settings, OnscreenFeedback, 0
15+
IniRead, exclude_fullscreen, config.ini, settings, ExcludeFullscreen, 0
16+
IniRead, sys_update, config.ini, settings, UpdateWithSystem, 0
17+
if (!device_name)
18+
device_name:="capture"
19+
if (!hotkey_mute or !hotkey_unmute)
20+
edit_config()
21+
edit_config(){
22+
RunWait, notepad config.ini
23+
Reload
24+
}
25+
isFileEmpty(file){
26+
FileGetSize, size , %file%
27+
return !size
28+
}

resources.ahk

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)