DLL keylogger

Vous avez développé un logiciel en PureBasic et vous souhaitez le faire connaitre ?
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

DLL keylogger

Message par nico »

A venir, une dll permettant de capturer les touches du clavier!
Dernière modification par nico le dim. 16/mars/2014 21:20, modifié 1 fois.
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: DLL keylogger

Message par Backup »

et la souris ? x,y, et bouton ? ... voir couleur
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: DLL keylogger

Message par nico »

La couleur, c'est un simple GetPixel_(hdc, x, y)

Les boutons de la souris, faut que je regarde ça.
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: DLL keylogger

Message par Backup »

ya Atomo qui avait fait une petit librairie pour la souris :)

Code : Tout sélectionner

;atomo
Enumeration
	#MouseEvent_EventType_LeftClick
	#MouseEvent_EventType_LeftDoubleClick
	#MouseEvent_EventType_LeftButtonPushed
	#MouseEvent_EventType_LeftButtonReleased
	#MouseEvent_EventType_RightClick
	#MouseEvent_EventType_RightDoubleClick
	#MouseEvent_EventType_RightButtonPushed
	#MouseEvent_EventType_RightButtonReleased
	#MouseEvent_EventType_Enter
	#MouseEvent_EventType_Exit
	#MouseEvent_EventType_Drag
	#MouseEvent_EventType_Move
EndEnumeration

Structure MouseEvent_Gadget
	Gadget.i
	GadgetID.i
	MouseHover.b
	Drag.b
	LeftButtonPushed.b
	LeftButtonTimestamp.i
	RightButtonPushed.b
	RightButtonTimestamp.i
EndStructure

Structure MouseEvent_EventStack
	Gadget.i
	EventType.b
EndStructure

Threaded NewList MouseEvent_Gadget.MouseEvent_Gadget()
Threaded NewList MouseEvent_EventStack.MouseEvent_EventStack()

Threaded MouseEvent_MouseX, MouseEvent_MouseY
Threaded MouseEventGadget, MouseEventType

ProcedureDLL isMouseButton(Button)
	CompilerIf #PB_Compiler_OS = #PB_OS_Windows
		If GetAsyncKeyState_(Button) & 32768
			ProcedureReturn #True
		EndIf
	CompilerEndIf
EndProcedure

ProcedureDLL isMouseMoved()
	MouseX = DesktopMouseX() : MouseY = DesktopMouseY()
	If MouseX <> MouseEvent_MouseX Or MouseY <> MouseEvent_MouseY
		MouseEvent_MouseX = MouseX : MouseEvent_MouseY = MouseY
		ProcedureReturn #True
	EndIf
EndProcedure

ProcedureDLL GetObjectFromPosition(x, y)
	CompilerIf #PB_Compiler_OS = #PB_OS_Windows
		ProcedureReturn WindowFromPoint_(y<<32|x)
	CompilerEndIf
EndProcedure

ProcedureDLL SendMouseEvent(Gadget, EventType)
	LastElement(MouseEvent_EventStack())
	AddElement(MouseEvent_EventStack())
	MouseEvent_EventStack()\Gadget = Gadget
	MouseEvent_EventStack()\EventType = EventType
EndProcedure

