How can I change the master volume level? Using this code
[DllImport (\"winmm.dll\")]
public static extern int waveOutSetVolume (IntPtr hwo, uint dwVolume);
Use this free library, it's simple and does the job. InputSimulator
It simulates a key press. You only have to add this reference and call wherever you want static methods like these:
InputSimulator.SimulateKeyPress(VirtualKeyCode.VOLUME_UP);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VOLUME_DOWN);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VOLUME_MUTE);
Then, if you want to get the master vokume level do:
// volume update
MMDevice defaultDevice = new MMDeviceEnumerator()
.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
// veloce attesa per l'aggiornamento del volume
Thread.Sleep(100);
float level = defaultDevice.AudioEndpointVolume.MasterVolumeLevelScalar;
Doing this you'll have in level the current volume in 0-1 format (eg. 52% is 0.52) If you want to have it in 0-100 format simply do level*100