;-- TIME_STAMP   2018-07-21 19:39:36   v 0.1

#Region    ;************ Includes ************
#include '_MuteActiveWindow.au3'
#EndRegion ;************ Includes ************

;~ Run('sndvol.exe')
;~ Exit

;~ Local $vMute = _MuteWindow(); Active window
;~ Local $vMute = _MuteWindow('Mozilla Firefox'); Window Title
;~ Local $vMute = _MuteWindow('MozillaWindowClass'); Classname
;~ Local $vMute = _MuteWindow(0x009511BA); Window Handle
;~ Local $vMute = _MuteWindow(WinGetHandle('[REGEXPTITLE:.*Firefox.*]')); Window Handle
;~ Local $vMute = _MuteWindow(14132); PID
;~ Local $vMute = _MuteWindow('firefox.exe') ; ProcessName
;~ Local $vMute = _MuteWindow('Systemsounds'); Toggles the Systemsounds
;~ Local $vMute = _MuteWindow('Lautsprecher'); Toggles the Lautsprecher (loudspeaker)
; Das ^^ könnte man auch auf anderen (vorhandene) Geräte anwenden...
;~ ConsoleWrite('@@ Debug line' & @TAB & @ScriptLineNumber & '   var: $vMute = ' & $vMute & @CRLF & '!@ ' & @TAB & '#Error: ' & @error & @TAB & '#Extended: ' & @extended & @CRLF)
;~ Exit

OnAutoItExitRegister('_MuteExit')

Global $g_aHotKeys = [HotKeySet('+!m', '_MuteActiveWindow'), HotKeySet('^+m', '_MuteExit')]

If Not $g_aHotKeys[0] Then Exit MsgBox(16, @ScriptName, 'Hotkey Alt+Shift+M could not be set!') ; Hotkey to mute active window sound.
If Not $g_aHotKeys[1] Then Exit MsgBox(16, @ScriptName, 'Hotkey Ctrl+Shift+M could not be set!') ; Hotkey to exit this script.

_CW('>  Alt+Shift+M : Hotkey to mute active window sound.')
_CW('> Ctrl+Shift+M : Hotkey to exit this script.\n')

While Sleep(250)
WEnd

Func _MuteActiveWindow()
	Local Static $bBreak = False
	If Not $bBreak Then ; So that the function is not called several times before it has been run through.
		$bBreak = True
		Local $vMute = _MuteWindow()
		If @error Then MsgBox(48, @ScriptName, '$vMute = ' & $vMute & @CRLF & @CRLF & '#Error: ' & @error & @CRLF & '#Extended: ' & @extended & @CRLF, 3)
		$bBreak = False
	EndIf
EndFunc   ;==>_MuteActiveWindow

Func _MuteExit()
	If $g_aHotKeys[0] Then HotKeySet('+!m')
	If $g_aHotKeys[1] Then HotKeySet('^+!m')
	Exit
EndFunc   ;==>_MuteExit
