Set global hotkey using Windows modifier

I want to configure the global hotkey * in VB6, which listens for the Win+ key combination O.

I found a bunch of dirty examples, but nothing related to the Windows key.

What is the ideal way to customize hotkeys and how does one of them include a Windows key as a modifier?

* I'm after the global shortcut. This means that I do not need to have the application in focus for it to work.

+3
source share
1 answer

RegisterHotKey in the Windows API allows you to register a global hotkey. You will also need to use GlobalAddAtom to get a unique hotkey identifier. See this link for more 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 to the WM_HOTKEY message in your window.

+1
source

Source: https://habr.com/ru/post/1743920/


All Articles