Mouse Hook to capture Left Double Click

Just starting out? Need help? Post your questions and find answers here.
eJan
Enthusiast
Enthusiast
Posts: 365
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Mouse Hook to capture Left Double Click

Post by eJan »

Hi, i'm using this method to capture mouse clicks inside DVBViewer window, i'd like to change the position of Viewer window with Left Mouse Double Click, but can't find any solution.

Code: Select all

; Fluid Byte: http://www.purebasic.fr/english/viewtopic.php?p=236663#p236663

Procedure MouseHook(nCode, wParam, lParam)

  If wParam = #WM_LBUTTONDOWN
    SetGadgetText(0, "Left Mouse Clicked")
  EndIf

  If wParam = #WM_MBUTTONDOWN
    SetGadgetText(0, "Middle Mouse Clicked")
    ;ProcedureReturn 1
  EndIf

  ProcedureReturn CallNextHookEx_(0, nCode, wParam, lParam)
EndProcedure

OpenWindow(0, 0, 0, 240, 140, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 180, 20, "")

hhkLLMouse = SetWindowsHookEx_(#WH_MOUSE_LL, @MouseHook(), GetModuleHandle_(0), 0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

UnhookWindowsHookEx_(hhkLLMouse)
Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Mouse Hook to capture Left Double Click

Post by Dude »

What about if wParam = #WM_LBUTTONDBLCLK ? I haven't tried it. Put it before the other #LBUTTON messages so it gets checked first.
eJan
Enthusiast
Enthusiast
Posts: 365
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: Mouse Hook to capture Left Double Click

Post by eJan »

As MSDN says: https://msdn.microsoft.com/en-us/librar ... s.85).aspx
The identifier of the mouse message. This parameter can be one of the following messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_RBUTTONDOWN, or WM_RBUTTONUP.
I have tried before, unfortunatelly i can't use WinCallback, because the click to capture is outside PB Window.
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Mouse Hook to capture Left Double Click

Post by RASHAD »

Hi

Code: Select all

; Fluid Byte: http://www.purebasic.fr/english/viewtopic.php?p=236663#p236663
Global oTime

Procedure MouseHook(nCode, wParam, lParam)
  Select wParam
      
    Case #WM_LBUTTONDOWN
        If GetTickCount_() < (oTime + GetDoubleClickTime_())
          SetGadgetText(0, "Left Mouse DblClicked")
          MoveWindow_(WindowID(0),100,100,240,140,1)
        Else
           SetGadgetText(0, "Left Mouse Clicked")
        EndIf
        oTime = GetTickCount_()
      
    Case  #WM_MBUTTONDOWN
        SetGadgetText(0, "Middle Mouse Clicked")

  EndSelect
  ProcedureReturn CallNextHookEx_(0, nCode, wParam, lParam)
EndProcedure

OpenWindow(0, 0, 0, 240, 140, "Mouse Hook", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 180, 20, "")

hhkLLMouse = SetWindowsHookEx_(#WH_MOUSE_LL, @MouseHook(), GetModuleHandle_(0), 0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

UnhookWindowsHookEx_(hhkLLMouse)
Egypt my love
eJan
Enthusiast
Enthusiast
Posts: 365
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: Mouse Hook to capture Left Double Click

Post by eJan »

That did the trick, thanks RASHAD.
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Mouse Hook to capture Left Double Click

Post by RASHAD »

You are welcome :)
Egypt my love
Post Reply