Created
November 17, 2025 17:52
-
-
Save enyone/8ee1d1f48cd366e184acccdf3512c41d to your computer and use it in GitHub Desktop.
Windows microphone mute toggle code
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
| using System; | |
| using System.Runtime.InteropServices; | |
| namespace Mic { | |
| class Mute { | |
| [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); | |
| [DllImport("user32.dll")] public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); | |
| private const int WM_APPCOMMAND=0x319; | |
| private const int APPCOMMAND_MICROPHONE_VOLUME_MUTE=0x180000; | |
| public static void MicMute(IntPtr h) { | |
| SendMessageW(h, WM_APPCOMMAND, h, (IntPtr)APPCOMMAND_MICROPHONE_VOLUME_MUTE); | |
| } | |
| static void Main(string[] args) | |
| { | |
| MicMute(GetForegroundWindow()); | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Build with: