Jump to content

Accelerating mouse


Cue
 Share

Recommended Posts

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

Link to comment
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...

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

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