views:

132

answers:

1

I want to set up a global hotkey* in VB6 that listens to the keyboard shortcut Win + O.

I have found heaps of messy examples, but nothing which involves the Windows key.

What's the ideal way to setup hotkeys and how does one include the Windows key as a modifier?

* I'm after a global shortcut. That means I don't have to have the application in focus for it to work.

+1  A: 

RegisterHotKey in the Windows API will allow you to register a global hot key. You will also need to use GlobalAddAtom to obtain a unique hot key identifier. See this link for details.

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)

Then you just need to listen for the WM_HOTKEY message on your window.

bwarner
jay