Jump to content

Recommended Posts

Posted (edited)

Hi guys, i'm experimenting WinAPI and Set Windows Hook Ex. Everything work as expected except double click:

#include <WindowsConstants.au3>
#include <WinAPI.au3>

HotKeySet("{Esc}", "Cleanup")

Global $hHook, $hStub_KeyProc

_Main()

Func _Main()
    Local $hmod

    $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hmod = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Main
;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS, $X, $Y, $Delta
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
    Switch $wParam
        Case $WM_LBUTTONDBLCLK
            ConsoleWrite("LBUTTONDBLCLK" & @CRLF)
    EndSwitch
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_KeyProc)
    Exit
EndFunc   ;==>Cleanup

I don't see any ConsoleWrite...How i can resolve? Where is my error?

Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted (edited)

I have read now on MSDN this:

Only windows that have the CS_DBLCLKS style can receive WM_LBUTTONDBLCLK messages

 

 

Maybe can be this the problem but i have think an alternative solution, but i need an help ;)

1) Intercept $WM_LBUTTONDOWN and $WM_LBUTTONUP

2) Use TimerInt on LBUTTONDOWN and TimerDiff on LBUTTONUP  for check the millisecond between the press-release

3) Use _WinAPI_GetDoubleClickTime() for check the default time of double click;

Func _WinAPI_GetDoubleClickTime()
    Local $aResult = DllCall("user32.dll", "uint", "GetDoubleClickTime")
    Return $aResult[0]
EndFunc 

4) Mix all and add a Consolewrite("DoubleClick") only if _WinAPI_GetDoubleClickTime() <= TimerDiff and the LBUTTONUP was pressed twice

The problem is with point 4 :D

Thanks for any help

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted (edited)

I'm talking with myselft :D

This is what i have done:

Global $hHook, $hStub_KeyProc, $fDouble = False, $Flag = True, $Click = 0, $Timer
Case $WM_LBUTTONDOWN
            $fDouble = False
            $Click += 1
            If $Click > 2 Then $Click = 1
            If $Click = 1 And $Flag Then
                $Timer = TimerInit()
                $Flag = False
            EndIf
            If $Click = 2 And Not $Flag Then
                If TimerDiff($Timer) <= _WinAPI_GetDoubleClickTime() Then
                    $fDouble = True
                    ConsoleWrite("LBUTTONDBLCLK" & @CRLF)
                EndIf
                $Flag = True
            EndIf
            If $fDouble = False Then ConsoleWrite("LBUTTONDOWN" & @CRLF)

Working fine but have one problem i don't know how to resolve

click + click in timer = WM_LBUTTONDOWN

click + click in timer = WM_LBUTTONDOWN

etc.

But if i make a click and then do nothing ( so not a double click ), then i make clic + click in timer i don't have the ConsoleWrite

I need to do anther click with nothing and then click + click

Hope is clear :D

I'll repeat:

If i make double click in sequence WORK

If i make a click, wait ex. 1 sec and then do a double click NOT WORK

If i make a click, wait ex. 1 sec, another click, then do a double click WORK

The click may not be odd when i need to performe a double click  :D

If someone know what i need to resolve the issue please post. Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

  • Solution
Posted

Try this:

HotKeySet("{Esc}", "_Exit")

Global Const $WH_MOUSE_LL = 14

Global $DblClk_Speed = RegRead("HKCU\Control Panel\Mouse", "DoubleClickSpeed") ;Getting system double click speed
If @error Then $DblClk_Speed = 500

Global $Timer = 0

Global $hKeyProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr")
Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)

Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _
                        "ptr", DllCallbackGetPtr($hKeyProc), "hwnd", $hmod[0], "dword", 0)

While 1
    Sleep(100)
WEnd

Func _Mouse_Handler($nCode, $wParam, $lParam)
    If $nCode < 0 Then
        Local $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "wparam", $wParam, _
                              "lparam", $lParam)
        Return $aRet[0]
    EndIf

    Switch BitAND($WParam, 0xFFFF)
        Case 513 ;Primary Down
            _CheckInterval()
    EndSwitch
EndFunc

Func _CheckInterval()
    If $Timer = 0 Then
        $Timer = TimerInit()
    Else
        If TimerDiff($Timer) <= 500 Then ConsoleWrite("!> Double click" & @LF)
        $Timer = TimerInit()
    EndIf
EndFunc

Func _Exit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0])
    DllCallbackFree($hKeyProc)
    Exit
EndFunc

Regards

Posted

I have complicated things unnecessarily with my flags and click count

I'll use only the _CheckInterval() func. Thanks
 

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...