代码之家  ›  专栏  ›  技术社区  ›  Luke

在Windows中添加全局键盘快捷键的最简单方法是什么?

  •  5
  • Luke  · 技术社区  · 15 年前

    我想让我的应用程序在不运行时检测键盘快捷键,但由于在Windows中似乎没有这样做的功能,合理的回退方法是使用后台进程,而不使用任何监听按键的UI。当应用程序不在.Net的前台时,是否可以监视按键?

    看起来像这样 CodeProject article 有我需要的。

    4 回复  |  直到 15 年前
        1
  •  4
  •   RichieHindle    15 年前

    Windows快捷方式可以有一个相关的热键-右键单击“开始”菜单中的任何程序,转到“属性”,您将看到一个“快捷键”框。Windows将代表您查找该热键,并在看到它时启动您的程序。(我用它来制作 Ctrl+Alt+C 启动计算器。)

    要以编程方式进行设置,请使用 IShellLink

        2
  •  4
  •   Amr Elgarhy    15 年前

    通过调用此API:

    注册热键

    http://msdn.microsoft.com/en-us/library/ms646309.aspx

    http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html

    然后重写此方法“WndProc”以监视按键。

    protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            // let the base class process the message
            base.WndProc(ref m);
    
            // if this is a WM_HOTKEY message, notify the parent object
            const int WM_HOTKEY = 0x312;
            if (m.Msg == WM_HOTKEY) ...............
    

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc(VS.71).aspx

        3
  •  4
  •   Thomas Levesque    9 年前

    This library 它也很好

    编辑:我最近创建了这个库,它使用了不同的方法: NHotkey

        4
  •  3
  •   Marko    15 年前

    没有办法让它成为非侵入性的。

    添加全局键盘快捷键总是很麻烦。如果你必须这样做,确保它是一个选择加入,而不是选择退出功能。