简体   繁体   English

RegisterHotkey 仅适用于 WIndows 7,不适用于 XP、服务器 2003

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

I am setting up global shortcut keys in Windows, using the RegisterHotKey method我在 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

The code to process this is:处理这个的代码是:

[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);
    }

On my windows 7 PC this works, but in XP or Windows Server 2003 it does not.在我的 windows 7 PC 上,这是可行的,但在 XP 或 Windows Server 2003 上却不行。 Any ideas where it goes wrong?有什么想法会出错吗?

Looking at the documentation for RegisterHotKey it states that the MOD_NOREPEAT flag is not supported on Vista/XP/2K.查看RegisterHotKey的文档,它指出 Vista/XP/2K 不支持 MOD_NOREPEAT 标志。 I suspect that this is your problem.我怀疑这是你的问题。

You should check the return value which would tell you immediately that something is wrong.您应该检查返回值,它会立即告诉您有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通知图标可以在Windows XP中正常工作,但不能在Windows Server 2003中正常工作 - Notify icon working fine in windows XP but not in windows server 2003 Windows XP / Server 2003 / VS 2010上的CefSharp - CefSharp on Windows XP / Server 2003 / VS 2010 为什么文件夹在Windows XP和Windows Server 2003上被锁定? - Why folders are locked on Windows XP and Windows Server 2003? 应用程序在Windows XP下运行,但不在Server 2003 R2下运行 - Application runs under windows xp but not under server 2003 r2 windows 服务在 windows 7 上工作,但不在 windows 服务器 2003 上 - windows service working on windows 7 but not on windows server 2003 仅在Windows 2003 Server上指定了无效的算法 - Invalid algorithm specified on Windows 2003 Server only WPF应用程序无法在Windows Server 2003/2008中工作 - WPF application not working in windows server 2003/2008 如何在Windows Server 2003和Windows XP中延迟创建的服务? - How can I delay my created service in Windows Server 2003 & Windows XP? 无法在某些Windows XP / Server 2003计算机上建立HTTPS连接 - Can't establish HTTPS connections on some Windows XP/Server 2003 machines 与系统时钟同步运行每一分钟(在Windows Server 2003上不起作用) - run every min in sync with system clock (not working on Windows Server 2003)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM