Jump to content

MouseProc SetWindowsHookEx failure...


Recommended Posts

Greetings!

I have some serious issues with registering MouseProc with SetWindowsHookEx function...

As long as mouse stays inside the GUI - console returns messages etc. - properly!

But as soon as mouse leaves GUI window - everything stops, no more messages...

Here's the code:

OnAutoItExitRegister('OnAutoItExit')


$hKey_Proc = DllCallbackRegister("MouseProc", "int", "int;ptr;ptr")

$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)

$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", 7, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)

; unlogical!
GUICreate('Test')
GUISetState()

Do
Until GuiGetMsg() = -3
Exit


Func MouseProc($nCode, $wParam, $lParam)
    ConsoleWrite($nCode )

    Switch $wParam
        Case 0x0201
            ConsoleWrite(@CRLF & 'LEFT DOWN' & @CRLF)
        Case 0x0202
            ConsoleWrite(@CRLF & 'LEFT UP' & @CRLF)
        Case 0x0206
            ConsoleWrite(@CRLF & 'RIGHT DOUBLE DOWN' & @CRLF)
        Case 0x020A
            ConsoleWrite(@CRLF & 'WHEEL' & @CRLF)
    EndSwitch

EndFunc

Func OnAutoItExit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
    $hM_Hook[0] = 0
    DllCallbackFree($hKey_Proc)
    $hKey_Proc = 0
EndFunc   ;==>OnAutoItExit

What's wrong? How should it look like to work properly?

Basically, I'd like to create non-Low Level MouseHook for receiving mouse msg just from one window.

Non-Low Levelr = CPU saving purpose. (same code with $WH_LL_MOUSE insetad of $WH_MOUSE [int 7 stands for it] works perfectly... why? :graduated:)

BR, I hope for your help :]

4gr

Edited by 4ggr35510n
Link to comment
Share on other sites

  • 1 month later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...