I'm writing C# desktop application, which would allow me to mute my mic on hotkey, when I'm playing smtng with discord/skype/teamspeak etc. So, I need my app to accept my hotkey (ex: ctrl + B) without me alt+tabbing from my game.
public partial class Form1 : Form
{
private const int APPCOMMAND_MICROPHONE_VOLUME_MUTE = 0x180000;
private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int WM_APPCOMMAND = 0x319;
[DllImport("user32.dll")]
public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg,
IntPtr wParam, IntPtr lParam);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
return;
}
private void button1_Click(object sender, EventArgs e)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_MUTE);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == (Keys.Control | Keys.B)) {
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_VOLUME_MUTE);
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void Form1_Resize_1(object sender, EventArgs e)
{
if (FormWindowState.Minimized == this.WindowState)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(500);
this.Hide();
}
else if (FormWindowState.Normal == this.WindowState)
{
notifyIcon1.Visible = false;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
}
My form is just a test environment, it has 1 button for turn on/off mic, it reads Ctrl+B hotkey to turn on/off mic, and it goes to tray, when minimized.
So, the main point is: I need it to accept Ctrl+B combinaton when my app is minimized and my app mustn't steal focus from program(game), that i'm using in the moment.