문제

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.

도움이 되었습니까?

해결책 2

Running as an administrator fixed it.

다른 팁

Perhaps you can't pass 0 for the Id param? See the link below, which specifies IDH_ALTTAB, IDH_NEXT, or IDH_PREV. What that corresponds to… I don't know.

http://msdn.microsoft.com/en-us/library/ms997649.aspx#xpvisualstyles_topic3

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top