Skip to content

Commit

Permalink
Add PTT function from AHK_MicMute:rewrite (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad authored Aug 12, 2020
1 parent dbf3649 commit 8a82bf3
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 93 deletions.
10 changes: 8 additions & 2 deletions Lib/OSD.ahk
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Global OSD_state:= 0
Global OSD_txt:=
Global OSD_sysTheme:=
OSD_getSysTheme()
OSD_spawn(txt, OSD_Accent, exclude_fullscreen:=0){
if (exclude_fullscreen && isActiveWinFullscreen())
return
if (OSD_state = 0){
SetFormat, integer, d
Gui, Color, 191919, %OSD_Accent%
Gui, Color,% OSD_sysTheme? "E6E6E6":"191919" , OSD_Accent
Gui, +AlwaysOnTop -SysMenu +ToolWindow -caption -Border
Gui, Font, s11, Segoe UI
Gui, Font, s11 w500, Segoe UI
Gui, Add, Text, c%OSD_Accent% vOSD_txt W165 Center, %txt%
SysGet, MonitorWorkArea, MonitorWorkArea, 0
OSD_yPos:= MonitorWorkAreaBottom * 0.95
Expand All @@ -23,6 +25,10 @@ OSD_destroy(){
OSD_state := 0
SetTimer, OSD_destroy, Off
}
OSD_getSysTheme(){
RegRead, OSD_sysTheme
, HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
}
isActiveWinFullscreen(){ ;returns true if the active window is fullscreen
winID := WinExist( "A" )
if ( !winID )
Expand Down
65 changes: 17 additions & 48 deletions MicMute.ahk
Original file line number Diff line number Diff line change
@@ -1,81 +1,50 @@
#Include, <VA>
#Include, <OSD>
OSD_spawn("Loading config...", "4BB04F")
#Include, resources.ahk
#Include, config.ahk
#Include, assets.ahk
OSD_spawn("MicMute", "4BB04F")
global global_mute:= ;1 muted
global keys:= StrSplit(hotkey_mute, [" ","#","!","^","+","&",">","<","*","~","$","UP"], " `t")
init_tray()
update_state()
if (sys_update){
SetTimer, update_state, 500
}
if (hotkey_mute=hotkey_unmute){
Hotkey, %hotkey_mute%, toggle_hotkey
Hotkey,%hotkey_mute% ,% push_to_talk? "ptt_hotkey" : "toggle_hotkey"
}else{
Hotkey, %hotkey_mute%, mute_hotkey
Hotkey, %hotkey_unmute%, unmute_hotkey
}
;Hotkey Functions
toggle_hotkey(){
VA_SetMasterMute(!global_mute, device_name . ":1")
VA_SetMasterMute(!global_mute, device_name)
update_state()
show_feedback(global_mute)
show_feedback(global_mute, sound_feedback, OSD_feedback)
}
ptt_hotkey(){
unmute_hotkey()
KeyWait, % keys[keys.Length()]
mute_hotkey()
}
mute_hotkey(){
if (global_mute)
return
VA_SetMasterMute(1, device_name . ":1")
VA_SetMasterMute(1, device_name)
update_state()
show_feedback(global_mute)
show_feedback(global_mute, sound_feedback, OSD_feedback)
}
unmute_hotkey(){
if (!global_mute)
return
VA_SetMasterMute(0, device_name . ":1")
VA_SetMasterMute(0, device_name)
update_state()
show_feedback(global_mute)
show_feedback(global_mute, sound_feedback, OSD_feedback)
}
;
update_state(){
state:=VA_GetMasterMute(device_name . ":1")
state:=VA_GetMasterMute(device_name)
if (state!=global_mute){
global_mute:=state
update_tray(global_mute)
}
}
update_tray(state){
Menu, Tray, Icon, % state? mute_ico : default_ico
Menu, Tray, Tip, % state? "Microphone Muted" : "Microphone Online"
}
show_feedback(state){
if (sound_feedback){
SoundPlay,% state? "resources\mute.mp3" : "resources\unmute.mp3"
}
if (OSD_feedback){
OSD_destroy()
if (state)
OSD_spawn("Microphone Muted", "DC3545", exclude_fullscreen)
else
OSD_spawn("Microphone Online", "007BFF", exclude_fullscreen)
}
}
;tray initialization functions
init_tray(){
RegRead, sysTheme
, HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
default_ico:= sysTheme? "resources\default_black.ico" : "resources\default_white.ico"
mute_ico:= sysTheme? "resources\mute_black.ico" : "resources\mute_white.ico"
if (FileExist(default_ico)) {
Menu, Tray, Icon, %default_ico%
}
Menu, Tray, Tip, MicMute
Menu, Tray, NoStandard
Menu, Tray, Add, Edit Config, edit_config
Menu, Tray, Add, Help, launch_help
Menu, Tray, Add, Exit, exit
}
launch_help(){
Run, https://github.com/SaifAqqad/AHK_MicMute#usage
}
exit(){
ExitApp
}
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
</p>

## Usage
A config file will open the first time you run the application:
A config file will be created the first time you run the Script:
```ini
[settings]
Microphone=""
MuteHotkey=""
UnmuteHotkey=""
PushToTalk=
SoundFeedback=
OnscreenFeedback=
ExcludeFullscreen=
Expand All @@ -21,25 +22,30 @@ UpdateWithSystem=
1. `Microphone` can be any substring of your microphone's name or the controller's name as shown in this image:
<details><summary>image</summary>

![](./resources/Controlpaneldialog.png)
![](./assets/Controlpaneldialog.png)

</details>


you can also leave it as `""` to select the default microphone
###
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).

You can set both to the same hotkey to make it a toggle.


Examples: `"<^M"`: left ctrl+M, `"RShift"`: right shift, `"^!T"`: ctrl+alt+T, `"LControl & XButton1"`: left ctrl+ mouse 4

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

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
3. Set `PushToTalk` to `1` to enable PTT, `MuteHotkey` and `UnmuteHotkey` need to be set to the same hotkey first.

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
<details><summary>On screen feedback</summary>

![](./resources/OSD.gif)
![](./assets/OSD.gif)

</details>

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
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


###
Expand All @@ -50,6 +56,7 @@ UpdateWithSystem=
Microphone="amazonbasics"
MuteHotkey="*RShift"
UnmuteHotkey="*RShift"
PushToTalk=0
SoundFeedback=1
OnscreenFeedback=1
ExcludeFullscreen=0
Expand Down
43 changes: 43 additions & 0 deletions assets.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FileCreateDir, assets
FileInstall, .\assets\mute.mp3, assets\mute.mp3
FileInstall, .\assets\unmute.mp3, assets\unmute.mp3
FileInstall, .\assets\default_white.ico, assets\default_white.ico
FileInstall, .\assets\default_black.ico, assets\default_black.ico
FileInstall, .\assets\mute_white.ico, assets\mute_white.ico
FileInstall, .\assets\mute_black.ico, assets\mute_black.ico
show_feedback(state, sound_feedback:=0, OSD_feedback:=0){
if (sound_feedback){
SoundPlay,% state? "assets\mute.mp3" : "assets\unmute.mp3"
}
if (OSD_feedback){
OSD_destroy()
if (state)
OSD_spawn("Microphone Muted", "DC3545", exclude_fullscreen)
else
OSD_spawn("Microphone Online", "007BFF", exclude_fullscreen)
}
}
update_tray(state){
Menu, Tray, Icon, % state? mute_ico : default_ico
Menu, Tray, Tip, % state? "Microphone Muted" : "Microphone Online"
}
init_tray(){
RegRead, sysTheme
, HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
default_ico:= sysTheme? "assets\default_black.ico" : "assets\default_white.ico"
mute_ico:= sysTheme? "assets\mute_black.ico" : "assets\mute_white.ico"
if (FileExist(default_ico)) {
Menu, Tray, Icon, %default_ico%
}
Menu, Tray, Tip, MicMute
Menu, Tray, NoStandard
Menu, Tray, Add, Edit Config, edit_config
Menu, Tray, Add, Help, launch_help
Menu, Tray, Add, Exit, exit
}
launch_help(){
Run, https://github.com/SaifAqqad/AHK_MicMute#usage
}
exit(){
ExitApp
}
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.
28 changes: 28 additions & 0 deletions config.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
if (!FileExist("config.ini") || isFileEmpty("config.ini")) {
IniWrite, Microphone=""`nMuteHotkey=""`nUnmuteHotkey=""`nPushToTalk=`nSoundFeedback=`nOnscreenFeedback=`nExcludeFullscreen=`nUpdateWithSystem=`n, config.ini, settings
edit_config()
}
global device_name:="", global hotkey_mute:="", global hotkey_unmute:="", global push_to_talk:=""
global sound_feedback:="", global OSD_feedback:=""
global exclude_fullscreen:="", global sys_update:=""
global mute_ico:="", global default_ico:=""
IniRead, device_name, config.ini, settings, Microphone, %A_Space%
IniRead, hotkey_mute, config.ini, settings, MuteHotkey, %A_Space%
IniRead, hotkey_unmute, config.ini, settings, UnmuteHotkey, %A_Space%
IniRead, push_to_talk, config.ini, settings, PushToTalk, 0
IniRead, sound_feedback, config.ini, settings, SoundFeedback, 0
IniRead, OSD_feedback, config.ini, settings, OnscreenFeedback, 0
IniRead, exclude_fullscreen, config.ini, settings, ExcludeFullscreen, 0
IniRead, sys_update, config.ini, settings, UpdateWithSystem, 0
if (!device_name)
device_name:="capture"
if (!hotkey_mute or !hotkey_unmute)
edit_config()
edit_config(){
RunWait, notepad config.ini
Reload
}
isFileEmpty(file){
FileGetSize, size , %file%
return !size
}
36 changes: 0 additions & 36 deletions resources.ahk

This file was deleted.

0 comments on commit 8a82bf3

Please sign in to comment.