Jump to content

Hold Mouse Button?


Recommended Posts

This doesn't quite fully work... I am trying to make the mouse automatically click one time a second, but once I hold the mouse button in, it always clicks once a second, even if I let go...

#include "Misc.au3"
$dll = DllOpen("user32.dll")

While 1
    sleep(1000)
    If _IsPressed("01", $dll) then Click()
WEnd

DllClose($dll)

func Click()
    while 1
        MouseClick("primary")
    wend
endfunc
Link to comment
Share on other sites

Try this (untested).

func Click()
    while 1
        If NOT _IsPressed("01", $dll) then exitloop
        MouseClick("primary")
        Sleep(1000)
    wend
endfunc

Edit: Changed the order of calls in the function.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This should work... Hold on...

#include "Misc.au3"
$dll = DllOpen("user32.dll")

While 1
    sleep(1000)
    If _IsPressed("01", $dll) then Click()
WEnd

func Click()
    while 1
        If NOT _IsPressed("01", $dll) then exitloop
        MouseClick("primary")
        Sleep(1000)
    wend
endfunc

DllClose($dll)
Link to comment
Share on other sites

another try then and again untested. You might have to uncomment the MouseUp() line

#include "Misc.au3"
$dll = DllOpen("user32.dll")

While 1
    sleep(1000)
    If _IsPressed("01", $dll) then Click()
WEnd

func Click()
    while _IsPressed("01", $dll)
         MouseClick("primary")
         Sleep(1000)
    wend
    ;MouseUp( "primary" )
endfunc

DllClose($dll)

NM That won't work either because you are trying to click the same button that is already triggering the function(). Using the Right button to trigger the function works

#include "Misc.au3"
$dll = DllOpen("user32.dll")

While 1
    sleep(1000)
    If _IsPressed("02", $dll) then
    If Click() Then ExitLoop
    EndIf
WEnd

func Click()
    while _IsPressed("02", $dll)
         If MouseClick("primary") Then ConsoleWrite("mouse clicked" & @CRLF)
         Sleep(1000)
     wend
     Return 1
endfunc

DllClose($dll)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Amazingly enough it's MouseMove()

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

lol at changing both the mouse buttong on the scipt again :mellow:

Anyway your code works fine with the same button.

#include "Misc.au3"
$dll = DllOpen("user32.dll")

While 1
    sleep(100)
    If _IsPressed("01", $dll) then Click()
WEnd

func Click()
    while _IsPressed("01", $dll)
         Mousemove(700,400,10)
         Sleep(1000)
         Mousemove(600,400,10)
    wend
    ;MouseUp( "primary" )
endfunc

DllClose($dll)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

How can I disable the mouse for the duration of my script, without it being stuck in a forever loop? This is how I plan to disable it:

While
    MouseMove (@DesktopWidth, @DesktopHeight, 0)
Wend

But if I do that, the rest of my script can't run while the mouse is disabled... :mellow:

Link to comment
Share on other sites

How can I disable the mouse for the duration of my script, without it being stuck in a forever loop? This is how I plan to disable it:

While
    MouseMove (@DesktopWidth, @DesktopHeight, 0)
Wend

But if I do that, the rest of my script can't run while the mouse is disabled... :mellow:

Can you explain this question a bit better? I am not entirely sure what you are asking.

For the mouse click script though, I think this should work for you:

#include "Misc.au3"
$dll = DllOpen("user32.dll")

While 1
    Sleep(1000)
    If _IsPressed("01", $dll) Then
        If Click() Then ExitLoop
    EndIf
WEnd

Func Click()
    While _IsPressed("01", $dll)
        MouseUp("primary")
        If MouseDown("primary") Then ConsoleWrite("mouse clicked" & @CRLF)
        Sleep(1000)
    WEnd
    Return 1
EndFunc   ;==>Click

DllClose($dll)

EDIT: Same script as what George gave you, just had to add a mouseup() and change mouseclick() to MouseDown(). When using mouse click, you are telling it to press down and release, so even though you still have the button held down, your script released it. With MouseDown() it never tells it that the button was released. You lifting your finger is the only thing that triggers the release.

Hope that makes sense.

Edited by danwilli
Link to comment
Share on other sites

But then the mouse is not clicking.

he wants to click while he holds the button down, the code that GEO posted does exactly that.

Yes, it IS clicking, did you try it? It clicks.

The one that GEO posted, leaves the loop after ONE click. The one he posted where you hold down the right mouse button to click the left, worked fine, but was not what was requested.

EDIT: HAHA, I guess it would serve a better point when I paste the correct code LOL.

Sorry JohnOne, you are indeed right, that one DOES NOT WORK.

I have edited the previous code to match this as well.

Here is the one I meant to, and thought I did, paste:

#include "Misc.au3"
$dll = DllOpen("user32.dll")

While 1
    Sleep(1000)
    If _IsPressed("01", $dll) Then
        If Click() Then ExitLoop
    EndIf
WEnd

Func Click()
    While _IsPressed("01", $dll)
        MouseUp("primary")
        If MouseDown("primary") Then ConsoleWrite("mouse clicked" & @CRLF)
        Sleep(1000)
    WEnd
    Return 1
EndFunc   ;==>Click

DllClose($dll)
Edited by danwilli
Link to comment
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
 Share

  • Recently Browsing   0 members

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