Need help with a script that records mouse position and moves mouse automatically.

Ask gaming related questions (AHK v1.1 and older)
off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by off » 18 Mar 2023, 18:30

@gyrosav
Its because BlockInput at line 40-42, i put that because as you said, when u accidently moving the cursor when it automaticly moving, it will mess up the progress, you can just remove line 40-42 to fix it
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

gyrosav
Posts: 81
Joined: 30 Dec 2020, 02:48

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by gyrosav » 19 Mar 2023, 04:12

@off

Yes, I love the block input but sometimes it remains blocked forever. I have to open the task manager to end the AHK because it makes everything stop working. I want the block input but can you make it so that it doesn't remain blocked forever?

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by off » 19 Mar 2023, 04:31

@gyrosav
Maybe you need to put line 58 before line 56
The code will be

Code: Select all

BlockInput, Off
BlockInput, MouseMoveOff
BlockInput, Default
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

gyrosav
Posts: 81
Joined: 30 Dec 2020, 02:48

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by gyrosav » 19 Mar 2023, 05:40

@off

hmm i tried this but it locked up my computer. I couldnt do anything. I had to kill the AHK script to get mouse and keyboard working again. Can you take a look?

gyrosav
Posts: 81
Joined: 30 Dec 2020, 02:48

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by gyrosav » 19 Mar 2023, 06:11

@off

I need the block input. without it the script is also erratic. but the block input is 100% sometimes making an error and not stopping the block input. please help! =)

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by off » 19 Mar 2023, 21:03

@gyrosav
Sorry, i cannot reproduce your issue.
This script works perfectly without locking any key, mouse, anything.
viewtopic.php?p=513031#p513031

But yeah, maybe it is caused by different computer
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

gyrosav
Posts: 81
Joined: 30 Dec 2020, 02:48

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by gyrosav » 19 Mar 2023, 22:16

@off

No problem! Thank you sir!!!

gyrosav
Posts: 81
Joined: 30 Dec 2020, 02:48

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by gyrosav » 30 Mar 2023, 06:44

@off

Off, can you take another look? It 100% locks sometimes. It won't let me do anything. I need the block input but is there another way to make it so that it doesn't break the AHK? Mouse clicks or key presses stop working completely forever. The only way to fix it is if I CTRL-ALT-DELETE and end task the AHK. Please help.

Code: Select all

#NoEnv
#KeyHistory
SetBatchLines -1
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance Force

CoordMode, Mouse, Client

Gui, +AlwaysOnTop +ToolWindow
Gui, Font, S8, Verdana
Gui, Add, Text, xm y+10 Section, X: 
Gui, Add, Edit, YS-3 x36 vX Disabled Center

Gui, Add, Text, xm y+10 Section, Y: 
Gui, Add, Edit, YS-3 x36 vY Disabled Center

Gui, Add, Text, xm, Press y to Record
Gui, Add, Text, xm, Press CTRL+v to Replay

Gui, Show,, Mouse Replay

Return

Record:

Return

+c::
+v::
Gui, Submit, NoHide
; MsgBox, %X% %Y%
If (X="") or (Y="")
{
MsgBox, Please record mouse position first.
Return
}
Else
{
	BlockInput, On
	BlockInput, MouseMove
	BlockInput, Mouse
	SendInput, {Click Left 1} ; using SendInput to prevent Clicking with Shift 
	Sleep, 1
	;Click, Left Up ; send mouse button up, to prevent "dragging" mouse move
	;Click, Right Up
	Sleep, 1
	MouseGetPos, SaveX, SaveY ; save current position
	Gui, Submit, NoHide
	;MouseClick, Right, % X, % Y, 1, 1
	MouseMove, %X%, %Y%, 0 ; using Combination from MouseMove and basic Click to improve the restore process
	Click, Right, 1
	Sleep, 1 ; delay between click and restoring position
	MouseMove, %SaveX%, %SaveY%, 0 ; restore position
	Sleep, 1 ; delay before activating mouse input
	BlockInput, MouseMoveOff
	BlockInput, Default
	BlockInput, Off
}
Return

MButton::
	SetTimer, ToolTip, 10
	KeyWait, Lbutton, Down
	MouseGetPos, MouseX, MouseY
	GuiControl,,X, % MouseX
	GuiControl,,Y, % MouseY
	SetTimer, ToolTip, OFF
	ToolTip
Return

ToolTip:
	ToolTip Waiting for click...
Return

GuiClose:
GuiEscape:
	ExitApp
Return

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Need help with a script that records mouse position and moves mouse automatically.

Post by off » 30 Mar 2023, 21:45

@gyrosav
I cant get your issues, perhaps anyone else can help you..
So sorry

Edit :
If i pick the coordinate to be the gui window, it freezes, maybe you can try to send a screenshot or a gif showing your problem..
image.png
image.png (6.34 KiB) Viewed 492 times
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Post Reply

Return to “Gaming Help (v1)”