Script that moves my cursor in a circle

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fluxilient
Posts: 3
Joined: 03 Dec 2019, 14:44

Script that moves my cursor in a circle

Post by Fluxilient » 03 Dec 2019, 14:54

I needed a certain script. I've tried to fix it for a while. So here's what I need.


Every 3 seconds, it moves my cursor in a circle. Must be accurate without drift. I need it to type this every 300 seconds:

/play skyblock (enter) wait 10 seconds


/WARP island (wait 10 seconds)

[Mod edit: Topic name added.]

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Script that moves my cursor in a circle

Post by swagfag » 03 Dec 2019, 16:33

uve tried to fix it. what is it?
moves my cursor in a circle
mice moving in circles

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 03 Dec 2019, 17:17

Basically does what you want. Modify as needed:

Code: Select all

#Persistent

SetTimer, MoveMouse, 3000
SetTimer, SendText, 300000
return

MoveMouse:
	MoveMouseInCircle(200, 15)
return

SendText:
	SendInput, /play skyblock{Enter}
	Sleep, 10000
	SendInput, /WARP island ; no Enter?
	; don't see what waiting another 10 seconds here is supposed to accomplish. what follows it?
return

MoveMouseInCircle(r := 200, degInc := 5, start := "top", speed := 0)
{
	static radPerDeg := 3.14159265359 / 180

	MouseGetPos, cx, cy
	Switch start
	{
		Case "top":
			angle := 0
			cy += r
		Case "right":
			angle := 90 * radPerDeg
			cx -= r
		Case "bottom":
			angle := 180 * radPerDeg
			cy -= r
		Case "left":
			angle := 270 * radPerDeg
			cx += r
	}
	loop, % 360 / degInc
	{
		angle += degInc * radPerDeg
		MouseMove, cx + r * Sin(angle), cy - r * Cos(angle)
		Sleep, speed
	}
}

Esc::ExitApp
Use AHK version 1.1.31 or later.

Fluxilient
Posts: 3
Joined: 03 Dec 2019, 14:44

Re: Script that moves my cursor in a circle

Post by Fluxilient » 03 Dec 2019, 17:25

Thx ima test it out :

Fluxilient
Posts: 3
Joined: 03 Dec 2019, 14:44

Re: Script that moves my cursor in a circle

Post by Fluxilient » 03 Dec 2019, 17:42

Thanks it works. Anyway to make it run in the background?

And how do I turn ut off?

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 03 Dec 2019, 18:36

Not sure what you mean by running in the background. You won't be able to use the mouse at the same time it's moving it around. You might be able to have it send the text to a background window, but that doesn't work for all windows.

Hit the Escape key to exit the script.

harsimransran
Posts: 4
Joined: 16 Oct 2022, 16:53

Re: Script that moves my cursor in a circle

Post by harsimransran » 16 Oct 2022, 17:51

Hey guys,
I was looking at this script, and it works like a charm, but is what needs to be changed in the hand so that the speed is increased and there is a specific Hotkey to trigger this script, Like F2 to start and F3 to stop, rather than closing the hand.

I'm newbie to AHK and still trying to learn the mechanics.

I appreciate any help you can provide. ^_^

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 16 Oct 2022, 18:41

Since the speed is already maximum, you could make it go faster by increasing the degree increment, which would make it less like a circle because it would have longer and flatter segments.

Starting it with a hotkey would be simple, but stopping it with a hotkey depends on what you would want to do after that. When it’s restarted, would it just complete the circle? Or would you want it to start over?

harsimransran
Posts: 4
Joined: 16 Oct 2022, 16:53

Re: Script that moves my cursor in a circle

Post by harsimransran » 16 Oct 2022, 18:50

boiler wrote:
03 Dec 2019, 17:17
Basically does what you want. Modify as needed:

Code: Select all

#Persistent

SetTimer, MoveMouse, 3000
SetTimer, SendText, 300000
return

MoveMouse:
	MoveMouseInCircle(200, 15)
return

SendText:
	SendInput, /play skyblock{Enter}
	Sleep, 10000
	SendInput, /WARP island ; no Enter?
	; I don't see what waiting another 10 seconds here is supposed to accomplish. what follows it?
return

MoveMouseInCircle(r := 200, degInc := 5, start := "top", speed := 0)
{
	static radPerDeg := 3.14159265359 / 180

	MouseGetPos, cx, cy
	Switch start
	{
		Case "top":
			angle := 0
			cy += r
		Case "right":
			angle := 90 * radPerDeg
			cx -= r
		Case "bottom":
			angle := 180 * radPerDeg
			cy -= r
		Case "left":
			angle := 270 * radPerDeg
			cx += r
	}
	loop, % 360 / degInc
	{
		angle += degInc * radPerDeg
		MouseMove, cx + r * Sin(angle), cy - r * Cos(angle)
		Sleep, speed
	}
}

Esc::ExitApp
Use AHK version 1.1.31 or later.

Hey guys

This script works like a charm, but is there any way we can trigger this script rather than just opening it for it to work? Like using F2 to start and F3 to Stop (replace it with ESC), cause it gives me an error when I add:: to the script for the commands. I appreciate any help you can provide.

harsimransran
Posts: 4
Joined: 16 Oct 2022, 16:53

Re: Script that moves my cursor in a circle

Post by harsimransran » 16 Oct 2022, 18:53

boiler wrote:
16 Oct 2022, 18:41
Since the speed is already maximum, you could make it go faster by increasing the degree increment, which would make it less like a circle because it would have longer and flatter segments.

Starting it with a hotkey would be simple, but stopping it with a hotkey depends on what you would want to do after that. When it’s restarted, would it just complete the circle? Or would you want it to start over?
So for the script, I wanted it go a loop, just make circular rotations. Just need a Hostkey to push the script to start and stop like on wherever the pointer is at.
I hope that makes sense :D

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 16 Oct 2022, 19:13

