Last active
August 5, 2021 21:49
-
-
Save tiagoad/4effd79eb4d331335128b9e3eecb491d to your computer and use it in GitHub Desktop.
A AutoHotKey script to implement push-to-talk at the Windows mixer level.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ------------ | |
; Push to talk | |
; ------------ | |
; | |
; This AutoHotKey script implements push-to-talk at the Windows mixer level. | |
; | |
; The hotkey set by HOTKEY_TOGGLE will toggle between "Open" and "PTT" mode: | |
; - Open: Microphone is unmuted; | |
; - PTT: Microphone is only unmuted while HOTKEY_PTT is pressed. | |
; | |
; Tray icon: | |
; - Red: Microphone is unmuted; | |
; - Blue: Microphone is muted. | |
; | |
; Author: Tiago Dias <[email protected]> | |
; | |
; Constants (change this) | |
global MIC_COMPONENT_TYPE := Master | |
global MIC_DEVICE_NUMBER := 5 ; Set this to your device number. See https://www.autohotkey.com/docs/commands/SoundSet.htm#Soundcard | |
global MIC_START_PTT := 1 ; Set to 0 to start in open mode, 1 to start in push to talk mode | |
global HOTKEY_PTT := "printscreen" ; This hotkey will unmute the interface while pressed, if in PTT mode | |
global HOTKEY_TOGGLE := "<^>!printscreen" ; This hotkey will toggle between PTT and Open mode | |
global ICON_MUTED := b64_to_hicon("iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJUlEQVRIiWP4z8Dwn5aYYdSCUQtGLRi1YNSCUQtGLRi1YGhYAADE1nu9V0lEEgAAAABJRU5ErkJggg==") | |
global ICON_UNMUTED := b64_to_hicon("iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJElEQVRIiWNgYPn/n6Z41IJRC0YtGLVg1IJRC0YtGLVgaFgAADwBhL013AtPAAAAAElFTkSuQmCC") | |
; Variables | |
global ptt := MIC_START_PTT | |
global talking := 0 | |
;; | |
;; Hotkeys | |
;; | |
Hotkey, %HOTKEY_PTT%, hotkey_ptt_down | |
Hotkey, %HOTKEY_PTT% up, hotkey_ptt_up | |
Hotkey, %HOTKEY_TOGGLE%, hotkey_toggle | |
; Mute mic on start, if PTT is on by default. | |
if (ptt) { | |
mic_mute() | |
} | |
return | |
; Toggle PTT <-> Always On | |
hotkey_toggle: | |
if (ptt) { | |
ptt = 0 | |
mic_unmute() | |
} else { | |
ptt = 1 | |
mic_mute() | |
} | |
return | |
; PTT | |
hotkey_ptt_down: | |
if (ptt) { | |
talking = 1 | |
mic_unmute() | |
} | |
return | |
; PTT | |
hotkey_ptt_up: | |
if (ptt and talking) { | |
mic_mute() | |
talking = 0 | |
return | |
} | |
;; | |
;; Utility functions | |
;; | |
get_mic_muted() { | |
SoundGet, volume, %MIC_COMPONENT_TYPE%, Mute, %MIC_DEVICE_NUMBER% | |
MsgBox, %volume% | |
return volume == "On" | |
} | |
mic_mute() { | |
SoundSet, 1, %MIC_COMPONENT_TYPE%, Mute, %MIC_DEVICE_NUMBER% | |
Menu, Tray, Icon, HICON:*%ICON_UNMUTED% | |
} | |
mic_unmute() { | |
SoundSet, 0, %MIC_COMPONENT_TYPE%, Mute, %MIC_DEVICE_NUMBER% | |
Menu, Tray, Icon, HICON:*%ICON_MUTED% | |
} | |
; https://www.autohotkey.com/boards/viewtopic.php?t=36636 | |
b64_to_hicon(b64, W:=0, H:=0) { | |
local blen := StrLen(b64) | |
local nBytes := Floor(StrLen(RTrim(b64, "="))) * 3/4 | |
local bin := 0 | |
local binary := DllCall("Crypt32.dll\CryptStringToBinary", "Str", b64, "UInt", BLen, "UInt", 1,"Ptr", &(Bin:=VarSetCapacity(Bin,nBytes)), "UIntP",nBytes, "UInt", 0, "UInt", 0) | |
local hicon := binary ? DllCall("CreateIconFromResourceEx", "Ptr",&Bin, "UInt", nBytes, "Int", True, "UInt", 0x30000, "Int", W, "Int", H, "UInt", 0, "UPtr") : 0 | |
return hicon | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment