1. Create a Hot key class to deal with the hotkey registry and unregistry
Public Class Hotkey
#Region “Declarations – WinAPI, Hotkey constant and Modifier Enum”
Public Declare Function RegisterHotKey Lib“user32” (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Public Declare Function UnregisterHotKey Lib“user32” (ByVal hwnd As IntPtr, ByVal id AsInteger) As Integer
Public Const WM_HOTKEY As Integer = &H312
Public Const VK_F6 As Short = &H75S
Public Const VK_F7 As Short = &H76S
Public Const VK_F8 As Short = &H77S
Public Const VK_F9 As Short = &H78S
Enum KeyModifier
None = 0
Alt = &H1
Control = &H2
Shift = &H4
Winkey = &H8
End Enum
‘This enum is just to make it easier to call the registerHotKey function: The modifier integer codes are replaced by a friendly “Alt”,”Shift” etc.
#End Region
#Region “Hotkey registration, unregistration and handling”
Public Shared Sub registerHotkey(ByRef sourceForm As Form, ByVal triggerKey As String, ByVal modifier As KeyModifier)
RegisterHotKey(sourceForm.Handle, 1, modifier, Asc(triggerKey.ToUpper))
End Sub
Public Shared Sub registerHotkey_VK(ByRef sourceForm As Form, ByVal id As Integer, ByVal vk As Integer, ByVal modifier As KeyModifier)
RegisterHotKey(sourceForm.Handle, id, modifier, vk)
End Sub
Public Shared Sub unregisterHotkeys(ByRef sourceForm As Form)
UnregisterHotKey(sourceForm.Handle, 1)
‘Remember to call unregisterHotkeys() when closing your application.
End Sub
#End Region
End Class
2. Register HotKey in the form to be used
Hotkey.registerHotkey_VK(Me, 1, Hotkey.VK_F6, Hotkey.KeyModifier.Alt + Hotkey.KeyModifier.Control)
Hotkey.registerHotkey_VK(Me, 2, Hotkey.VK_F7, Hotkey.KeyModifier.Alt + Hotkey.KeyModifier.Control)
3. Create an overrided WndProc function to provide the “Hotkey” function
Protected OverridesSub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = Hotkey.WM_HOTKEY Then
If m.WParam = 1 Then
‘Deal with the hotkey Alt + Ctrl + F6
End If
If m.WParam = 2 Then
‘Deal with the hotkey Alt + Ctrl + F7
End If
End If
MyBase.WndProc(m)
End Sub
4. Unregister hotkeys
Hotkey.unregisterHotkeys(Me)
You have a youtube channel?
No. May be in future.
I have to show thanks to this writer for rescuing me from this crisis. Right after looking out throughout the online world and finding strategies which were not powerful, I assumed my entire life was gone. Being alive without the presence of solutions to the issues you’ve sorted out all through the blog post is a critical case, as well as the kind that might have in a negative way affected my career if I had not noticed your web site. Your main training and kindness in handling the whole lot was very helpful. I am not sure what I would’ve done if I had not encountered such a solution like this. I am able to at this time look forward to my future. Thank you very much for your skilled and sensible guide. I will not be reluctant to endorse the website to anybody who needs and wants counselling about this situation.
Some truly nice and utilitarian info on this site, likewise I think the style has got wonderful features.
I think other web site proprietors should take this site as an model, very clean and wonderful user genial style and design, let alone the content. You are an expert in this topic!
I simply could not depart your site prior to suggesting that I actually loved the usual info a person supply in your visitors? Is going to be back steadily to inspect new posts.
Thanks for your posting. What I want to comment on is that when searching for a good internet electronics shop, look for a web page with full information on critical indicators such as the personal privacy statement, protection details, any payment procedures, and various terms along with policies. Generally take time to look into the help as well as FAQ areas to get a superior idea of the way the shop operates, what they can perform for you, and how you can make use of the features.
Keep up the excellent work, I read few content on this web site and I believe that your web blog is rattling interesting and has got bands of excellent info.
Hey, you used to write wonderful, but the last several posts have been kinda boring¡K I miss your tremendous writings. Past few posts are just a bit out of track! come on!
Perfectly written subject matter, regards for selective information .
Hey very nice website!! Man .. Beautiful .. Wonderful .. I’ll bookmark your web site and take the feeds additionally…I’m happy to seek out numerous useful information here in the post, we’d like work out extra strategies in this regard, thanks for sharing.
I have not checked in here for some time because I thought it was getting boring, but the last several posts are good quality so I guess I will add you back to my everyday bloglist. You deserve it my friend 🙂
Very good written information. It will be beneficial to anyone who employess it, including yours truly :). Keep doing what you are doing – looking forward to more posts.
My brother suggested I might like this website. He
was totally right. This post actually made my day. You can not imagine simply how much time I had spent
for this information! Thanks!
Hi, after reading this amazing piece of writing i am as well glad
to share my experience here with friends.
Hello, i think that i saw you visited my blog so i
came to return the favor.I’m trying to find things to improve my website!I suppose its ok to use some of your ideas!!
I am genuinely pleаѕed to glаnce at this weblog рοѕtѕ which carгiеs plenty of hеlpful faсts,
thаnks for pгoνiԁing theѕe data.
Hello there! I simply wish to give you a big thumbs up for your excellent information you’ve got right
here on this post. I’ll be returning to your web site for more soon.