[Resolved][2008]hotkeys the shorter way ?
All the codes to declare 1 single Global hotkey I found are just huge, I mean they are really really long. Isnt there a shorter way to do this? something like this maybe?
Code:
HotKeySet("{F5}", "_testfunc")
Sub _testfunc()
HotKeySet("{F5}") ' unreg hotkey
End Sub
Re: [2008]hotkeys the shorter way ?
ou want a hotkey to work if your application is in focus then your hotkey code will be extremely simple.
If you wnat a global hotkey then you have to use those complicated codes involving windows API.
The following code is as short as i can get to a global hotkey:
Code:
Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Integer = &H312
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Me.Handle.ToInt32, 0, 0, System.Windows.Forms.Keys.F11)'edit this for the hotkey you want
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
'code for if they press hotkey here
Else
End If
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
UnregisterHotKey(Me.Handle.ToInt32, 0)
End Sub