[V2.beta.3] A_TimeSincePriorHotkey not -1 when A_PriorHotkey blank Topic is solved

Report problems with documented functionality
neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

[V2.beta.3] A_TimeSincePriorHotkey not -1 when A_PriorHotkey blank

Post by neogna2 » 11 Dec 2021, 09:06

https://lexikos.github.io/v2/docs/Variables.htm
A_TimeSincePriorHotkey ... It will be -1 whenever A_PriorHotkey is blank.

Code: Select all

a:: MsgBox A_TimeSincePriorHotkey   ;blank, but should be -1 according to doc
b:: MsgBox A_TimeSincePriorHotkey+0 ;"Error:  Expected a Number but got an empty string."
https://github.com/Lexikos/AutoHotkey_L/blob/5d5a569f123f68cbd522d90bf6780f2b3be404af/source/application.cpp#L1065

Filed as bug rather than document improvement because the default value was -1 in v1 and that was useful.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [V2.beta.3] A_TimeSincePriorHotkey not -1 when A_PriorHotkey blank

Post by swagfag » 25 Jan 2022, 05:18

it was changed in a111: "Fixed built-in variables to return numbers as Integer rather than as String."
previously the function was https://github.com/Lexikos/AutoHotkey_L/blob/b31178da2fd65149fc1e3cdb1cf96cbd9fd0ca58/source/script2.cpp#L10541
now the function is https://github.com/Lexikos/AutoHotkey_L/blame/6012f87b817e8823c48608960c37a77e48ca3e74/source/script2.cpp#L10402

i think it was intentional, otherwise lexikos could have easily kept else return -1. so the docs should be changed probably

explain how -1 was useful. its there to signal that there was no prior key. but in v1 nobody ever checked for this and simply ignored it(or they werent even aware of that distinction). now in v2, ure forced to handle it(ure still free to ignore it if u dont care about it, but it now has to be a conscious decision)

Star J
Posts: 1
Joined: 27 Apr 2022, 02:53

Re: [V2.beta.3] A_TimeSincePriorHotkey not -1 when A_PriorHotkey blank

Post by Star J » 27 Apr 2022, 03:17

I agree that the default value of - 1 is better.
At first I thought this value was num type, but using it to calculate would get an error at the beginning
I have to add an "if", which will be meaningless next time

joefiesta
Posts: 494
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: [V2.beta.3] A_TimeSincePriorHotkey not -1 when A_PriorHotkey blank

Post by joefiesta » 02 May 2022, 09:17

I don't use V2. Does this mean the following code, which I do use, fails in V2:

PicHotkeyCt += 1
if (A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 350)
...
; double press (could also be more than 2)

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

Re: [V2.beta.3] A_TimeSincePriorHotkey not -1 when A_PriorHotkey blank  Topic is solved

Post by lexikos » 24 May 2022, 06:04

If you don't treat A_TimeSince' = -1 as a separate condition to A_TimeSince' >= 0, the result will be as though no time has passed since the previous hotkey was pressed. How is that ever useful? Personally, I've never used A_TimeSincePriorHotkey without first consulting A_PriorHotkey, don't think it would be useful to do so, and don't see any rhyme or reason to it returning -1.

The error is was in the outdated documentation.

@joefiesta No. Note the condition "whenever A_PriorHotkey is blank".

neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: [V2.beta.3] A_TimeSincePriorHotkey not -1 when A_PriorHotkey blank

Post by neogna2 » 24 May 2022, 11:22

lexikos wrote:
24 May 2022, 06:04
The error is was in the outdated documentation.
Ok. Similar doc update needed for A_TimeSinceThisHotkey then, because in v2.beta3 its is blank (not -1) if A_ThisHotkey is blank.


Post Reply

Return to “Bug Reports”