使用Windows修饰符设置全局热键

时间:2010-05-04 05:30:10

标签: vb6 shortcut hotkeys

我想在VB6中设置一个全局热键 *,用于侦听键盘快捷键 Win + O

我找到了大量凌乱的例子,但没有任何涉及Windows密钥的内容。

设置热键的理想方法是什么?如何将Windows键作为修饰符包含在内?

* 我追求全球捷径。这意味着我不必专注于应用程序。

1 个答案:

答案 0 :(得分:1)

Windows API中的RegisterHotKey将允许您注册全局热键。您还需要使用GlobalAddAtom来获取唯一的热键标识符。有关详细信息,请参阅this link

Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer

Private Const WM_HOTKEY As Long = &H312
Private Const MOD_WIN          As Long = &H8

  m_lHotkey = GlobalAddAtom("MyHotkey")
  Call RegisterHotKey(Me.hwnd, m_lHotkey, MOD_WIN, vbKeyO)

然后你只需要在你的窗口上监听WM_HOTKEY消息。