I'm using the following code to intercept the ALT+TAB key sequence in my c# application.
Some relevant snippets:
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
and
bool ret = RegisterHotKey(this.Handle, 0, MOD_ALT, 0x09);
Console.WriteLine("return value:" + ret);
Console.WriteLine("lasterror=" + Marshal.GetLastWin32Error());
and
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_HOTKEY)
{
MessageBox.Show("Generic hotkey interception");
if (m.WParam.ToInt32() == 0)
{
MessageBox.Show("ALT+TAB intercepted");
}
}
base.WndProc(ref m);
}
Pretty much in the second snippet, ret is false, but when I replace MOD_ALT (which is 0x01) with MOD_SHIFT (0x04), ret becomes true and the hotkey interception works.
I was wondering why this is the case, because the many examples I've seen on the web state that they work.
Running as an administrator fixed it.