save/restore mouse postion issue

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stargate
Posts: 9
Joined: 14 Jun 2019, 08:17

save/restore mouse postion issue

Post by stargate » 20 Nov 2022, 02:15

Hello everyone
simple script save/restore mouse potions with hot key inside a loop when i press F8 to save the mouse position and restore it after 3sec at which location i pressed f8
what i want is to delete the previous saved mouse position after successfully restored , so it doesn't restore the mouse position to same location over and over in the next time inside the loop if i didn't want to press f8 again

Code: Select all

~f8::
MouseGetPos, OrigX, OrigY

sleep 3000 ;3 sec
SetPos:
If GetKeyState("f8")

	SetTimer, SetPos, -5
Else
	Click, %OrigX% %OrigY% Left 0

Return

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: save/restore mouse postion issue

Post by mikeyww » 20 Nov 2022, 05:40

Code: Select all

~F8 Up::
on := False
SoundBeep, 900
Return

~F8::
If on
 Return
on := True
CoordMode, Mouse
MouseGetPos, x, y        ; Save mouse position
SetTimer, Restore, -3000 ; Restore mouse position after elapsed time
SoundBeep, 1500
Return

Restore:
CoordMode, Mouse
MouseMove, x, y
SoundBeep, 1200
Return

stargate
Posts: 9
Joined: 14 Jun 2019, 08:17

Re: save/restore mouse postion issue

Post by stargate » 20 Nov 2022, 09:25

thanks

what if y want the mouse position get restored after a code line in the full script, not by time

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: save/restore mouse postion issue

Post by mikeyww » 20 Nov 2022, 11:50

Code: Select all

F7::Gosub, Restore

~F8 Up::
on := False
SoundBeep, 900
Return

~F8::
If !on {
 on := True
 CoordMode, Mouse
 MouseGetPos, x, y ; Save mouse position
 SoundBeep, 1500
}
Return

Restore:           ; Restore mouse position
CoordMode, Mouse
MouseMove, x, y
SoundBeep, 1200
Return

stargate
Posts: 9
Joined: 14 Jun 2019, 08:17

Re: save/restore mouse postion issue

Post by stargate » 21 Nov 2022, 03:01

thx
still same issue mouse go to old position which i saved in the 1st loop
i want to press f8 once while the sub loop is running to save mouse position > so mouse restored after sub loop ends
and after 1st loops ends out of the infinite loop if i don't want to press f8 the mouse doesn't go the old saving position
from main loop 1
i want to clear the saved mouse position after 1st loop ends from the infinite loop
here is the script the main loop is an infinite loop and inside that a sub loop run for 5sec which the mouse is restored after it ends

Code: Select all


~b::Reload ; hotkey b

~F8 Up::
on := False
Return

~F8::
If !on {
 on := True
 CoordMode, Mouse
 MouseGetPos, x, y ; Save mouse position
}
Return

f::
Loop ; this is the infinite loop
{
InitialTime:=A_TickCount
Loop  ; this is the sub loop
{
Send {RButton}
sleep 250
If (A_TickCount - InitialTime > 5000) 
   Break
}

Restore:           ; Restore mouse position
CoordMode, Mouse
MouseMove, x, y

Sleep 2000
}
return

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: save/restore mouse postion issue

Post by mikeyww » 21 Nov 2022, 07:59

After you restore the mouse position, you can set the x and y variables to null.

stargate
Posts: 9
Joined: 14 Jun 2019, 08:17

Re: save/restore mouse postion issue

Post by stargate » 21 Nov 2022, 08:44

i'm not a coder all i did is just copy paste codes :D
could you type me what is the line will be

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: save/restore mouse postion issue

Post by mikeyww » 21 Nov 2022, 10:02

Code: Select all

x := y := ""

stargate
Posts: 9
Joined: 14 Jun 2019, 08:17

Re: save/restore mouse postion issue

Post by stargate » 30 Nov 2022, 07:46

hi again and ty
i want to add something to the script
along with the mouse movement i want to send a key press after the mouse movement and off course i want them all connected with the previously pressed f8 if =ON
so if f8 is ON
Restore:
CoordMode, Mouse
MouseMove, x, y
and+ press key 3 with sleep amount

how to combine them
so the script doesn't press key 3 if no mouse movement happened

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: save/restore mouse postion issue

Post by mikeyww » 30 Nov 2022, 10:39

With any of the scripts that have been posted, you could put a Send command immediately after the mouse move (on the next line).

stargate
Posts: 9
Joined: 14 Jun 2019, 08:17

Re: save/restore mouse postion issue

Post by stargate » 01 Dec 2022, 13:57

yes i did that but the send button that i want get executed after mouse move whether if f8 is On or off
the mouse move correctly doesn't do anything if i didn't press f8 for save mouse position but on the other hand the send button i want get executed in both ways after mouse move line
i want to send button lets say send {3} only if the mouse movement is restored , and doesn't send 3 if i didn't save mouse position
i want to combine them together on the condition { the mouse movement and send {3}}

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: save/restore mouse postion issue

Post by mikeyww » 01 Dec 2022, 14:37

Code: Select all

#If (x = "")
~F8::
CoordMode, Mouse
MouseGetPos, x, y            ; Save mouse position
ToolTip, (%x%`, %y%)
SoundBeep, 1900
Return
#If

f::
SoundBeep, 1500
Loop {                       ; This is the infinite loop
 end := A_TickCount + 5000
 While (A_TickCount < end) { ; This is the sub loop
  Click, R
  Sleep, 250
 }
 If (x > "") {               ; F8 was pressed,
  CoordMode, Mouse           ;  so restore mouse position
  MouseMove, x, y
  Send abcdefg
  Sleep, 2000
  x := ""
  SoundBeep, 1000
  ToolTip
 }
}

stargate
Posts: 9
Joined: 14 Jun 2019, 08:17

Re: save/restore mouse postion issue

Post by stargate » 02 Dec 2022, 08:17

working perfect now as i wanted to be
ty

Post Reply

Return to “Ask for Help (v1)”