Interception d'un message hook ...

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Interception d'un message hook ...

Message par Stefou »

Salut à tous 8)

Voila j'aurais besoins de filtrer les événements clavier, sans que les programmes destinataire ne soit prévenu.

Exemple : Je suis sous firefox, j'appuie sur F3, mon prog en pur a le message comme quoi j'ai appuyé sur F3, mais firefox ne l'a pas !

J'ai programmé un hook, mais je ne suis pas sur que cela soit la bonne direction.

Merci pour votre aide.

Hook.dll

Code : Tout sélectionner

ProcedureDLL HookKeyboard(code.l, wParam.l, lParam.l)
  hMyWin = FindWindow_("WindowClass_0","RecupEvent")
  If lParam<0 : type=0 : Else : type=1 : EndIf
  PostMessage_(hMyWin,#WM_USER+5,wParam,type)
  
  ProcedureReturn CallNextHookEx_(@HookKeyboard(), code, wParam, lParam)
EndProcedure
Et le programme de base :

Code : Tout sélectionner

OpenWindow(0, 0, 0, 550, 160,"RecupEvent",  #PB_Window_SystemMenu)
SetWindowState(0,#PB_Window_Minimize)
   
hDLL = OpenLibrary(0, "Hook.dll")
hmyHookHookKeyboard = SetWindowsHookEx_(#WH_KEYBOARD 	, GetProcAddress_(hDLL, "HookKeyboard"), hDLL, 0)

Repeat
  Event=WaitWindowEvent()
  nouvel_entrer=0
  Debug Event
  Select Event
    Case #WM_USER+5
      If EventwParam()=119 ; F8 menu fonction
      Else
        
      action$="Appuye touche"
      If EventlParam()=0 : type$="UP" : Else : type$="DOWN" : EndIf
      action$=LSet(action$,20)+LSet(Str(EventwParam()),10)+LSet(type$,10)
      Debug action$
    EndIf
    
  EndSelect
  
Until GetWindowState(0)<>#PB_Window_Minimize
   

resu2=UnhookWindowsHookEx_(hmyHookHookKeyboard)
   
CloseLibrary(0)
CloseWindow(0)