October 22, 2018
Hot Topics:

Create a Hotkey for your Application

  • November 20, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

Add a new form and draw on a command button (cmdEnd). Copy the following code into the form:

Option Explicit

Private Declare Function SendMessage Lib_
  "user32" _
  Alias "SendMessageA"_
  (ByVal hwnd As Long, _
  ByVal wMsg As Long, ByVal wParam_
  As Long, lParam As Long) As Long

Private Const WM_SETHOTKEY = &H32
'// Shift + A
Private Const HK_SHIFTA = &H141
'// Shift * B
Private Const HK_SHIFTB = &H142
'// Control + A
Private Const HK_CONTROLA = &H241
Private Const HK_ALTZ = &H45A

Private Sub cmdEnd_Click()
Unload Me
End Sub

Private Sub Form_Load()
'// Start subclassing the form
Subclass Me.hwnd

'// Assign our hotkey
SendMessage Me.hwnd, WM_SETHOTKEY,_
  HK_ALTZ, 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
'// End subclassing unless you want 
'// abnormal effects on the system
UnSubclass Me.hwnd
End Sub

Page 2 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date