CodeItBetter Programming Another VB Programming Blog

How to create an HotKey for your application

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'System & API - How to create an HotKey for your application

Option Explicit
 
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_SETHOTKEY = &H32
Public Const WM_SHOWWINDOW = &H18
Public Const HK_SHIFTA = &H141 'Shift + A
Public Const HK_SHIFTB = &H142 'Shift + B
Public Const HK_CONTROLA = &H241 'Control + A
Public Const HK_ALTZ = &H45A 'Alt + Z

Private Sub Form_Load()
    Dim erg&
    'Lets Notify windows know what Hotkey you want for your app.
    erg& = SendMessage(Me.hwnd, WM_SETHOTKEY, HK_ALTZ, 0)
    If erg& <> 1 Then MsgBox "You need to use another Hotkey", vbOKOnly, "Error"
    erg& = DefWindowProc(Me.hwnd, WM_SHOWWINDOW, 0, 0)
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.