ProcedureDLL MouseEvent()
	Object = GetObjectFromPosition(DesktopMouseX(), DesktopMouseY())
	isMouseMoved = isMouseMoved()
	
	ForEach MouseEvent_Gadget() 
		;{ Hover
		If MouseEvent_Gadget()\GadgetID = Object
			If MouseEvent_Gadget()\MouseHover = #False
				SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_Enter)
				MouseEvent_Gadget()\MouseHover = #True
				If MouseEvent_Gadget()\LeftButtonPushed = #False
					MouseEvent_Gadget()\LeftButtonPushed = -1
				EndIf
				If MouseEvent_Gadget()\RightButtonPushed = #False
					MouseEvent_Gadget()\RightButtonPushed = -1
				EndIf
			EndIf
			Else
			If MouseEvent_Gadget()\MouseHover = #True
				SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_Exit)
				MouseEvent_Gadget()\MouseHover = #False
			EndIf
		EndIf
		;}
		;{ Left Button
		If isMouseButton(#PB_MouseButton_Left) = #True
			If MouseEvent_Gadget()\MouseHover = #True
				If MouseEvent_Gadget()\LeftButtonPushed = #False
					SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_LeftButtonPushed)
					MouseEvent_Gadget()\LeftButtonPushed = #True
				EndIf
			EndIf
			Else
			If MouseEvent_Gadget()\LeftButtonPushed = #True
				SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_LeftButtonReleased)
				If MouseEvent_Gadget()\MouseHover = #True And MouseEvent_Gadget()\Drag = #False
					If ElapsedMilliseconds()-MouseEvent_Gadget()\LeftButtonTimestamp <= 500
						SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_LeftDoubleClick)
						MouseEvent_Gadget()\LeftButtonTimestamp = 0
						Else
						SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_LeftClick)
						MouseEvent_Gadget()\LeftButtonTimestamp = ElapsedMilliseconds()
					EndIf
				EndIf
				MouseEvent_Gadget()\LeftButtonPushed = #False
				MouseEvent_Gadget()\Drag = #False
				ElseIf MouseEvent_Gadget()\LeftButtonPushed = -1
				MouseEvent_Gadget()\LeftButtonPushed = #False
			EndIf
		EndIf
		;} 
		;{ Right Button
		If isMouseButton(#PB_MouseButton_Right) = #True
			If MouseEvent_Gadget()\MouseHover = #True
				If MouseEvent_Gadget()\RightButtonPushed = #False
					SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_RightButtonPushed)
					MouseEvent_Gadget()\RightButtonPushed = #True
				EndIf
			EndIf
			Else
			If MouseEvent_Gadget()\RightButtonPushed = #True
				SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_RightButtonReleased)
				If MouseEvent_Gadget()\MouseHover = #True
					If ElapsedMilliseconds()-MouseEvent_Gadget()\RightButtonTimestamp <= 500
						SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_RightDoubleClick)
						MouseEvent_Gadget()\RightButtonTimestamp = 0
						Else
						SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_RightClick)
						MouseEvent_Gadget()\RightButtonTimestamp = ElapsedMilliseconds()
					EndIf
				EndIf
				MouseEvent_Gadget()\RightButtonPushed = #False
				ElseIf MouseEvent_Gadget()\RightButtonPushed = -1
				MouseEvent_Gadget()\RightButtonPushed = #False
			EndIf
		EndIf
		;} 
		;{ Movement
		If isMouseMoved = #True
			If MouseEvent_Gadget()\LeftButtonPushed = #True
				SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_Drag)
				MouseEvent_Gadget()\Drag = #True
				Else
				If MouseEvent_Gadget()\MouseHover = #True
					SendMouseEvent(MouseEvent_Gadget()\Gadget, #MouseEvent_EventType_Move)
				EndIf
			EndIf
		EndIf
		;}
	Next
	
	;Get Event
	If ListSize(MouseEvent_EventStack())
		FirstElement(MouseEvent_EventStack())
		MouseEventGadget = MouseEvent_EventStack()\Gadget
		MouseEventType = MouseEvent_EventStack()\EventType
		DeleteElement(MouseEvent_EventStack())
		ProcedureReturn #True
	EndIf
EndProcedure

ProcedureDLL MouseEventGadget()
	ProcedureReturn MouseEventGadget
EndProcedure

ProcedureDLL isMouseEventGadget(Gadget)
	ForEach MouseEvent_Gadget()
		If MouseEvent_Gadget()\Gadget = Gadget
			ProcedureReturn #True
		EndIf
	Next
EndProcedure

ProcedureDLL MouseEventType()
	ProcedureReturn MouseEventType
EndProcedure

ProcedureDLL AddMouseEventGadget(Gadget)
	If isMouseEventGadget(Gadget) = #False
		AddElement(MouseEvent_Gadget())
		MouseEvent_Gadget()\Gadget = Gadget
		MouseEvent_Gadget()\GadgetID = GadgetID(Gadget)
	EndIf
EndProcedure

ProcedureDLL RemoveMouseEventGadget(Gadget)
	ForEach MouseEvent_Gadget()
		If MouseEvent_Gadget()\Gadget = Gadget
			DeleteElement(MouseEvent_Gadget())
			Break
		EndIf
	Next
