- Код: Выделить всё
' Module
' - - - - - -
' Код модуля
Option Explicit
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const MOD_WIN = &H8
Private Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = -4
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
Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Long
Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Long) As Long
Public 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
Public hForm As Long
Public OldWndProc As Long
Public hAtom1 As Long
Public hAtom2 As Long
Public dl As Long
Public Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_HOTKEY
If wParam = hAtom1 Then Beep 'Alt+Q
If wParam = hAtom2 Then Form1.Show 'Alt+Win+Z
End Select
WindowProc = CallWindowProc(OldWndProc, hwnd, Msg, wParam, lParam)
End Function
' - - - - - - - - - - - -
' Form
' - - - - - -
' Код формы
Option Explicit
Private Sub Form_Load()
hForm = Form1.hwnd
' Субклассируем Форму (Form1) (Смотрите дополнительно:
' http://pva-land.jino-net.ru/codesvb/037.php
OldWndProc = SetWindowLong(hForm, GWL_WNDPROC, AddressOf WindowProc)
' 1)
' При нажатии комбинации клавиш Alt и Q компьютер
' говорит "Beep"
' 2)
' При нажатии комбинации клавиш Alt, Win (Виндовз) и Z
' на экране появляется Форма (Form1)
' Создаем глобальный атом
hAtom1 = GlobalAddAtom("A:myglobatom1")
' Устанавливаем горячую клавишу (Alt+Q)
dl = RegisterHotKey(hForm, hAtom1, MOD_ALT, vbKeyQ)
hAtom2 = GlobalAddAtom("A:myglobatom2")
dl = RegisterHotKey(hForm, hAtom2, MOD_ALT Or MOD_WIN, vbKeyZ)
End Sub
Private Sub Form_Unload(Cancel As Integer)
dl = SetWindowLong(hForm, GWL_WNDPROC, OldWndProc)
dl = UnregisterHotKey(hForm, hAtom1)
dl = GlobalDeleteAtom(hAtom1)
dl = UnregisterHotKey(hForm, hAtom2)
dl = GlobalDeleteAtom(hAtom2)
End Sub
как можно переделать чтобы можно было использовать клавиши пр. Z+1, Z+X,F+7