Cela peut vous donner le vertige, mais tant que vous connaissez les connaissances VB et que vous voulez cette chose, vous devez l'étudier attentivement.
modHook.bas
Option explicite
Fonction de déclaration publique CallNextHookEx Lib user32.dll (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lparam As Any) As Long
Public Declare Sub CopyMemory Lib kernel32 Alias RtlMoveMemory (lpDest As Any, lpSource As Any, ByVal cBytes As Long)
Public Declare Sub keybd_event Lib user32 (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Données publiques () sous forme de chaîne
NUM public aussi longtemps
Public OldHook aussi longtemps
LngClsPtr public aussi longtemps
Fonction publique BackHook (ByVal nCode As Long, ByVal wParam As Long, ByVal lparam As Long) As Long
Si nCode < 0 Alors
BackHook = CallNextHookEx (OldHook, nCode, wParam, lparam)
Fonction de sortie
Fin si
ResolvePointer(LngClsPtr).RiseEvent (lparam)
Appelez CallNextHookEx (OldHook, nCode, wParam, lparam)
Fonction de fin
Fonction privée ResolvePointer (ByVal lpObj As Long) comme ClsHook
Dim oSH comme ClsHook
CopieMémoire oSH, lpObj, 4&
Définir ResolvePointer = oSH
Copier la mémoire oSH, 0&, 4&
Fonction de fin
ClsHook.cls
Option explicite
Événement public KeyDown (KeyCode en tant qu'entier, Shift en tant qu'entier)
Type privé EVENTMSG
wMsg aussi longtemps
lParamLow tant que
lParamHigh tant que
msgTime aussi longtemps
hWndMsg aussi longtemps
Type de fin
Const privé WH_JOURNALRECORD = 0
Const privée WM_KEYDOWN = &H100
Fonction de déclaration privée SetWindowsHookEx Lib user32.dll Alias SetWindowsHookExA (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Fonction de déclaration privée UnhookWindowsHookEx Lib user32.dll (ByVal hHook As Long) As Long
Fonction de déclaration privée GetAsyncKeyState Lib user32.dll (ByVal vKey As Long) sous forme d'entier
Sous-ensemble public SetHook()
OldHook = SetWindowsHookEx (WH_JOURNALRECORD, AddressOf BackHook, App.hInstance, 0)
Fin du sous-marin
Décrochage du sous-marin public()
Appeler UnhookWindowsHookEx (OldHook)
Fin du sous-marin
Fonction amie RiseEvent (ByVal lparam As Long) As Long
Dim Msg comme EVENTMSG
Dim IntShift comme entier
Dim IntCode comme entier
CopierMemory Msg, ByVal lparam, Len(Msg)
IntShift = 0
Sélectionnez Case Msg.wMsg
Cas WM_KEYDOWN
Si GetAsyncKeyState(vbKeyShift) Alors IntShift = (IntShift ou 1)
Si GetAsyncKeyState(vbKeyControl) Alors IntShift = (IntShift ou 2)
Si GetAsyncKeyState(vbKeyMenu) Alors IntShift = (IntShift ou 4)
IntCode = Msg.lParamLow et &HFF
Debug.Print Msg.lParamLow
Débogage.Impression &HFF
RaiseEvent KeyDown (IntCode, IntShift)
Fin de la sélection
Fonction de fin
Sous-classe privée_Initialize()
LngClsPtr = ObjPtr(Moi)
Fin du sous-marin
form1.frm
Option explicite
Dim WithEvents Hook comme ClsHook
Fonction de déclaration privée MapVirtualKeyEx Lib user32 Alias MapVirtualKeyExA (ByVal uCode As Long, ByVal uMapType As Long, ByVal dwhkl As Long) As Long
Fonction de déclaration privée GetKeyboardLayout Lib user32 (ByVal dwLayout As Long) As Long
Fonction de déclaration privée GetForegroundWindow Lib user32 () As Long
Fonction de déclaration privée GetWindowThreadProcessId Lib user32 (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Sous-privé Hook_KeyDown (KeyCode en tant qu'entier, Shift en tant qu'entier)
DimStrCodeAsString
StrCode = CodeVersChaîne (CodeClé)
Si StrCode = [Shift] Ou StrCode = [Alt] Ou StrCode = [Ctrl] Alors
Si Shift = vbAltMask + vbCtrlMask Alors StrCode = [Alt + Ctrl]
Si Shift = vbAltMask + vbShiftMask Alors StrCode = [Alt + Shift]
Si Shift = vbCtrlMask + vbShiftMask Alors StrCode = [Ctrl + Shift]
Si Shift = vbCtrlMask + vbShiftMask + vbAltMask Alors StrCode = [Ctrl + Shift + Alt]
Autre
Si Shift = vbShiftMask Alors StrCode = [Shift] + & StrCode
Si Shift = vbCtrlMask Alors StrCode = [Ctrl] + & StrCode
Si Shift = vbAltMask Alors StrCode = [Alt] + & StrCode
Si Shift = vbAltMask + vbCtrlMask Alors StrCode = [Alt + Ctrl] + & StrCode
Si Shift = vbAltMask + vbShiftMask Alors StrCode = [Alt + Shift] + & StrCode
Si Shift = vbCtrlMask + vbShiftMask Alors StrCode = [Ctrl + Shift] + & StrCode
Si Shift = vbCtrlMask + vbShiftMask + vbAltMask Alors StrCode = [Ctrl + Shift + Alt] + & StrCode
Fin si
Si LCase(StrCode) = LCase(HotKey) Then ' Cette section est une fonction simple après le clavier HOOK, qui consiste à masquer et afficher la fenêtre de départ.
Si App.TaskVisible = False Alors
Moi.Afficher
App.TaskVisible = Vrai
Autre
Moi.Masquer
App.TaskVisible = Faux
Fin si
Fin si
Fin du sous-marin
Fonction privée CodeToString (nCode As Integer) As String
DimStrKeyAsString
Sélectionnez le cas nCode
Cas vbKeyBack : StrKey = BackSpace
Cas vbKeyTab : StrKey = Tab
Cas vbKeyClear : StrKey = Clear
Cas vbKeyReturn : StrKey = Entrée
Cas vbKeyShift : StrKey = Shift
Cas vbKeyControl : StrKey = Ctrl
Cas vbKeyMenu : StrKey = Alt
Cas vbKeyPause : StrKey = Pause
Cas vbKeyCapital : StrKey = CapsLock
Cas vbKeyEscape : StrKey = ESC
Cas vbKeySpace : StrKey = ESPACE
Cas vbKeyPageUp : StrKey = PAGE UP
Cas vbKeyPageDown : StrKey = PAGE DOWN
Cas vbKeyEnd : StrKey = END
Cas vbKeyHome : StrKey = HOME
Cas vbKeyLeft : StrKey = FLÈCHE GAUCHE
Cas vbKeyUp : StrKey = FLÈCHE VERS LE HAUT
Cas vbKeyRight : StrKey = FLÈCHE DROITE
Cas vbKeyDown : StrKey = FLÈCHE VERS LE BAS
Cas vbKeySelect : StrKey = SELECT
Cas vbKeyPrint : StrKey = IMPRIMER ÉCRAN
Cas vbKeyExecute : StrKey = EXECUTE
Cas vbKeySnapshot : StrKey = SNAPSHOT
Cas vbKeyInsert : StrKey = INS
Cas vbKeyDelete : StrKey = DEL
Cas vbKeyHelp : StrKey = AIDE
Cas vbKeyNumlock : StrKey = NUM LOCK
Cas vbKey0 à vbKey9 : StrKey = Chr$(nCode)
Cas vbKeyA à vbKeyZ : StrKey = LCase(Chr$(nCode)) 'MapVirtualKeyEx(nCode, 2, GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, 0))))
Cas vbKeyF1 à vbKeyF16 : StrKey = F & CStr(nCode - 111)
Cas vbKeyNumpad0 à vbKeyNumpad9 : StrKey = Numpad & CStr(nCode - 96)
Cas vbKeyMultiply : StrKey = Pavé numérique {*}
Cas vbKeyAdd : StrKey = Pavé numérique {+}
Cas vbKeySeparator : StrKey = Pavé numérique {ENTER}
Cas vbKeySubtract : StrKey = Pavé numérique {-}
Cas vbKeyDecimal : StrKey = Pavé numérique {.}
Cas vbKeyDivide : StrKey = Pavé numérique {/}
Autre cas
StrKey = Chr$(MapVirtualKeyEx(nCode, 2, GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, 0)))) & Str(MapVirtualKeyEx(nCode, 2, GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, 0))))
Fin de la sélection
CodeVersChaîne = [ & CléStre & ]
Fonction de fin