[v2] Missing Hotkeys? (SetTimer and rapidly firing hotkeys) Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

[v2] Missing Hotkeys? (SetTimer and rapidly firing hotkeys)

Post by iseahound » 26 Sep 2022, 18:43

I'm not sure how to interpret this behavior:

#1 - Works perfectly. I expect scrolling the mouse wheel to queue and display 1, 2, 3...

Code: Select all

#Requires AutoHotkey v2.0-beta

global internal := 0        ; local copy of external value.

WheelUp:: {
   global internal
   internal := internal + 1
   fn(internal)
}

WheelDown:: {
   global internal
   internal := internal - 1
   fn(internal)
}

fn(value) {
   static log := ""
   log .= value "`n" ;", " %valueRef% "`n"
   Tooltip log
}

MButton:: Reload
Esc:: ExitApp
#2 - I expect the same behavior as above. I've only added a small delay of 100 ms, and wrapped it in SetTimer. But several calls to SetTimer seem to be missing???

Code: Select all

#Requires AutoHotkey v2.0-beta

global internal := 0        ; local copy of external value.

WheelUp:: {
   global internal
   internal := internal + 1
   SetTimer () => fn(internal), -100
}

WheelDown:: {
   global internal
   internal := internal - 1
   SetTimer () => fn(internal), -100
}

fn(value) {
   static log := ""
   log .= value "`n" ;", " %valueRef% "`n"
   Tooltip log
}

MButton:: Reload
Esc:: ExitApp
I am really not sure if this is normal, I don't see why SetTimer causes some calls to be "missed".

EDIT: In #2, when I scroll really fast, it does hit the max hotkeys per interval and show a msgbox asking to continue. But where did their calls to SetTimer go?

EDIT 2:: Seems to be related to () => () syntax. Replaceing it with fn.bind(value) works fine.

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

Re: [v2] Missing Hotkeys? (SetTimer and rapidly firing hotkeys)  Topic is solved

Post by lexikos » 26 Sep 2022, 19:14

If you don't even understand what is happening, why post in Bug Reports? I've moved the topic.

It's not a bug.
Reset: If SetTimer is used on an existing timer, the timer is reset

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: [v2] Missing Hotkeys? (SetTimer and rapidly firing hotkeys)

Post by iseahound » 26 Sep 2022, 19:43

It's not obvious to me that an anonymous function is essentially static and is not dynamically created with each call.

Post Reply

Return to “Ask for Help (v2)”