Hot keys when form isn't in focus

Craig

Well-known member
Joined
Oct 15, 2005
Messages
110
Location
United Kingdom
Programming Experience
Beginner
Hi,

I am creating a program where I need it to be able to use hotkeys.
Eg. When I press "ctrl+F1" I need it to run some code whether the form has focus or not.

After searching this forum, I found this thread.
http://www.vbdotnetforums.com/showthread.php?t=7471

However I can't understand the code posted by JohnH (the last post on the thread)

Could anyone either explain to me this code or just show me how I would set the key combination for the hotkey

Thanks!
 
To make it use Ctrl+F1 for hotkey:

in the Win32 class add:
Const VK_F1 As Int32 = &H70

in Sub SetupHotkey you do this for control key and F1 key:
fsModifiers = Win32.HotkeyModifierFlags.MOD_CONTROL
vkey = Win32.VK_F1

in Sub myHotkeyaction you do what you want to have done when user keypress Ctrl+F1
 
Thanks alot! That works perfectly.

However, if i were to want to modify the code so that you would only have to press a function key without pressing control, how would i go about it?

Thanks in advance

EDIT: Also if i wanted to have 2 or more hotkeys, how would i go about that?
 
Last edited:
No modifier:
Not sure if it's allowed, not recommended anyway. You could try Const MOD_UNMODIFIED As Int32 = &H0

More hotkeys:
Add more elements to the AtomIds array and follow the same setup.
- The string you use when assigning a new atom must be unique.
- Register the different hotkeys with each its own AtomId.

As you see, the AtomId is also the id you check for WParam in Sub WndProc to distinguish the different hotkeys. Route to any 'action' sub of your own.

Remember to unregister them all and delete all the atoms on exit.
 
Back
Top