Api - Hook - Interception des pressions sur la touche PrtScr (Sous Windows XP -
Cjvg
Messages postés330Date d'inscriptionmercredi 6 décembre 2000StatutMembreDernière intervention26 octobre 2017
-
5 avril 2011 à 15:33
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 2021
-
7 avril 2011 à 09:45
Bonjour,
Impossible d'enregistrer l'exemple ci-dessous dans les Sources Vb France ?.......
Cet extrait de projet doit permettre d'intercepter les pressions sur la touche Prtscr (Utilisation Hook - GetKeyState).
Cet exemple exécuté sous l'éditeur Visual Basic fonctionne correctement.
Une fois compilé, le Projet.exe n'intercepte plus les pressions sur la touche Prtscr.?.....
Par avance merci.
--------------------------------------------------------------------------------------------
**-Dans une Form-**
Option Explicit
Private Sub Form_Load()
Me.Caption = App.EXEName
Timer1.Interval = 300
Timer1.Enabled = True
End Sub
' Hook - Appel de la procédure de détection des pressions sur la touche PrtScr '
Private Sub Timer1_Timer()
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf ProcClavier, App.hInstance, App.ThreadID)
End Sub
' Fin de travail '
Private Sub Picture1_Click()
UnhookWindowsHookEx hHook
End
End Sub
**-Dans un module-**
Option Explicit
Public Const WH_KEYBOARD = 2
Public Const VK_PRINTSCREEN = &H2C
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
'--------------------------------------------------------------------------------------------
' Procédure de détection des pressions sur les touches du Clavier (Hook) '
Public Function ProcClavier(ByVal Parm As Long, ByVal ParmOut As Long, ByVal ParmIn As Long) As Long
If Parm < 0 Then
ProcClavier = CallNextHookEx(hHook, Parm, ParmOut, ByVal ParmIn)
Exit Function
End If
If (GetKeyState(VK_PRINTSCREEN) And &HF0000000) Then
MsgBox "PrintScreen Pressée"
End If
ProcClavier = CallNextHookEx(hHook, Parm, ParmOut, ByVal ParmIn)
End Function