script to sleep while mouse moves and I move my scroll wheel

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
genaro
Posts: 45
Joined: 09 Feb 2016, 20:07

script to sleep while mouse moves and I move my scroll wheel

Post by genaro » 21 Jan 2022, 16:13

Can you help me plz with I want a script to sleep while a mouse moves and I move my scroll wheel and the script continues if I don't do it for a second.

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

Re: script to sleep while mouse moves and I move my scroll wheel

Post by boiler » 21 Jan 2022, 21:00

You probably haven't gotten any replies yet because it's very unclear what you are saying. Try restating it in short, separate sentences that describe what you want to happen in a step-by-step manner.

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

Re: script to sleep while mouse moves and I move my scroll wheel

Post by mikeyww » 21 Jan 2022, 21:11

Here is an example of a loop that "stops" when the mouse moves.

Code: Select all

SetTimer, Check, -100
Loop {
 Send x
 Sleep, 100
 Send y
 Sleep, 100
}
Check:
CoordMode, Mouse
MouseGetPos, x1, y1
SetTimer, Check2, -100
Return
Check2:
CoordMode, Mouse
MouseGetPos, x2, y2
If (x2 != x1 || y2 != y1) ; Mouse moved
 Loop {
  MouseGetPos, x1, y1
  Sleep, 100
  MouseGetPos, x2, y2
 } Until (x2 = x1 && y2 = y1)
SetTimer, Check, -100
Return

genaro
Posts: 45
Joined: 09 Feb 2016, 20:07

Re: script to sleep while mouse moves and I move my scroll wheel

Post by genaro » 22 Jan 2022, 00:37

boiler, mikeyww thank you so much guys. In a more clear way: I have a script that does clicks and presses buttons.
at some point of it I want it to pause doing it for 2 seconds until I stop scrolling with mousewheel and moving a wheel (to read my webpage)
after 2 seconds of stopping doing it (I don't move my mousewheel and mouse itself) I want the script to continue doing my clicks that I programmed.
The script is actually going to close the tab that I was reading after that.

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

Re: script to sleep while mouse moves and I move my scroll wheel

Post by boiler » 22 Jan 2022, 05:58

So, you want your script to behave like what mikeyww showed, except you also want the mouse wheel movements to pause what the script would be doing, and you don’t want it to resume after being paused until 2 seconds after you’ve stopped moving the mouse or mouse wheel. Is that correct?

genaro
Posts: 45
Joined: 09 Feb 2016, 20:07

Re: script to sleep while mouse moves and I move my scroll wheel

Post by genaro » 22 Jan 2022, 22:35

boiler wrote:
22 Jan 2022, 05:58
So, you want your script to behave like what mikeyww showed, except you also want the mouse wheel movements to pause what the script would be doing, and you don’t want it to resume after being paused until 2 seconds after you’ve stopped moving the mouse or mouse wheel. Is that correct?
yes

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

Re: script to sleep while mouse moves and I move my scroll wheel

Post by mikeyww » 23 Jan 2022, 08:18

Possibly something like this.

Code: Select all

squelch = 2000
SetTimer, Check, -100
SetTimer, Check3, 100
Loop {
 Send x
 Sleep, 100
 Send y
 Sleep, 100
}
Check:
CoordMode, Mouse
MouseGetPos, x1, y1
SetTimer, Check2, -100
Return

Check2:
CoordMode, Mouse
MouseGetPos, x2, y2
If (x2 != x1 || y2 != y1) { ; Mouse moved
 Loop {
  MouseGetPos, x1, y1
  Sleep, 100
  MouseGetPos, x2, y2
 } Until (x2 = x1 && y2 = y1)
 Sleep, squelch
}
SetTimer, Check, -100
Return

Check3:
While Instr(A_PriorHotkey, "Wheel") && A_TimeSincePriorHotkey < squelch
 Sleep, squelch
~WheelUp::
~WheelDown::Return

Post Reply

Return to “Ask for Help (v1)”