Code: Select all
ToolTip,% "Mic " (master_mute="On"?"Off":"On") ;use a tool tip at mouse pointer to show what state mic is after toggle
Code: Select all
ToolTip,% "Mic " (master_mute="On"?"Off":"On") ;use a tool tip at mouse pointer to show what state mic is after toggle
Code: Select all
Capslock::
SoundSet, +1, MASTER, mute, 5 ;5 is my mic ID number, must use a separate script to figure out your mic ID. then replace the 5 in this line and the line below it with your mic ID
SoundGet, master_mute, , mute, 5
if (master_mute = "On") {
Loop, 12 {
KeyboardLED(4, "On", A_Index-1)
}
} else {
Loop, 12 {
KeyboardLED(4, "Off", A_Index-1)
}
}
KeyboardLED(LEDvalue, Cmd, Kbd=0)
{
SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
If Cmd= switch ;switches every LED according to LEDvalue
KeyLED:= LEDvalue
If Cmd= on ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
If Cmd= off ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
{
LEDvalue:= LEDvalue ^ 7
KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
}
success := DllCall( "DeviceIoControl"
, "ptr", h_device
, "uint", CTL_CODE( 0x0000000b ; FILE_DEVICE_KEYBOARD
, 2
, 0 ; METHOD_BUFFERED
, 0 ) ; FILE_ANY_ACCESS
, "int*", KeyLED << 16
, "uint", 4
, "ptr", 0
, "uint", 0
, "ptr*", output_actual
, "ptr", 0 )
NtCloseFile(h_device)
return success
}
CTL_CODE( p_device_type, p_function, p_method, p_access )
{
Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}
NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
VarSetCapacity(objattrib,6*A_PtrSize,0)
VarSetCapacity(io,2*A_PtrSize,0)
VarSetCapacity(pus,2*A_PtrSize)
DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
NumPut(6*A_PtrSize,objattrib,0)
NumPut(&pus,objattrib,2*A_PtrSize)
status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
,"UInt",flags,"ptr",0,"UInt",0, "UInt")
return % fh
}
NtCloseFile(handle)
{
return DllCall("ntdll\ZwClose","ptr",handle)
}
SetUnicodeStr(ByRef out, str_)
{
VarSetCapacity(out,2*StrPut(str_,"utf-16"))
StrPut(str_,&out,"utf-16")
}
If you have more than one microphone to mute in the script, one of the IDs you have in there could be the ID for the Speaker (not the microphone).OsquoWassen wrote: ↑17 Aug 2020, 06:08Hi, i have the exact same problem as the last guy, (Script is muting my speakers instead of mic) difference is i cant figure it out. Could someone help please?
Code: Select all
MicList := GetMics(80)
; Unmute all mics so all mics are in same state
For k, v in MicList
{
SoundSet, 0, MASTER, mute, v
}
Pause::
For k, v in MicList
{
SoundSet, +1, MASTER, mute, v
SoundGet, master_mute, , mute, v
}
; change the message for the tool tip
if (master_mute = "On")
msg := "Mic is OFF"
if (master_mute = "Off")
msg := "Mic is ON"
ToolTip, %msg% ; use a tool tip at mouse pointer to show what state mic is after toggle
SetTimer, RemoveToolTip, 500
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
GetMics(vol)
{
SetBatchLines -1
SplashTextOn,,, % "Finding Mics Set to " . vol . "%..."
ControlTypes = VOLUME,ONOFF,MUTE,MONO,LOUDNESS,STEREOENH,BASSBOOST,PAN,QSOUNDPAN,BASS,TREBLE,EQUALIZER,0x00000000, 0x10010000,0x10020000,0x10020001,0x10030000,0x20010000,0x21010000,0x30040000,0x30020000,0x30030000,0x30050000,0x40020000,0x50030000,0x70010000,0x70010001,0x71010000,0x71010001,0x60030000,0x61030000
ComponentTypes = MASTER,HEADPHONES,DIGITAL,LINE,MICROPHONE,SYNTH,CD,TELEPHONE,PCSPEAKER,WAVE,AUX,ANALOG,N/A
Mics := []
Loop ; For each mixer number that exists in the system, query its capabilities.
{
CurrMixer := A_Index
SoundGet, Setting,,, %CurrMixer%
if ErrorLevel = Can't Open Specified Mixer ; Any error other than this indicates that the mixer exists.
break
; For each component type that exists in this mixer, query its instances and control types:
Loop, parse, ComponentTypes, `,
{
CurrComponent := A_LoopField
; First check if this component type even exists in the mixer:
SoundGet, Setting, %CurrComponent%,, %CurrMixer%
if ErrorLevel = Mixer Doesn't Support This Component Type
continue ; Start a new iteration to move on to the next component type.
Loop ; For each instance of this component type, query its control types.
{
CurrInstance := A_Index
; First check if this instance of this instance even exists in the mixer:
SoundGet, Setting, %CurrComponent%:%CurrInstance%,, %CurrMixer%
; Checking for both of the following errors allows this script to run on older versions:
if ErrorLevel in Mixer Doesn't Have That Many of That Component Type,Invalid Control Type or Component Type
break ; No more instances of this component type.
; Get the current setting of each control type that exists in this instance of this component:
Loop, parse, ControlTypes, `,
{
CurrControl := A_LoopField
SoundGet, Setting, %CurrComponent%:%CurrInstance%, %CurrControl%, %CurrMixer%
; Checking for both of the following errors allows this script to run on older versions:
if ErrorLevel in Component Doesn't Support This Control Type,Invalid Control Type or Component Type
continue
if Setting != %vol% ; Only allow values that have been set to vol
continue
Mics.Push(CurrMixer)
} ; For each control type.
} ; For each component instance.
} ; For each component type.
} ; For each mixer.
SplashTextOff
SetBatchLines 10
return Mics
}
Great stuff, thanks for this tweak. I too was having issues with the id changing using docks etc...jaredarm wrote: ↑28 Mar 2022, 02:31Amazing! I created an account just to say thank you OP! This has opened my eyes to the power of AHK.
I've had the script running for a while but I was having some trouble where my mics wouldn't stay on the same ID number. I'm working from home a few days a week at the moment and the mixer values kept changing, probably from the different docking arrangements I have. I was getting tired of finding the mic IDs and editing the script, so I modified the script so that it runs the ID check when it's launched. It looks for any mics that mics with a volume of 80% (on a variable so that it can be changed easily). All I then need to do is change the volume of all the mics I want the script to mute to 80%. The script then mutes all the mics it found. I find it useful to mute all mics because I often change which mic I'm using for calls (headphones, laptop mic, webcam mic). I have it set to use the Pause key which I then have mapped to a spare mouse button.
My code below in case it helps anyone else.
.....
Code: Select all
ToolTip, % "Microphone " (master_mute = "On" ? "OFF" : "ON")
All rights reserved to "Firenyth" for the code, original page where I found the code here:
vie...
Code: Select all
if (master_mute = "Off") {
SoundBeep, 1500, 300
Menu, Tray, Icon, C:\Windows\System32\imageres.dll, 233
}
if (master_mute = "On") {
SoundBeep, 500, 300
Menu, Tray, Icon, C:\Windows\System32\imageres.dll, 230
}
Code: Select all
#Requires AutoHotkey v2.0-beta
#SingleInstance force
TraySetIcon "C:\Windows\System32\imageres.dll", 250
A_IconTip := "Microphone Status"
Pause:: {
if (SoundGetMute( , "Microphone") = 1) {
SoundSetMute 0, , "Microphone"
ToolTip "Microphone Mute Off"
SetTimer () => ToolTip(), -1000
TraySetIcon "C:\Windows\System32\imageres.dll", 233
SoundBeep 1500, 300
}
else {
SoundSetMute 1, , "Microphone"
ToolTip "Microphone Mute On"
SetTimer () => ToolTip(), -1000
TraySetIcon "C:\Windows\System32\imageres.dll", 230
SoundBeep 500, 300
}
}
This is working well on my work and personal laptops but isn't working on my home desktop. The mics on the laptops are integrated, but I have a Logi USB camera/mic combo on the desktop. Is that potentially affecting things? All devices are on Windows 10, 64 bit, same version of AHK (2.0.11.0), etc. I haven't tried the option of using a device ID from page 1 since this worked so well on the other devices.GioEarthling2 wrote: ↑14 Mar 2023, 06:45converted it to v2Code: Select all
#Requires AutoHotkey v2.0-beta #SingleInstance force TraySetIcon "C:\Windows\System32\imageres.dll", 250 A_IconTip := "Microphone Status" Pause:: { if (SoundGetMute( , "Microphone") = 1) { SoundSetMute 0, , "Microphone" ToolTip "Microphone Mute Off" SetTimer () => ToolTip(), -1000 TraySetIcon "C:\Windows\System32\imageres.dll", 233 SoundBeep 1500, 300 } else { SoundSetMute 1, , "Microphone" ToolTip "Microphone Mute On" SetTimer () => ToolTip(), -1000 TraySetIcon "C:\Windows\System32\imageres.dll", 230 SoundBeep 500, 300 } }
addded beep from willzen and tray icon status
thanks <3
UPDATE: even though the mics on all devices were just labelled "microphone" renaming the one on my desktop and updating "Microphone" to the new name got it to start working on the desktop as well. Thanks again for posting this GioEarthling2!mattofamillion wrote: ↑02 Jan 2024, 20:52This is working well on my work and personal laptops but isn't working on my home desktop. The mics on the laptops are integrated, but I have a Logi USB camera/mic combo on the desktop. Is that potentially affecting things? All devices are on Windows 10, 64 bit, same version of AHK (2.0.11.0), etc. I haven't tried the option of using a device ID from page 1 since this worked so well on the other devices.GioEarthling2 wrote: ↑14 Mar 2023, 06:45converted it to v2Code: Select all
#Requires AutoHotkey v2.0-beta #SingleInstance force TraySetIcon "C:\Windows\System32\imageres.dll", 250 A_IconTip := "Microphone Status" Pause:: { if (SoundGetMute( , "Microphone") = 1) { SoundSetMute 0, , "Microphone" ToolTip "Microphone Mute Off" SetTimer () => ToolTip(), -1000 TraySetIcon "C:\Windows\System32\imageres.dll", 233 SoundBeep 1500, 300 } else { SoundSetMute 1, , "Microphone" ToolTip "Microphone Mute On" SetTimer () => ToolTip(), -1000 TraySetIcon "C:\Windows\System32\imageres.dll", 230 SoundBeep 500, 300 } }
addded beep from willzen and tray icon status
thanks <3