Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for togglemicrophonemute.cs

(view source code of togglemicrophonemute.cs as plain text)

  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4.  
  5. namespace RobvanderWoude
  6. {
  7. 	internal class ToggleMicrophoneMute
  8. 	{
  9. 		static readonly string progver = "1.00";
  10.  
  11.  
  12. 		static int Main( string[] args )
  13. 		{
  14. 			if ( args.Length == 0 )
  15. 			{
  16. 				AudioControl.ToggleMicrophoneMute( );
  17.  
  18. 				return 0;
  19. 			}
  20. 			else
  21. 			{
  22. 				Console.Error.WriteLine( "ToggleMicrophoneMute.exe, " + progver );
  23. 				Console.Error.WriteLine( "Toggle the microphone's muted state" );
  24. 				Console.Error.WriteLine( );
  25. 				Console.Error.Write( "Usage: " );
  26. 				Console.ForegroundColor = ConsoleColor.White;
  27. 				Console.Error.WriteLine( "ToggleMicrophoneMute" );
  28. 				Console.ResetColor( );
  29. 				Console.Error.WriteLine( );
  30. 				Console.Error.WriteLine( "Notes: This program is a wrapper for C++ code by Io-oI" );
  31. 				Console.Error.Write( "       on " );
  32. 				Console.ForegroundColor = ConsoleColor.DarkGray;
  33. 				Console.Error.WriteLine( "https://superuser.com/a/1870763" );
  34. 				Console.ResetColor( );
  35. 				Console.Error.WriteLine( "       No guarantee: if no microphone is available," );
  36. 				Console.Error.WriteLine( "       or if it is locked by another program, the" );
  37. 				Console.Error.WriteLine( "       (un)mute command is ignored without notification." );
  38. 				Console.Error.WriteLine( "       Return code equals -1 if any command line" );
  39. 				Console.Error.WriteLine( "       arguments were specified, or 0 otherwise." );
  40. 				Console.Error.WriteLine( );
  41. 				Console.Error.WriteLine( "Written by Rob van der Woude" );
  42. 				Console.Error.WriteLine( "https://www.robvanderwoude.com" );
  43.  
  44. 				return -1;
  45. 			}
  46. 		}
  47. 	}
  48.  
  49.  
  50. 	// code by Io-oI
  51. 	// https://superuser.com/a/1870763
  52. 	public class AudioControl
  53. 	{
  54. 		[DllImport( "user32.dll", CharSet = CharSet.Auto )]
  55. 		public static extern int SendMessage( int hWnd, int Msg, int wParam, int lParam );
  56.  
  57. 		public const int WM_APPCOMMAND = 0x319;
  58. 		public const int APPCOMMAND_MICROPHONE_VOLUME_MUTE = 0x180000;
  59.  
  60. 		public static void ToggleMicrophoneMute( )
  61. 		{
  62. 			SendMessage( 0xFFFF, WM_APPCOMMAND, 0, APPCOMMAND_MICROPHONE_VOLUME_MUTE );
  63. 		}
  64. 	}
  65. }

page last modified: 2025-10-11; loaded in 0.0082 seconds