Api - Hook - Interception des pressions sur la touche PrtScr (Sous Windows XP -

Cjvg Messages postés 330 Date d'inscription mercredi 6 décembre 2000 Statut Membre Dernière intervention 26 octobre 2017 - 5 avril 2011 à 15:33
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 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

Label1.Caption = "Pressez sur la touche PrtScr"

'*-------------------------------------------------------------------------------------------
Me.ScaleMode = 1
Me.Move (Screen.Width - Me.Width) / 2, 10 + (Screen.Height - Me.Height) / 2
'*-------------------------------------------------------------------------------------------

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

3 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
6 avril 2011 à 12:41
Pourquoi un NOUVEAU hook créé tous les 300 ms ???

ciao...
BruNews, MVP VC++
0
Cjvg Messages postés 330 Date d'inscription mercredi 6 décembre 2000 Statut Membre Dernière intervention 26 octobre 2017
6 avril 2011 à 19:10
Pourquoi un NOUVEAU hook créé tous les 300 ms

Réponse: Ce n'est qu'un EXEMPLE pour présenter le problème.

L'anomalie ne vient pas de là ....................
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
7 avril 2011 à 09:45
voir a utiliser RegisterHotKey
peut être...

Renfield - Admin CodeS-SourceS - MVP Visual Basic & Spécialiste des RegExp
0
Rejoignez-nous