A simple and lightweight Hot Key UserControl that "enables the user to enter a combination of keystrokes to be used as a hot key". This is a drop-in ready UserControl module that wraps the Hot Key control from Windows' Common Controls Library.
Printable View
A simple and lightweight Hot Key UserControl that "enables the user to enter a combination of keystrokes to be used as a hot key". This is a drop-in ready UserControl module that wraps the Hot Key control from Windows' Common Controls Library.
Hi Bonnie,
Does this pre register (permanently register) the Hot Key, to fire up an EXE in any future session of Windows
or
Does it alert our running application, that the user clicked the hot key ?
Rob
PS I admire your work.
Both the RegisterHotKey function and the WM_SETHOTKEY message require that the application should already be running in order for them to work.
If you want the ability to launch your app via a system-wide hotkey, you could create a shortcut file to your app on either the Desktop or the Start menu and in the shortcut file's Properties dialog box, type in your desired hotkey in the Shortcut key field. Windows Explorer will then register the hotkey for you every time you log on to Windows and launch your app whenever you press the hotkey.
How can I make hotkeys only apply to this program, not global?
You would have to use TranslateAccelerator instead of RegisterHotKey or WM_SETHOTKEY. See About Keyboard Accelerators and Using Keyboard Accelerators for more info. Note that, by default, the VB6 runtime creates a message loop for us. In order to use TranslateAccelerator, you will either need to override the VB6-supplied message loop or insert a call to TranslateAccelerator via a GetMsgProc hook.
If you find that to be too much work, you could "cheat" by simply polling for the hotkey using a timer and then checking for the key combinations via multiple calls to GetKeyState. You won't be able to consume/discard the hotkey though.