Timer during mouse movement in event mode

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Wintermute
Posts: 2
Joined: 05 Jun 2023, 11:26

Timer during mouse movement in event mode

Post by Wintermute » 05 Jun 2023, 11:56

Hi, I'm new to the ahk community, and I couldn't find an answer to this posted online.

I'm wondering if it's possible to have a timer, that doesn't "pause" during non-instant mouse movement in SendEvent mode.
In the following code for example I would expect the count in tooltip to keep increasing during the mouse movement after "q" is pressed.

Code: Select all

#SingleInstance, Force
SendMode Event
SetWorkingDir, %A_ScriptDir%

SetTimer, Tick, 100

Tick()
{
    static count := 0
    ToolTip % count++
}

q::
MouseMove, 200, 200, 100
Ty in advance :D .

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

Re: Timer during mouse movement in event mode

Post by mikeyww » 05 Jun 2023, 12:11

Welcome to this AutoHotkey forum!

I believe that an individual command would need to finish its execution before a timed loop could continue to the next iteration or command. One workaround could be to break your mouse move into multiple steps or segments that are executed in a loop.

Multithreading (e.g., AHK_H) or multiple scripts could provide additional solutions.

Code: Select all

#Requires AutoHotkey v1.1.33
segments := 50
x2       := 200
y2       := 200
SetTimer tick, 100

q::
MouseGetPos x1, y1
xdif := (x2 - x1) / segments
ydif := (y2 - y1) / segments
Loop % segments
 MouseMove xdif, ydif,, R
MouseMove x2, y2
Return

tick() {
 Static count := 0
 ToolTip % count++
}

Wintermute
Posts: 2
Joined: 05 Jun 2023, 11:26

Re: Timer during mouse movement in event mode

Post by Wintermute » 05 Jun 2023, 12:48

Tnx for the help. I ended up with this:

Code: Select all

;...
myMouseMove(x, y, speed){
    segments := 100
    MouseGetPos, xpos, ypos
    difx := (x - xpos)/segments
    dify := (y - ypos)/segments
    i := 0
    loop, %segments%
    {
        i++
        MouseMove, xpos + difx*i, ypos + dify*i, speed
    }
}
Is there any official documentation on running multiple threads, all I could find is: https://www.autohotkey.com/docs/v1/misc/Threads.htm, which only describes normal blocking functions.

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

Re: Timer during mouse movement in event mode

Post by mikeyww » 05 Jun 2023, 13:13

Look for AHK_H on the Web site.

Post Reply

Return to “Ask for Help (v1)”