Page 1 sur 1

Probleme avec l'utilisation des hook

Publié : mer. 20/août/2008 19:55
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

Publié : mer. 20/août/2008 20:30
par jbernard13
c'est simple le Hook

meme Steven y arrive


Image

Publié : jeu. 21/août/2008 6:23
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