Sign in to follow this  
Followers 0
Cue

Accelerating mouse

8 posts in this topic

I have a problem which keeps reoccurring (no pun intended). I Need to figure out a way to exit a previous function call and start it again. Ive searched the forums far and wide and though the question has come up alot i cannot find a definite answer.

code for an accelerating mouse

Dim $MouseStep=0
$Keys2Set=StringSplit('{UP},{RIGHT},{DOWN},{LEFT}',',')

for $i=1 to 4
    HotKeySet($Keys2Set[$i],"Control_Mouse")
Next

while 1
WEnd

Func Control_Mouse()
    $MouseStep+=1
    
    Switch @HotKeyPressed
        Case $Keys2Set[1]
            MouseMove(MouseGetPos(0),MouseGetPos(1)-$MouseStep,0);up
        Case $Keys2Set[2]
            MouseMove(MouseGetPos(0)+$MouseStep,MouseGetPos(1),0);right
        Case $Keys2Set[3]
            MouseMove(MouseGetPos(0),MouseGetPos(1)+$MouseStep,0);down
        Case $Keys2Set[4]
            MouseMove(MouseGetPos(0)-$MouseStep,MouseGetPos(1),0);left
    EndSwitch

    Do
        $g = $MouseStep
        Sleep(100)
    until $g == $MouseStep
    
    $MouseStep=0
    Return 0
EndFunc

The problem with this code and many of my previous codes is that it is recurrsive which is a big problem.

My previous post which is related:

http://www.autoitscript.com/forum/index.ph...mp;#entry253581

even though the recurrsion limit of Autoit is fairly high

MAXEXECUTERECURSE 384

I need to figure out a way to avoid it. So if there is anyone with good programming practice please can you give me some advice for this kind of senario

Other posts

http://www.autoitscript.com/forum/index.ph...mp;hl=Recursion

http://www.autoitscript.com/forum/index.ph...mp;hl=Recursion

Share this post


Link to post
Share on other sites



I have a problem which keeps reoccurring (no pun intended).

Good thing you said "no pun intended" there, otherwise people might get the impression that... that... wait, where was the pun again?

Anyway, try this maybe?

HotKeySet("{UP}", "MoveUp")
HotKeySet("{Down}", "MoveDwn")
HotKeySet("{Left}", "MoveLft")
HotKeySet("{Right}", "MoveRt")
HotKeySet("{End}", "LClick")
HotKeySet("{PgDn}", "RClick")

Global $Speed = 10

While 1
    Sleep(10000)
WEnd

Func MoveUp()
    $Pos = MouseGetPos()
    MouseMove($Pos[0], $Pos[1]-$Speed, 1)
EndFunc

Func MoveDwn()
    $Pos = MouseGetPos()
    MouseMove($Pos[0], $Pos[1]+$Speed, 1)
EndFunc

Func MoveLft()
    $Pos = MouseGetPos()
    MouseMove($Pos[0]-$Speed, $Pos[1], 1)
EndFunc

Func MoveRt()
    $Pos = MouseGetPos()
    MouseMove($Pos[0]+$Speed, $Pos[1], 1)
EndFunc

Func LClick()
    MouseClick("Left")
EndFunc

Func RClick()
    MouseClick("Right")
EndFunc

one of the first scripts I made...

Share this post


Link to post
Share on other sites

Thanks Paulie I was begginig to think this was going to be another post that will get buried without a reply. Is there a way to make the mouse accelerate using your code like the one i posted without getting a stack overflow problem.

Share this post


Link to post
Share on other sites

Where was the pun?

Share this post


Link to post
Share on other sites

lol, I dont even know anymore. it was 4 am when i posted that and for some reason I thought reoccurring and recursion were similiar things. Lame i know :whistle:

Share this post


Link to post
Share on other sites

maybe...

Dim $MouseStep = 0
$Keys2Set = StringSplit('{UP},{RIGHT},{DOWN},{LEFT},{F9},{ESC}', ',')

For $i = 1 To $Keys2Set[0]
    HotKeySet($Keys2Set[$i], "Control_Mouse")
Next

While 1
    Sleep(10)
WEnd

Func Control_Mouse()
    $MouseStep += 1
    $Mpos = MouseGetPos()
    $XMove = 0
    $YMove = 0
    
    Switch @HotKeyPressed
        Case $Keys2Set[1]
            $YMove = -1
        Case $Keys2Set[2]
            $XMove = 1
        Case $Keys2Set[3]
            $YMove = 1
        Case $Keys2Set[4]
            $XMove = -1
        Case $Keys2Set[5]
            $MouseStep = 0
            Return
        Case $Keys2Set[6]
            Exit
    EndSwitch
    
    For $x = 1 To $MouseStep
        MouseMove($Mpos[0] + $XMove, $Mpos[1] + $YMove, 0)
        $XMove += $XMove
        $YMove += $YMove
        Sleep(100)
    Next
    
EndFunc   ;==>Control_Mouse

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Hi Valuator, that code also suffurs from recursion and it seems to make the cursor behave very odd. :whistle:

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Dim $MouseStep=0
$Keys2Set=StringSplit('{UP},{RIGHT},{DOWN},{LEFT}',',')

for $i=1 to 4
    HotKeySet($Keys2Set[$i],"Control_Mouse")
Next

while 1
WEnd

Func Control_Mouse()
    $MouseStep+=1
   
    Switch @HotKeyPressed
        Case $Keys2Set[1]
            MouseMove(MouseGetPos(0),MouseGetPos(1)-$MouseStep,0);up
        Case $Keys2Set[2]
            MouseMove(MouseGetPos(0)+$MouseStep,MouseGetPos(1),0);right
        Case $Keys2Set[3]
            MouseMove(MouseGetPos(0),MouseGetPos(1)+$MouseStep,0);down
        Case $Keys2Set[4]
            MouseMove(MouseGetPos(0)-$MouseStep,MouseGetPos(1),0);left
    EndSwitch

    Sleep(100)
   
    $MouseStep=0
    Return 0
EndFunc

right I simple got rid of the do...until. to be honest i dont even know why i added it in the first place. i think the time i write it was an importatnt factor again

Edited by Cue

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