[TuT]How to Register a HotKey
Add this right after "Public Class Form1"
Code:
Public Const MOD_ALT As Integer = &H1 'Alt key
Public Const WM_HOTKEY As Integer = &H312
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 As Integer) As Integer
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
Dim id As IntPtr = m.WParam
Select Case (id.ToString)
Case "9"
'Code here
End Select
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
Call UnregisterHotKey(Me.Handle, 9)
Call UnregisterHotKey(Me.Handle, 10)
End Sub
Add this to the Form Loading
Code:
Call RegisterHotKey(Me.Handle, 9, MOD_ALT, Keys.C)
'Replace Keys.C with the Hotkey you want
The hotkey
will work even if form isnt in focus, aka it will work ingame.