EndProcedure


; Exemple d'utilisation :
Window = OpenWindow(#PB_Any, 0, 0, 300, 300, "Window", #PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
If Window
	
	ContainerGadget = ContainerGadget(#PB_Any, 50, 50, 200, 200, #PB_Container_Flat)
	SetGadgetColor(ContainerGadget, #PB_Gadget_BackColor, #White)
	AddMouseEventGadget(ContainerGadget)
	CloseGadgetList()
	
	Repeat
		Event = WaitWindowEvent(1)
		MouseEvent = MouseEvent()
		If MouseEvent
			If MouseEventGadget() = ContainerGadget
				Select MouseEventType()
					Case #MouseEvent_EventType_LeftClick
					Debug "LeftClick"
					Case #MouseEvent_EventType_LeftDoubleClick
					Debug "LeftDoubleClick"
					Case #MouseEvent_EventType_LeftButtonPushed
					Debug "LeftButtonPushed"
					Case #MouseEvent_EventType_LeftButtonReleased
					Debug "LeftButtonReleased"
					Case #MouseEvent_EventType_RightClick
					Debug "RightClick"
					Case #MouseEvent_EventType_RightDoubleClick
					Debug "RightDoubleClick"
					Case #MouseEvent_EventType_RightButtonPushed
					Debug "RightButtonPushed"
					Case #MouseEvent_EventType_RightButtonReleased
					Debug "RightButtonReleased"
					Case #MouseEvent_EventType_Enter
					Debug "Enter"
					Case #MouseEvent_EventType_Exit
					Debug "Exit"
					Case #MouseEvent_EventType_Drag
					Debug "Drag"
					Case #MouseEvent_EventType_Move
					Debug "Move"
				EndSelect
			EndIf
		EndIf
	Until event = #PB_Event_CloseWindow
EndIf
; Epb

nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: DLL keylogger

Message par nico »

Je préfère quelque chose comme ça, beaucoup plus court:

Code : Tout sélectionner

Structure MSLLHOOKSTRUCT
  pt.Point
  mouseData.l
  flags.l
  time.l
  ; align.l pour x64
  *dwExtraInfo
EndStructure

#Main = 0

Global HHOOKMouse.i

Procedure LowLevelMouseProc(nCode.l, wParam.i, lParam.i)
  Protected *Pointer.MSLLHOOKSTRUCT, ID.l, Handle.i
  Static MemID.l, Exit.l = 0
  
  If nCode = #HC_ACTION
    *Pointer = lParam
    
    ScreenToClient_(WindowID(#Main), @*Pointer\pt)
    
    Handle = RealChildWindowFromPoint_(WindowID(#Main), *Pointer\pt\x + *Pointer\pt\y << 32)
    
    ID = GetDlgCtrlID_(Handle)
    
    Select wParam 
      Case #WM_MOUSEMOVE
        ;Debug "WM_MOUSEMOVE" 
        If MemID <> ID
          If Exit = 0
            Exit = 1
            Debug "MOUSEMOVE ENTER"
            If ID <> 0
              Debug "Gadget ID = " + Str(ID)
            Else
              Debug "NO Gadget ID"
            EndIf
          Else
            Exit= 0
            Debug "MOUSEMOVE EXIT"
            If ID <> 0
              Debug "Gadget ID = " + Str(ID)
            Else
              Debug "NO Gadget ID"
            EndIf
          EndIf
        EndIf
        MemID = ID
        
      Case #WM_LBUTTONDOWN
        Debug "#WM_LBUTTONDOWN"
        If ID <> 0
          Debug "Gadget ID = " + Str(ID)
        Else
          Debug "NO Gadget ID"
        EndIf
        
      Case #WM_LBUTTONUP
        Debug "#WM_LBUTTONUP"
        If ID <> 0
          Debug "Gadget ID = " + Str(ID)
        Else
          Debug "NO Gadget ID"
        EndIf
        
      Case #WM_RBUTTONDOWN
        Debug "#WM_RBUTTONDOWN"
        If ID <> 0
          Debug "Gadget ID = " + Str(ID)
        Else
          Debug "NO Gadget ID"
        EndIf
        
      Case #WM_RBUTTONUP
        Debug "#WM_RBUTTONUP"
        If ID <> 0
          Debug "Gadget ID = " + Str(ID)
        Else
          Debug "NO Gadget ID"
        EndIf
        
      Case #WM_MBUTTONDOWN
        Debug "#WM_MBUTTONDOWN" 
        If ID <> 0
          Debug "Gadget ID = " + Str(ID)
        Else
          Debug "NO Gadget ID"
        EndIf
        
      Case #WM_MBUTTONUP
        Debug "#WM_MBUTTONUP"
        If ID <> 0
          Debug "Gadget ID = " + Str(ID)
        Else
          Debug "NO Gadget ID"
        EndIf
        
    EndSelect
    MemID = ID
  EndIf
  
  ProcedureReturn CallNextHookEx_(HHOOKMouse, nCode, wParam, lParam)
EndProcedure



If OpenWindow(#Main, 0, 0, 600, 600, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget |#PB_Window_ScreenCentered)
  ; Ne pas commencer l'énumération des gadgets par 0
  EditorGadget(10, 10, 10, 580, 580)
  
  HHOOKMouse = SetWindowsHookEx_(#WH_MOUSE_LL, @LowLevelMouseProc(), GetModuleHandle_(0), 0)
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  
  UnhookWindowsHookEx_(HHOOKLMouse)
EndIf 
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: DLL keylogger

Message par Backup »

Merci pour ce code, je vais regarder ça demain :)
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: DLL keylogger

Message par Mesa »

Je trouve dommage que le code de @nico empêche l'utilisation d'un gadget n°0.

L'adaptation de son code pour lever cette limitation est ici. J'en ai profité pour ajouté l'utilisation de la molette de la souris.

Code : Tout sélectionner

;http://www.purebasic.fr/french/viewtopic.php?f=8&t=14254&view=next
Structure MSLLHOOKSTRUCT
  pt.Point
  mouseData.l
  flags.l
  time.l
  ; align.l pour x64
  *dwExtraInfo
EndStructure


#Main = 10

Global HHOOKMouse.i
Global hWinMain


Procedure LowLevelMouseProc(nCode.l, wParam.i, lParam.i)
  Protected *Pointer.MSLLHOOKSTRUCT, ID.l, Handle.i
  Static  MemID.l, WasOnGadget.l = 0
    
  If nCode < 0  ; préconisé par microsoft
    ProcedureReturn CallNextHookEx_(HHOOKMouse, nCode, wParam, lParam); 
  EndIf
    
  If nCode = #HC_ACTION
    *Pointer = lParam
    ScreenToClient_(WindowID(#Main), @*Pointer\pt)
    Handle = RealChildWindowFromPoint_(WindowID(#Main), *Pointer\pt\x + *Pointer\pt\y << 32)
    
    
    If handle=hWinMain 
      Gadget = #False    
    Else
      Gadget=#True
      ID = GetDlgCtrlID_(Handle)
    EndIf
    
    
    Select wParam 
      Case #WM_MOUSEMOVE
        ;Debug "WM_MOUSEMOVE" 
        
        If Gadget = #False 
        ;Debug "Over Windows #Main"
          
          If WasOnGadget = 1
            Debug "EXIT Gadget ID = " + Str(MemID)
          EndIf
          WasOnGadget=0 
        Else     
          
          
          If WasOnGadget=0 Or MemID<>ID  
            Debug "ENTER Gadget ID = " + Str(ID)
            WasOnGadget=1
            MemID = ID
          Else
            ;Debug "Over Gadget ID = " + Str(ID) 
          EndIf 
          
        EndIf
        
        
        
      Case #WM_LBUTTONDOWN
        Debug "#WM_LBUTTONDOWN"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
      Case #WM_LBUTTONUP
        Debug "#WM_LBUTTONUP"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
        
      Case #WM_RBUTTONDOWN
        Debug "#WM_RBUTTONDOWN"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
      Case #WM_RBUTTONUP
        Debug "#WM_RBUTTONUP"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
        
      Case #WM_MBUTTONDOWN
        Debug "#WM_MBUTTONDOWN" 
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
      Case #WM_MBUTTONUP
        Debug "#WM_MBUTTONUP"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf     
        
      Case #WM_MOUSEWHEEL
        Debug "wheel"
        
        If *Pointer\mouseData >0
          Debug " en avant"
        Else
          Debug " en arrière"
      EndIf
        
    EndSelect
    
  EndIf
  
  
  ProcedureReturn CallNextHookEx_(HHOOKMouse, nCode, wParam, lParam)
EndProcedure



hWinMain=OpenWindow(#Main, 0, 0, 600, 600, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget |#PB_Window_ScreenCentered)

EditorGadget(0, 10, 10, 50, 50)
ButtonGadget(1, 10, 60, 60,30,"ok")
TextGadget(2,10,100,60,30,"texte")

HHOOKMouse = SetWindowsHookEx_(#WH_MOUSE_LL, @LowLevelMouseProc(), GetModuleHandle_(0), 0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

UnhookWindowsHookEx_(HHOOKLMouse)

  ; Attention si la souris sort de la fenêtre ou entre dans la fenêtre un évènement 
  ; ENTER EXIT est lancé

Et si vous voulez la position de la souris sur l'écran ou sur la fenêtre en temps réel + le double clic sur les 3 boutons + la molette alors voir ici :

Code : Tout sélectionner

;http://www.purebasic.fr/french/viewtopic.php?f=8&t=14254&view=next

; Remarque : TODO reste à gérer le cas où la souris est en dehors de la fenêtre

Structure MSLLHOOKSTRUCT
  pt.Point
  mouseData.l
  flags.l
  time.l
  ; align.l pour x64
  *dwExtraInfo
EndStructure


#Main = 10

Global HHOOKMouse.i
;Global hWinMain ;[Edition]  fonctionne en static

Global LastLeftButtonClickTime ; doubleclic

Procedure LowLevelMouseProc(nCode.l, wParam.i, lParam.i)
  Protected *Pointer.MSLLHOOKSTRUCT, ID.l, Handle.i
  Static hWinMain.l, MemID.l, WasOnGadget.l = 0, WasOnWindow.l = 0
  
  
  If nCode < 0  ; préconisé par microsoft
    ProcedureReturn CallNextHookEx_(HHOOKMouse, nCode, wParam, lParam); 
  EndIf
  
  
  If nCode = #HC_ACTION
    *Pointer = lParam
    
    ; Horodatage de l'évènement (peut être static ou protected...)
    ;Chrono = *Pointer\time
    ;Debug Chrono
    
    ; Position de la souris dans l'écran
    ;Debug "MouseX="+Str(*Pointer\pt\x)+ " MouseY="+Str(*Pointer\pt\y)
    
    ;Position de la souris dans la fenêtre #Main 
    ScreenToClient_(WindowID(#Main), @*Pointer\pt)
    ;Debug "MouseX="+Str(*Pointer\pt\x)+ " MouseY="+Str(*Pointer\pt\y)
    
    
    ; Quel gadget ?
    Handle = RealChildWindowFromPoint_(WindowID(#Main), *Pointer\pt\x + *Pointer\pt\y << 32)
    ;Debug Handle
    
    ;     If Handle=0 ; Souris en dehors de la fenêtre
    ;       WasOnWindow=1
    ;     EndIf
    
    
    If handle=hWinMain ; Souris sur la fenêtre mais pas sur un gadget
     ;Debug "window #Main"
      Gadget = #False
      
    Else ; Souris sur un gadget
      Gadget=#True
      ID = GetDlgCtrlID_(Handle)
    EndIf
    
    
    Select wParam 
      Case #WM_MOUSEMOVE
        ;Debug "WM_MOUSEMOVE" 
        
        If Gadget = #False ; Sur la fenêtre
        ;Debug "Over Windows #Main"
          
          If WasOnGadget = 1
            Debug "EXIT Gadget ID = " + Str(MemID)
          EndIf
          WasOnGadget=0 
        Else               ; Sur un gadget
          
          
          If WasOnGadget=0 Or MemID<>ID  
            Debug "ENTER Gadget ID = " + Str(ID)
            WasOnGadget=1
            MemID = ID
          Else
            ;Debug "Over Gadget ID = " + Str(ID) 
          EndIf 
          
        EndIf
        
        
        
      Case #WM_LBUTTONDOWN
        Debug "#WM_LBUTTONDOWN"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
       
        
        ;double clic gauche
        If *Pointer\time < LastLeftButtonClickTime + GetDoubleClickTime_()
          
          Debug "DOUBLE CLIC"
          Select ID
            Case 0
              Debug "DOUBLECLIC SUR EditorGadget ID=0" 
              
            Case 1
              Debug "DOUBLECLIC SUR ButtonGadget ID=1"
              
            Case 2
              Debug "DOUBLECLIC SUR TextGadget ID=2" 
              
          EndSelect          
          
        Else
          LastLeftButtonClickTime = *Pointer\time
        EndIf
      Else 
        Debug "sur Windows #Main"
      EndIf
      
      Case #WM_LBUTTONUP
        Debug "#WM_LBUTTONUP"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
        
      Case #WM_RBUTTONDOWN
        Debug "#WM_RBUTTONDOWN"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        
        ;double clic droit
        ;         If *Pointer\time < LastLeftButtonClickTime + GetDoubleClickTime_()
        ;           
        ;             Debug "DOUBLE CLIC"
        ;             Select ID
        ;               Case 0
        ;                 Debug "DOUBLECLIC SUR EditorGadget 0" 
        ;                 
        ;               Case 1
        ;                 Debug "DOUBLECLIC SUR ButtonGadget 1"
        ;                 
        ;               Case 2
        ;                 Debug "DOUBLECLIC SUR TextGadget 2" 
        ;                 
        ;             EndSelect          
        ;             
        ;             Else
        ;                 LastLeftButtonClickTime = *Pointer\time
        ;               EndIf
        Else 
        Debug "sur Windows #Main"
      EndIf
        
      Case #WM_RBUTTONUP
        Debug "#WM_RBUTTONUP"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
        
      Case #WM_MBUTTONDOWN
        Debug "#WM_MBUTTONDOWN" 
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
       
        ;double clic milieu
        ;         If *Pointer\time < LastLeftButtonClickTime + GetDoubleClickTime_()
        ;           
        ;             Debug "DOUBLE CLIC"
        ;             Select ID
        ;               Case 0
        ;                 Debug "DOUBLECLIC SUR EditorGadget 0" 
        ;                 
        ;               Case 1
        ;                 Debug "DOUBLECLIC SUR ButtonGadget 1"
        ;                 
        ;               Case 2
        ;                 Debug "DOUBLECLIC SUR TextGadget 2" 
        ;                 
        ;             EndSelect          
        ;             
        ;             Else
        ;                 LastLeftButtonClickTime = *Pointer\time
        ;               EndIf
        Else 
        Debug "sur Windows #Main"
      EndIf
        
      Case #WM_MBUTTONUP
        Debug "#WM_MBUTTONUP"
        If Gadget=#True
          Debug "Gadget ID = " + Str(ID)
        Else 
        Debug "sur Windows #Main"
      EndIf
        
        
      Case #WM_MOUSEWHEEL
        Debug "wheel"
        ;Debug *Pointer\mouseData>>16 ; = +/- 120 et jamais 0
        If *Pointer\mouseData >0
          Debug " en avant"
        Else
          Debug " en arrière"
        EndIf
        
    EndSelect
    
  EndIf
  
  
  ProcedureReturn CallNextHookEx_(HHOOKMouse, nCode, wParam, lParam)
EndProcedure



hWinMain=OpenWindow(#Main, 0, 0, 600, 600, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget |#PB_Window_ScreenCentered)

EditorGadget(0, 10, 10, 50, 50)
ButtonGadget(1, 10, 60, 60,30,"ok")
TextGadget(2,10,100,60,30,"texte")

HHOOKMouse = SetWindowsHookEx_(#WH_MOUSE_LL, @LowLevelMouseProc(), GetModuleHandle_(0), 0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

UnhookWindowsHookEx_(HHOOKLMouse)

M.
Répondre