Hook clavier

cs_breton51 Messages postés 78 Date d'inscription jeudi 21 avril 2005 Statut Membre Dernière intervention 15 novembre 2018 - 5 déc. 2006 à 20:44
werdDomain Messages postés 60 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 1 novembre 2011 - 7 août 2008 à 22:24
bonjour

je voudrais bloquer la touche windows du clavier
pour ce faire je fait un hook sur le clavier en vb6 je n'est pas de pb je fait
SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardLowLevelProc, App.hInstance, 0&)
et dans la function KeyboardLowLevelProc je test ci la touche est egual a 91(code de la touche windows) ci c'est le cas je renvoi -1

en vb2005 cela ne marche pas du tout voici le code
dans la forme j'ai:

Friend
Class Form1

Inherits System.Windows.Forms.Form

Public hHook
As
Integer

Private
Sub Form1_Load(
ByVal eventSender
As System.Object,
ByVal eventArgs
As System.EventArgs)
Handles
MyBase.Load
 hHook = SetWindowsHookEx(WH_KEYBOARD_LL,
AddressOf KeyboardLowLevelProc,
Me.Handle, vbNull)
End
Sub














Private



Sub
Form1_FormClosed(

ByVal
eventSender

As
System.Object,

ByVal
eventArgs

As
System.Windows.Forms.FormClosedEventArgs)

Handles



Me
.FormClosed
   UnhookWindowsHookEx(hHook)


End



Sub
End



Class

dans le modul j'ai ceci:
Module Module1

Declare
Function CallNextHookEx
Lib
"user32" (
ByVal hHook
As
Integer,
ByVal ncode
As
Integer,
ByVal wParam
As
Integer,
ByRef lParam
As
Integer)
As
Integer
Delegate
Function SubClassProcDelegate(
ByVal idHook
As
Integer,
ByVal wParam
As
Integer,
ByVal lParam
As
Integer)
As
Integer
Public
Declare
Function SetWindowsHookEx
Lib
"user32"
Alias
"SetWindowsHookExA" (
ByVal idHook
As
Integer,
ByVal lpfn
As SubClassProcDelegate,
ByVal hmod
As
Integer,
ByVal dwThreadId
As
Integer)
As
Integer
Declare
Function UnhookWindowsHookEx
Lib
"user32" (
ByVal hHook
As
Integer)
As
Integer
Public
Declare
Sub CopyMemory
Lib
"kernel32"
Alias
"RtlMoveMemory" (
ByRef Destination
As
Object,
ByRef Source
As
Object,
ByVal Length
As
Integer)

Public
Const WH_KEYBOARD_LL
As
Short = 13

Public
Const VK_RWIN
As
Short = &H5Bs

Public
Const VK_LWIN
As
Short = &H5Cs

Public
Structure HOOKSTRUCT

      Dim vkCode
As
Integer
      Dim scanCode
As
Integer
      Dim flags
As
Integer
      Dim time
As
Integer
      Dim dwExtraInfo
As
Integer
End
Structure

Public
Function KeyboardLowLevelProc(
ByVal idHook
As
Integer,
ByVal wParam
As
Integer,
ByVal lParam
As
Integer)
As
Integer
Dim code_touche
As HOOKSTRUCT
' variable pour récupérer le vk code
'si idhook < 0 alors pas de traitement
If idHook < 0
Then
'      appeler le hook suivant
      KeyboardLowLevelProc = CallNextHookEx(Form1.hHook, idHook, wParam, lParam)

Else
      'copie la structure de lParam
      CopyMemory(p, lParam, Len(p))

      If 
code_touche.vkCode = 91
Then
' si la touche est préssée windows
            KeyboardLowLevelProc = -1
' on fait croire au système que la touche n'a pas été pressée
            Exit
Function
' on ne passe pas au hook suivant
      End
If
End
If
'appeler le hook suivant
KeyboardLowLevelProc = CallNextHookEx(Form1.hHook, idHook, wParam, lParam)

End
Function
End
Module

Merci de m'éclérer car la je ne vois pas

2 réponses

ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
6 déc. 2006 à 10:00
0
werdDomain Messages postés 60 Date d'inscription lundi 22 octobre 2007 Statut Membre Dernière intervention 1 novembre 2011
7 août 2008 à 22:24
aussi, une source complete en vb.net d'un hook keybord:


http://pscode.com/vb/scripts/ShowCode.asp?txtCodeId=2971&lngWId=10




pour anulé, dans l'evenement de la source ...
e.handeled = true
0
Rejoignez-nous