You still haven't been very specific, but try this. Use the same key (F2) to start and stop.

Code: Select all

Pause
loop
	MoveMouseInCircle(200, 20)
return

F2::Pause
Esc::ExitApp

MoveMouseInCircle(r := 200, degInc := 5, start := "top", speed := 0)
{
	static radPerDeg := 3.14159265359 / 180

	MouseGetPos, cx, cy
	Switch start
	{
		Case "top":
			angle := 0
			cy += r
		Case "right":
			angle := 90 * radPerDeg
			cx -= r
		Case "bottom":
			angle := 180 * radPerDeg
			cy -= r
		Case "left":
			angle := 270 * radPerDeg
			cx += r
	}
	loop, % 360 / degInc
	{
		angle += degInc * radPerDeg
		MouseMove, cx + r * Sin(angle), cy - r * Cos(angle)
		Sleep, speed
	}
}

harsimransran
Posts: 4
Joined: 16 Oct 2022, 16:53

Re: Script that moves my cursor in a circle

Post by harsimransran » 17 Oct 2022, 02:08

Well, this is what I was looking for; I needed the script to use the mouse to move in a circle, and with a hotkey to make to start/pause, you helped it with the F2 key.

Sorry for not being able to share the correct details that you asked for.
Thank you so much.

Bang_Jago
Posts: 4
Joined: 15 May 2021, 00:25

Re: Script that moves my cursor in a circle

Post by Bang_Jago » 23 Feb 2023, 03:57

boiler wrote:
16 Oct 2022, 19:13
You still haven't been very specific, but try this. Use the same key (F2) to start and stop.

Code: Select all

Pause
loop
	MoveMouseInCircle(200, 20)
return

F2::Pause
Esc::ExitApp

MoveMouseInCircle(r := 200, degInc := 5, start := "top", speed := 0)
{
	static radPerDeg := 3.14159265359 / 180

	MouseGetPos, cx, cy
	Switch start
	{
		Case "top":
			angle := 0
			cy += r
		Case "right":
			angle := 90 * radPerDeg
			cx -= r
		Case "bottom":
			angle := 180 * radPerDeg
			cy -= r
		Case "left":
			angle := 270 * radPerDeg
			cx += r
	}
	loop, % 360 / degInc
	{
		angle += degInc * radPerDeg
		MouseMove, cx + r * Sin(angle), cy - r * Cos(angle)
		Sleep, speed
	}
}
how to change the spped mouse? i need it to movee faster

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 23 Feb 2023, 07:53

Try changing the MouseMove line to this:

Code: Select all

		MouseMove, cx + r * Sin(angle), cy - r * Cos(angle), 0

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Script that moves my cursor in a circle

Post by LAPIII » 25 Mar 2023, 21:46

@boiler Your last script causes the cursor to go towards the middle of the canvas, like this:

Untitled_-_Paint 25_03_23 10⦂27⦂52⦂673 PM.jpg
Untitled_-_Paint 25_03_23 10⦂27⦂52⦂673 PM.jpg (73.94 KiB) Viewed 3024 times

Can you change this?

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 25 Mar 2023, 22:24

Please show exactly what code you ran to get that result.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Script that moves my cursor in a circle

Post by LAPIII » 26 Mar 2023, 00:45

I have a Windows 11, possibly MS paint behaves differently than other OSs:

Code: Select all

Pause
loop
	MoveMouseInCircle(200, 20)
return

F2::Pause
Esc::ExitApp

MoveMouseInCircle(r := 200, degInc := 5, start := "top", speed := 0)
{
	static radPerDeg := 3.14159265359 / 180

	MouseGetPos, cx, cy
	Switch start
	{
		Case "top":
			angle := 0
			cy += r
		Case "right":
			angle := 90 * radPerDeg
			cx -= r
		Case "bottom":
			angle := 180 * radPerDeg
			cy -= r
		Case "left":
			angle := 270 * radPerDeg
			cx += r
	}
	loop, % 360 / degInc
	{
		angle += degInc * radPerDeg
		MouseMove, cx + r * Sin(angle), cy - r * Cos(angle)
		Sleep, speed
	}
}

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 26 Mar 2023, 02:38

That doesn’t make any sense to me because it is showing that straight segment coming off what would be the halfway point around the circle. Can you describe where your mouse pointer is when you press the hotkey, then the path it takes as it draws?

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: Script that moves my cursor in a circle

Post by LAPIII » 26 Mar 2023, 02:48

I made an animated gif:
Untitled_-_Paint 26_03_23 03⦂48⦂06⦂169 AM.gif
Untitled_-_Paint 26_03_23 03⦂48⦂06⦂169 AM.gif (826.68 KiB) Viewed 3001 times

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script that moves my cursor in a circle

Post by boiler » 26 Mar 2023, 07:44

It looks like for reasons unrelated to the script, your mouse pointer jumps to a totally different location at various times. Are you pausing the script and then unpausing it after having moved your mouse pointer to a new location and somehow expecting it to continue where it left off? Are you in any way manually moving the mouse pointer while the script is running? Are you touching anything at all once you started the script running? You must at least be holding the left mouse button down to get it to draw, so it seems you may be moving the mouse either inadvertently or on purpose while holding the mouse button down. Are you changing the active window while it is running?

If not the above scenario, do you have any other scripts or applications running that have anything to do with positioning the mouse? Are you using a laptop with a touch screen or touchpad? Does your mouse pointer ever move to another location of the screen at other times instead of slowly moving in a path to a new location? What is your mouse pointing device?

Post Reply

Return to “Ask for Help (v1)”