I got the following code to simulate volumemute keypress:
[DllImport("coredll.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
byte VK_VOLUME_MUTE = 0xAD;
const int KEYEVENTF_KEYUP = 0x2;
const int KEYEVENTF_KEYDOWN = 0x0;
private void button1_Click(object sender, EventArgs e)
{
keybd_event(VK_VOLUME_MUTE, 0, KEYEVENTF_KEYDOWN, 0);
keybd_event(VK_VOLUME_MUTE, 0, KEYEVENTF_KEYUP, 0);
}
This code doesnt work. I know there's another way to mute/unmute sound by SendMessageW, but I dont want to use SendMessageW because I use KeyState to detect wheter I need to mute the sound or unmute the sound (if the user wants to unmute the sound and its already unmuted then I dont need to toggle - thats why I need to simulate VolumeMute keypress)
Thanks.