нашол я в справочнике по API функциям вот такой код
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
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private 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
Private bCancel As Boolean
Private 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, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
'minimize the form
WindowState = vbMinimized
End If
'let the operating system process other events
DoEvents
Loop
End Sub
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim ret As Long
bCancel = False
'register the Ctrl-F hotkey
ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
'show some information
Me.AutoRedraw = True
Me.Print "Press CTRL-F to minimize this form"
'show the form and
Show
'process the Hotkey messages
ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
bCancel = True
'unregister hotkey
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
этот код исправно работает, если-бы не одно НО, у меня не пполучилось переработать его для нескольких HotKey's у кого 6есть предложения на эту тему?
Ну вот, к примеру, мой модуль, только это было давненько, и не ругать меня за его кривость... ок
Option Explicit Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long Private Declare Function GetKeyNameText Lib "user32" Alias "GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal VK As Long) As Long Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Const GWL_WNDPROC As Long = -4
Public Enum gbHotKeyModifiers MOD_ALT = &H1 MOD_CONTROL = &H2 MOD_SHIFT = &H4 MOD_WIN = &H8 End Enum Public Type gbHWHotKeys VK As Integer Shift As gbHotKeyModifiers id As Long End Type Private Const WM_HOTKEY = &H312 Public Const cNone As String = "???" Private OldWndProc2 As Long, hi As Long
Private Function HotKeyWindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long On Error Resume Next HotKeyWindowProc = CallWindowProc(OldWndProc2, hWnd, uMsg, wParam, lParam) If OldWndProc2 = &H0 Then Exit Function
If uMsg = WM_HOTKEY Then If IsFrmLoaded("frmOptions") Then Exit Function For hi = 0 To UBound(HotKeys) If LoWord(wParam) = HotKeys(hi).id Then If HiWord(lParam) = HotKeys(hi).VK And LoWord(lParam) = HotKeys(hi).Shift Then Select Case hi Case Is = 0: Call frmOptions.Show Case Is = 1: frmStatistic.Visible = False: DoEvents: Call VBRasHangUp Case Else If hRasConn And dllSet.OneKeyDH Then If frmStatistic.Label2(3).Caption = ConList(hi - 2) Then _ frmStatistic.Visible = False: _ DoEvents: _ Call VBRasHangUp: _ Exit Function End If
frmStatistic.Label2(0).Caption = 1& frmStatistic.Visible = dllSet.IsWinVis: Call frmStatistic.SetMeOnTop End Select Exit For End If End If Next End If End Function
'??????????? ??????? ??????? Public Function RegHotKey(hWnd As Long, ByVal Modifiers As gbHotKeyModifiers, ByVal VirtKey As Integer) As Long If OldWndProc2 = 0 Then OldWndProc2 = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf HotKeyWindowProc)
RegHotKey = GlobalAddAtom(CStr(Rnd)) '????? ID, ?????????? ?? ???????? If RegisterHotKey(hWnd, RegHotKey, Modifiers, VirtKey) = 0 Then RegHotKey = 0 End Function
'???????? ??????? ??????? Public Function UnRegHotKey(hWnd As Long, ByVal id As Integer, Optional UnSubCass As Boolean = False) As Boolean If UnSubCass Then Call SetWindowLong(hWnd, GWL_WNDPROC, OldWndProc2): OldWndProc2 = 0
If UnregisterHotKey(hWnd, id) = 0 Then Exit Function '??????? Call GlobalDeleteAtom(id) '??????????? UnRegHotKey = True '??????? End Function
Public Function GetHotKeyText(ByVal VK As Integer, Shift As Integer) As String Dim KeyName As String * 256
If Shift Then GetHotKeyText = Choose(Shift, "Shift", "Ctrl", "Shift + Ctrl", "Alt", "Shift + Alt", "Ctrl + Alt", "Shift + Ctrl + Alt") & " + " If VK = 17 Or VK = 16 Or VK = 18 Then Exit Function
GetHotKeyText = GetHotKeyText & Left$(KeyName, GetKeyNameText(ByVal MapVirtualKey(VK, 0) * &H10000, KeyName, 255)) If Len(GetHotKeyText) = 0 Then GetHotKeyText = cNone End Function
Public Function ReModif(ByVal inModif As Long) As Integer On Error Resume Next If inModif Then ReModif = Choose(inModif, &H4, &H2, &H6, &H1, &H5, &H3, &H7, &H8, &HC, &HA, &HE, &H9, &HD, &HB, &HF) End Function
Private Function LoWord(DWord As Long) As Integer LoWord = IIf(DWord And &H8000&, DWord Or &HFFFF0000, DWord And &HFFFF&) End Function
Private Function HiWord(DWord As Long) As Integer HiWord = (DWord And &HFFFF0000) \ &H10000 End Function
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 Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long Private 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 Private bCancel As Boolean Private 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, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then If Message.wParam = 10 Then 'minimize the form WindowState = vbMinimized End If If Message.wParam = 11 Then 'hide the form Me.Hide End If End If 'let the operating system process other events DoEvents Loop End Sub Private Sub Form_Load() 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net Dim ret As Long bCancel = False 'register the Ctrl-F hotkey ret = RegisterHotKey(Me.hWnd, 10, MOD_CONTROL, vbKeyF) 'ðåãåñòðèðóåì åù¸ îäèí õîòêåé íî óæå ñ ïàðàìåòðîì 11 ret = RegisterHotKey(Me.hWnd, 11, MOD_CONTROL, vbKeyQ)
'show some information Me.AutoRedraw = True Me.Print "Press CTRL-F to minimize this form" Me.Print "Press CTRL-Q to hide this form"
'show the form and Show 'process the Hotkey messages ProcessMessages End Sub Private Sub Form_Unload(Cancel As Integer) bCancel = True 'unregister hotkey Call UnregisterHotKey(Me.hWnd, &HBFFF& End Sub