is there anything wrong with this script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zxibs
Posts: 3
Joined: 21 Sep 2021, 08:05

is there anything wrong with this script?

21 Sep 2021, 19:34

i just wanna try moving the mouse left and right smoothly 7 times using send mode input

Code: Select all

SendMode Input
1::a
2::d

direction := true
Rcount := 0
Lcount := 0
Dcount := 0

c::
Loop
 {
   if direction
     {
       direction = false
       Loop
         {
           Lcount = Lcount - 1
           MouseMove, %Lcount%, 0, 0, R 
           Sleep, 25
         } Until Lcount = -150
       Dcount = Dcount + 1
     }
   else if (direction = false)
     {
       direction = true
       Loop
         {
           Rcount = Rcount + 1
           MouseMove, %Rcount%, 0, 0, R 
           Sleep, 25
         } Until Rcount = 150
       Dcount = Dcount + 1
     }
 } until Dcount = 7
return
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: is there anything wrong with this script?

21 Sep 2021, 20:24

If the script works, then there is nothing wrong with it. Lines 5-8 are unreachable and will never execute. You can prove that by inserting some additional display or MsgBox lines there.

If "direction" is null, then it is neither "true" nor "false". Case in point:

Code: Select all

2::d

direction := false

c::
If (direction = false)
 Send x
Return
Explained: auto-execute
zxibs
Posts: 3
Joined: 21 Sep 2021, 08:05

Re: is there anything wrong with this script?

21 Sep 2021, 23:42

mikeyww wrote:
21 Sep 2021, 20:24
If the script works, then there is nothing wrong with it. Lines 5-8 are unreachable and will never execute. You can prove that by inserting some additional display or MsgBox lines there.

If "direction" is null, then it is neither "true" nor "false". Case in point:

Code: Select all

2::d

direction := false

c::
If (direction = false)
 Send x
Return
Explained: auto-execute
yeah the loop works but it doesn't move my mouse
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: is there anything wrong with this script?

22 Sep 2021, 00:36

Hallo,
is this how it should work?:

Code: Select all

SendMode Input
direction := true
Dcount := 0
Return
1::a
2::d
c::
Loop
{
	if direction
	{
		direction := false
		Lcount := 0
		Loop
		{
			Lcount := Lcount - 1
			MouseMove, -1, 0, 0 , R
			Sleep, 25
		}
		Until Lcount = -150
		Dcount := Dcount + 1
	}
	else if (direction = false)
	{
		direction := true
		Rcount := 0
		Loop
		{
			Rcount := Rcount + 1
			MouseMove, 1, 0, 0, R
			Sleep, 25
		}
		Until Rcount = 150
		Dcount := Dcount + 1
	}
}
until Dcount = 7
return
zxibs
Posts: 3
Joined: 21 Sep 2021, 08:05

Re: is there anything wrong with this script?

22 Sep 2021, 02:59

it finally worked here's the script

Code: Select all

SendMode Input
direction := true
Rcount := 0
Lcount := 0
Dcount := 0
return

c::
Loop
 {
   if direction
     {
       Loop
         {
           Lcount := Lcount - 1
           MouseMove, %Lcount%, 0, 0, R 
           Sleep, 25
         } Until Lcount = -25
       Lcount := 0
       Dcount := Dcount + 1
       direction := false
     }
   else if (direction = false)
     {
       Loop
         {
           Rcount := Rcount + 1
           MouseMove, %Rcount%, 0, 0, R 
           Sleep, 25
         } Until Rcount = 25
       Rcount := 0
       Dcount := Dcount + 1
       direction := true
     }
 } until Dcount = 7

Rcount := 0
Lcount := 0
Dcount := 0
direction := true

return

1::a
2::d

^E::ExitApp
Last edited by jNizM on 22 Sep 2021, 03:15, edited 1 time in total.
Reason: added code tags
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: is there anything wrong with this script?

23 Sep 2021, 02:26

Just a suggestion. Use A_Index

Code: Select all

SendMode Input
direction := true
return

c::
Loop, 7 ;Dcount
{
	if direction
	{
		Loop, 25 ;Lcount
		{
			MouseMove, -A_Index, 0, 0, R
			Sleep, 25
		}
	}
	else
	{
		Loop, 25 ;Rcount
		{
			MouseMove, A_Index, 0, 0, R
			Sleep, 25
		}
	}
	direction := !direction
}
direction := true
return

1::a
2::d

^E::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jeves and 155 guests