簡體   English   中英

RegisterHotkey 僅適用於 WIndows 7,不適用於 XP、服務器 2003

[英]RegisterHotkey only working in WIndows 7, not in XP, server 2003

我在 Windows 中設置全局快捷鍵,使用 RegisterHotKey 方法

public static int MOD_CONTROL = 0x2;
public static int WM_HOTKEY = 0x312;

RegisterHotKey(this.Handle, 0, MOD_CONTROL | MOD_NOREPEAT, 96); 
// ctrl numpad0

處理這個的代碼是:

[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);            

 protected override void WndProc(ref Message m)
    {

        if (m.Msg == WM_HOTKEY)         
        {
            MessageBox.Show("a hotkey is pressed"); //this also only shows in win7

            if (m.WParam.ToInt32() == 0) //ctrl numpad0
            {
                MessageBox.Show("Hotkey ctrl numpad0 pressed"); 
                // works fine in win7

            }

        }
        base.WndProc(ref m);
    }

在我的 windows 7 PC 上,這是可行的,但在 XP 或 Windows Server 2003 上卻不行。 有什么想法會出錯嗎?

查看RegisterHotKey的文檔,它指出 Vista/XP/2K 不支持 MOD_NOREPEAT 標志。 我懷疑這是你的問題。

您應該檢查返回值,它會立即告訴您有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM