How can I loop two things simultaneously?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fckoffjohn
Posts: 1
Joined: 18 Jan 2020, 21:36

How can I loop two things simultaneously?

18 Jan 2020, 22:53

Hi, I am new to this and having trouble making this loop work.

Code: Select all

toggle := 0

!x::

Loop{
    
	send {s down}
	sleep, 50
	send {s up}
	sleep, 200
	send {RButton}

	}
	
    MouseGetPos, MouseX, MouseY
    if toggle := !toggle
     gosub, MoveTheMouse
    else
     SetTimer, MoveTheMouse, off
    return

    MoveTheMouse:
    MouseMove, 50, %MouseY%
    SetTimer, MoveTheMouse, -5000  ; every 3 seconds 
    MouseMove, %MouseX%, %MouseY%
    return
  {
}
Only the this part of the code is actually happening right now and the mouse position never changes

Code: Select all

send {s down}
	sleep, 50
	send {s up}
	sleep, 200
	send {RButton}
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: How can I loop two things simultaneously?

19 Jan 2020, 11:47

There is a problem with the code, rethink your code structure.

Code: Select all

toggle := 0

!x::

Loop{
    
	send {s down}
	sleep, 50
	send {s up}
	sleep, 200
	send {RButton}

	}	; ----------> Because the loop has no break, It's an endless loop. So when using hotkeys it is always only in this loop.
	
    MouseGetPos, MouseX, MouseY
    if toggle := !toggle	;---------> what is this? if followed by variable assignment?
     gosub, MoveTheMouse
    else
     SetTimer, MoveTheMouse, off
    return

    MoveTheMouse:
    MouseMove, 50, %MouseY%
    SetTimer, MoveTheMouse, -5000  ; every 3 seconds 
    MouseMove, %MouseX%, %MouseY%
    return
  {	;-------------> and what is  this? blocks without code
}
return	;-------------> Hotkey missing return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 87 guests