Reputation: 11
How can I do a shortcut for a buttons so I can press it if I am in my desktop? I've already tried:
If e.Keycode = Keys.F2 Then
Stopclick.PerformClick()
End if
End Sub
Upvotes: 0
Views: 61
Reputation: 1857
I'm guessing that you mean you want to capture a key press when you minimize to your desktop or use a different program. The term that may help you out in your search is called Global Hotkeys
. Basically what you need to do is register a hotkey globally within Windows so that when your application is minimized or no longer has focus, it is still able to intercept the messages.
You can search Google for '.Net Global Hotkeys'. You can also check out this link: http://www.vbforums.com/showthread.php?672702-Register-Global-HotKeys
If you are simply trying to catch the F2 event on your form, then try the following code:
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData as Windows.Forms.Keys) As Boolean
If keyData = Keys.F5 then
'Take action here
End If
Return MyBase.ProcessCMDKey(msg, keyData)
End Function
Upvotes: 1