注册热键在.NET - 三/四个按键组合 [英] Register hotkeys in .NET - combination of three/four keys

查看:198
本文介绍了注册热键在.NET - 三/四个按键组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被卡住了。

现在,我使用下面的code听热键:

  [的DllImport(user32.dll中)
    公共静态的extern BOOL RegisterHotKey(IntPtr的的HWND,
      INT ID,INT fsModifiers,INT VLC);
    [的DllImport(user32.dll中)
    公共静态的extern BOOL UnregisterHotKey(IntPtr的的HWND,INT ID);


    保护覆盖无效的WndProc(参考消息M)
    {
        如果(m.Msg == 0x0312)
        {
            //什么我需要
        }
        base.WndProc(REF米);
    }
 

和这个函数注册热键:

  Form1.RegisterHotKey(this.Handle,this.GetType()GetHash code(),0,(INT)CHR);
 

它完美的作品。 我的问题是我如何注册多个热键相同的组合,例如:

  1. 在A + B + C + D
  2. ALT + SHIFT + B
  3. CTRL + ALT + SHIFT + X

编辑:我发现(如Zooba说的)如何解密的热键被送到这里的解决方案:

 保护覆盖无效的WndProc(参考消息M)
    {
        如果(m.Msg == 0x0312)
        {
            按键键=(密钥)(((INT)m.LParam>> 16)及0xFFFF的);
            ModifierKeys修改=(ModifierKeys)((INT)m.LParam和放大器; 0xFFFF的);
            如果((调整值+++键==ALT + S))
            {
                //做任何我需要的。
            }
        }
        base.WndProc(REF米);
    }
 

解决方案

我找到了答案。而不是使用 registerhotkey ,我用 KeyState ,它解决了我所有的问题。如果有人有兴趣,你可以去这里(<一href="http://web.archive.org/web/20151007163753/http://www.$c$cproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library?msg=3644157"相对=nofollow>备份上archive.org )

I got stuck.

Right now, I am using the following code to listen to hotkeys:

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


    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x0312)
        {
            // whatever i need
        }
        base.WndProc(ref m);
    }

and this function to register hotkey:

Form1.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 0, (int)chr);

it works perfectly. my question is how do I register multiple hotkeys as the same combination, for example:

  1. A+B+C+D
  2. ALT+SHIFT+B
  3. CTRL+ALT+SHIFT+X

edit: I found out (like Zooba said) how to "decrypt" which hotkey was sent and here's the solution:

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x0312)
        {
            Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
            ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF);
            if ((modifier + "+" + key == "Alt+S"))
            {
                //do what ever I need.
            }
        }
        base.WndProc(ref m);
    }

解决方案

I found the answer. Instead of using registerhotkey, I used KeyState and it solved all my problems. If anyone is interested, you can go here (backup on archive.org)

这篇关于注册热键在.NET - 三/四个按键组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