[VB6] Hotkey with CTRL + ALT + F9 ?
Hello! I wonder how im gonna write to make a hotkey! with CTRL ALT F9 buttons!
I dont know how to write the code, also if im gonna write VbKeyCTRL+ALT+F9 or how to do :S
Here's anyway the whole code..
In the forms:
VbKey Code:
Private Sub Form_Load()
Dim ret As Long
bCancel = False
'register the hotkeys
ret = RegisterHotKey(Me.hWnd, &HBFF0&, 0, vbKeyF8)
ret = RegisterHotKey(Me.hWnd, &HBFFF&, 0, vbKeyF9)
'show the form and
Show
'process the Hotkey messages
ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
'disable the hotkeys YOU MUST DO THIS BEFORE PRESSING STOP!
bCancel = True
Call UnregisterHotKey(Me.hWnd, &HBFF0&)
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
And in the module:
VbKey Code:
Option Explicit
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Public bCancel As Boolean
Public Sub ProcessMessages()
Dim Message As Msg
'loop until bCancel is set to True
Do While Not bCancel
'wait for a message
WaitMessage
'check if it's a HOTKEY-message
If PeekMessage(Message, Form1.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
If Message.wParam = &HBFF0& Then
MsgBox "WAAH!"
'let the operating system process other events
DoEvents
Loop
End Sub