Jump to content

Recommended Posts

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
Link to post
Share on other sites
  • Developers

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

Tnx

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
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.

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.

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?

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.

Link to post
Share on other sites

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
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...