Sign in to follow this  
Followers 0
DesireDenied

_WinAPI_SetWindowHookEx

11 posts in this topic

Can anyone tell me what is wrong with this code?

#include <WinAPI.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
OnAutoItExitRegister("Cleanup")
 
Global $hHook, $hStub_MouseProc
 
_Main()
 
Func _Main()
    $hStub_KeyProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
    $hmod  = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hmod)
    If Not @error Then
        ConsoleWrite( StringFormat("Hook installed [%s]", $hHook) & @CRLF)
    Else
        ConsoleWrite( StringFormat("Error code: %s", @error) & @CRLF)
    EndIf
 
    While 1
        Sleep(10)
    WEnd
EndFunc
 
Func _MouseProc($nCode, $wParam, $lParam)
    ConsoleWrite( StringFormat("nCode=%d\twParam=%08X\tlParam=%08X\n", $wParam, $lParam) )
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc
 
 
Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_MouseProc)
EndFunc   ;==>Cleanup

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Just post your found the solution when you have in stead of reporting it to request deletion.

Tnx

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The problem was:

$hStub_KeyProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")

Now I got another problem. I was trying to block all LMB inputs if TimmerDiff < 50ms but something is still wrong because LMB clicks are still beeing sent.

#include <WinAPI.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
OnAutoItExitRegister("Cleanup")
 
Global $hHook, $hStub_MouseProc, $iTimer = TimerInit()
 
_Main()
 
Func _Main()
    $hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
    $hmod  = _WinAPI_GetModuleHandle(0)
    $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hmod)
    If Not @error Then
        ConsoleWrite( StringFormat("Hook installed [%s]", $hHook) & @CRLF)
    Else
        ConsoleWrite( StringFormat("Error code: %s", @error) & @CRLF)
    EndIf
 
    While 1
        Sleep(10)
    WEnd
EndFunc
 
Func _MouseProc($nCode, $wParam, $lParam)
    Switch $wParam
        Case $WM_LBUTTONDOWN
            If TimerDiff($iTimer) < 50 Then
                BlockInput(1)
                BlockInput(0)
            EndIf
        Case $WM_LBUTTONUP
            $iTimer = TimerInit
    EndSwitch
 
    Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc
 
 
Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hStub_MouseProc)
EndFunc   ;==>Cleanup

Share this post


Link to post
Share on other sites

The problem was:

$hStub_KeyProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")

Now I got another problem. I was trying to block all LMB inputs if TimmerDiff < 50ms but something is still wrong because LMB clicks are still beeing sent.

If you haven't found a solution, it would help a little if you told us what exactly it is you're trying to do.

And what is "LMB"? Left mouse button? Somehow you've managed to make simple thinks very confusing and I'm left wondering how you do it.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

oh, my fault, sorry.

What I am trying to do is to block user from using Left Mouse Button more than ~20x times a second (every 50ms) and to log info if he was trying to do so.


Share this post


Link to post
Share on other sites

BlockInput(1) ; instead of InputBox(1) :P

Thanks for giving a try but this won't work for sure.

By the way, trying to type anything on keyboard, using mouse will be pain in the ass if you run script like this one.

What I need to do is to block left mouse button only if second mouse click was sent in less than 50ms from the first one.

There is no need to block any other key/mouse inputs.


Share this post


Link to post
Share on other sites

BlockInput(1) ; instead of InputBox(1) :P

Thanks for giving a try but this won't work for sure.

By the way, trying to type anything on keyboard, using mouse will be pain in the ass if you run script like this one.

What I need to do is to block left mouse button only if second mouse click was sent in less than 50ms from the first one.

There is no need to block any other key/mouse inputs.

All of a sudden, I can imagine that you are attempting to block automated mouse clicks using another script, who is going to be sending mouse clicks that fast if not a script.

So why not recreate the script that you're using to do that clicking instead?


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

A friend of mine got a problem with his laptop since last storm and power blackout something has happened to his motherboard.

Does not matter if he is using touch pad or a mouse plugged into USB port his laptop is recieving multiple left mouse button clicks, even if you use left mouse button just once.

We were trying to fix the laptop but many different computer/laptop services said they don't really know what is going on.

So I thought I can fix it using autoit by blocking duplicated mouse clicks.

I did some measurements and I have discovered that duplicated mouse clicks are appearing from 3-30 ms after real click.


Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I also had (well, have, if I connect that damn mouse again) a " of problem. I fixed it by getting a new mouse, but until that, I did a lot of googling around and found this ahk script. Under some conditions, it helped a lot.

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

we have already tried like 5 different mouses but the problem is still here.

thanks for your help, once i will get some things done i will take a look on that script.


Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0