Probleme avec l'utilisation des hook

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
lepiaf31
Messages : 510
Inscription : dim. 25/mars/2007 13:44
Localisation : Toulouse, France
Contact :

Probleme avec l'utilisation des hook

Message par lepiaf31 »

Bon alors j'ai un gros probleme: je n'arrive as pas du tout à utiliser les hook

Pour le moment j'essaye juste de récupérer les frappes du clavier mais je n'y arrive pas du tout.

Voila mon code (certainement complètement faux):

Code : Tout sélectionner

Global hHook

Procedure KeyboardProc(nCode.l, wParam.l, lParam.l)
  If nCode >= 0
    PrintN("wparam="+Str(wParam))
    PrintN("lparam="+Str(Param))
  EndIf
  
  ProcedureReturn CallNextHookEx_(hHook, nCode, wParam, lParam)
EndProcedure

Procedure envoi(parametre)
    hHook = SetWindowsHookEx_(#WH_KEYBOARD, @KeyboardProc(), GetModuleHandle_(0), GetCurrentThreadId_())
    PrintN(Str(hHook))
EndProcedure

Quit = 0
OpenConsole()
CreateThread(@envoi(), 0)

Repeat:Until Quit = 1
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

c'est simple le Hook

meme Steven y arrive


Image
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Message par Stefou »

Salut lepiaf !

Pour créer un hook il faut passer par une dll.

Le prog de la 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
A compiler en hook.dll (!!! Choisir Window DLL dans les options de compilation)

Puis ensuite il y a ton programme :

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()
  Select Event
    Case #WM_USER+5
        If EventlParam()=0 : type$="UP" : Else : type$="DOWN" : EndIf
        action$=LSet(action$,20)+LSet(Str(EventwParam()),10)+LSet(type$,10)
        Debug action$

        EndSelect
  
Until GetWindowState(0)<>#PB_Window_Minimize
   

UnhookWindowsHookEx_(hmyHookHookKeyboard)
   
CloseLibrary(0)
CloseWindow(0)
   
   
Et voilà, bon courage
Répondre