[v2.0-beta.15]: SetMouseDelay() does not work on Win11 Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
jiaojiaodubai23
Posts: 6
Joined: 22 Nov 2022, 04:16

[v2.0-beta.15]: SetMouseDelay() does not work on Win11

Post by jiaojiaodubai23 » 29 Nov 2022, 02:06

[Moderator's note: Topic moved from Bug Reports.]

I use VS Code to write the AHK2 scripts for automatic installation of .exe files on Win11, but SetMouseDelay() does not work here, which leads to poor stability of the script :? .

The following are two demonstration videos I recorded. The mouse has been highlighted by the screen recorder. The frame rate of both videos is 30fps.
[*]In Test1, I let the mouse move randomly in a long enough loop;
[*]In Test2, I copied 1000+rows of MouseMove statements directly.

We can see that the mouse movement speed of Test1 is significantly faster than the preset 2000 milliseconds, while in Test2, the MouseMove of 1000+lines was executed in less than 2 seconds.
Attachments
Test1.zip
Executing MouseMove() in a loop
(594.8 KiB) Downloaded 21 times
Test2.zip
Run MouseMove() more than 1000 times directly
(479.47 KiB) Downloaded 21 times

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2.0-beta.15]: SetMouseDelay() does not work on Win11

Post by lexikos » 29 Nov 2022, 21:26

It do not believe it is possible that SetMouseDelay would fail to work due to a difference in OS.

SetMouseDelay is not intended to have any effect with the SendInput mode. This is probably not clear in the documentation, but is noted.
A short delay (sleep) is done automatically after every mouse movement or click generated by Click and MouseMove/Click/Drag (except for SendInput mode).
By contrast,
Note: SetKeyDelay is not obeyed by SendInput; there is no delay between keystrokes in that mode. This same is true for Send when SendMode Input is in effect.
SendInput is the default mode in v2.

jiaojiaodubai23
Posts: 6
Joined: 22 Nov 2022, 04:16

Re: [v2.0-beta.15]: SetMouseDelay() does not work on Win11

Post by jiaojiaodubai23 » 03 Dec 2022, 20:33

@lexikos
I'm sorry to have noticed your reply so late.
In fact, as a novice in the AHK scripting language, I can only write scripts with the help of reference help documents, so I have already noticed that:
A short delay (sleep) is done automatically after every mouse movement…
Yes, the mouse movement event has a default delay, but this default delay must not be the 2000 ms I specified, right? The problem now is that in my case, even if I set the mouse delay as high as 2000 ms, the mouse movement will not have a significant delay (ideally, it should be 2 seconds apart between its two movement events, which is long enough to be clearly perceived by the naked eye).
In addition, you mentioned SendInput(), which makes me puzzled, because the function I tested does not include SendInput() at all. In the attachment I uploaded, I only tested the behavior of MouseMove().

My test code has been described in the original topic and shown in the attached video. However, to avoid ambiguity, I will attach my code here.

Test1:

Code: Select all

CoordMode("Mouse", "Screen")
SetMouseDelay(2000)
i := 1
while(i < 100000){
    MouseMove(Random(200, 1200), Random(200, 1200))
    i++
}
Test2:

Code: Select all

CoordMode("Mouse", "Screen")
SetMouseDelay(2000)
MouseMove(Random(200, 1200), Random(200, 1200))
MouseMove(Random(200, 1200), Random(200, 1200))
MouseMove(Random(200, 1200), Random(200, 1200))
MouseMove(Random(200, 1200), Random(200, 1200))
MouseMove(Random(200, 1200), Random(200, 1200))
; In the actual test, the statement in the previous line repeated 1000+lines to observe the obvious phenomenon.
; For the sake of presentation, the repeated code of the following hundreds of lines is omitted here.

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2.0-beta.15]: SetMouseDelay() does not work on Win11  Topic is solved

Post by lexikos » 03 Dec 2022, 23:39

Please note the emphasis.
except for SendInput mode
...
This same is true for Send when SendMode Input is in effect.
...
SendInput is the default mode in v2.
Also, in the documentation for MouseMove, which you are directly using:
This function uses the sending method set by SendMode.
Try with SendMode "Event".

jiaojiaodubai23
Posts: 6
Joined: 22 Nov 2022, 04:16

Re: [v2.0-beta.15]: SetMouseDelay() does not work on Win11

Post by jiaojiaodubai23 » 04 Dec 2022, 00:36

lexikos wrote:
03 Dec 2022, 23:39
Please note the emphasis.
except for SendInput mode
...
This same is true for Send when SendMode Input is in effect.
...
SendInput is the default mode in v2.
Also, in the documentation for MouseMove, which you are directly using:
This function uses the sending method set by SendMode.
Try with SendMode "Event".
Thank you for your prompt reply. I carefully read the documentation again and set SendMode to Event. After that, the script ran as scheduled.

Because I used to understand it literally, I mistakenly thought that SendMode only affected Send() series functions. Now that I have realized that this is not a bug, it may be more appropriate to move this topic to the "AutoHotkey>Ask For Help>AutoHotkey v2 Help" section.

You are a dedicated and kind developer. Thank you again.

Post Reply

Return to “Ask for Help (v2)”