Page 1 of 1

3-key Hotkey Combination and Suspend Toggling

Posted: 25 Mar 2019, 20:57
by Tigerlily
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=63056
Bpd wrote:
25 Mar 2019, 10:15
I'm having some issues with using the keys LShift + W/1 + 1/W to suspend and resume scripts. See below;

Code: Select all

#if getkeystate("LShift","P")
1 & W::Suspend, Off
W & 1::Suspend, Off
#if

#if getkeystate("LShift","P")
2 & W::Suspend, On
W & 2::Suspend, On
#if
The code mostly works, where after holding down LShift, whichever order 1/2 or W is pressed, the script will suspend or resume.

The situation in which it doesn't work is when you press LShift, then press 1, then press W. It begins to flick between suspend and resume over and over again. This doesn't happen when 2 is pressed or in the reversed orders.

Does this script behave like this for anyone else?
What changes have to be made to have LShift + 1/W + W/1 suspend, but not resume over and over again?
Is there an easier way to have multiple key combinations suspend and resume scripts, if so, how?

Any insight would be greatly appreciated thank you!
LShift + 1 & W::Suspend, Off toggles suspend on AND off. I tried around with LShift + 3 & W, LShift + 5 & W and more similar combos and replicated the same results. I feel this is a bug, maybe something I am missing

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 25 Mar 2019, 22:55
by Bpd
Thanks for posting this here TL! I'll be keeping an eye on this post.

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 27 Mar 2019, 14:49
by Helgef
I don't see any problem on 1.1.30.01 32/64 unicode. 1 & w only sets suspend off, never on, 2 & w only sets suspend on, never off, as to be expected.

Cheers.

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 27 Mar 2019, 16:25
by gregster
I can reproduce the behaviour on 1.1.29.01 (64bit). Once the hotkeys were suspended at least one time, I can toggle the suspension via 1 & W::Suspend, Off while LShift is pressed.

Edit: This surprise toggle is not working, if hotkeys were suspended strictly via the script's context menu (in the systray). Then, the suspension will just be turned off, like expected.

Edit2:
The same behaviour can be observed with this simplified setup:

Code: Select all

1 & w::Suspend, Off
2 & w::Suspend, On

; the same with
2 & w::Suspend, Off		; now this key combo toggles after the first suspension (which was not done via context menu)
1 & w::Suspend, On
while this doesn't show the surprise toggle effect:

Code: Select all

1::Suspend, Off
2::Suspend, On
It seems to be caused by key combos only. If this really doesn't show on [v1.1.30+] it might have somehow to do with the implementation of this change
https://autohotkey.com/docs/commands/Suspend.htm wrote:[v1.1.30+]: The decimal values 1, 0 and -1 may be used in place of On, Off and Toggle, respectively.

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 27 Mar 2019, 20:17
by Tigerlily
gregster wrote:
27 Mar 2019, 16:25
I can reproduce the behaviour on 1.1.29.01 (64bit). Once the hotkeys were suspended at least one time, I can toggle the suspension via 1 & W::Suspend, Off while LShift is pressed.

Edit: This surprise toggle is not working, if hotkeys were suspended strictly via the script's context menu (in the systray). Then, the suspension will just be turned off, like expected.

Edit2:
The same behaviour can be observed with this simplified setup:

Code: Select all

1 & w::Suspend, Off
2 & w::Suspend, On

; the same with
2 & w::Suspend, Off		; now this key combo toggles after the first suspension (which was not done via context menu)
1 & w::Suspend, On
while this doesn't show the surprise toggle effect:

Code: Select all

1::Suspend, Off
2::Suspend, On
It seems to be caused by key combos only. If this really doesn't show on [v1.1.30+] it might have somehow to do with the implementation of this change
https://autohotkey.com/docs/commands/Suspend.htm wrote:[v1.1.30+]: The decimal values 1, 0 and -1 may be used in place of On, Off and Toggle, respectively.
I'm running AHK v1.1.30.01 32/Unicode.
Helgef wrote:
27 Mar 2019, 14:49
I don't see any problem on 1.1.30.01 32/64 unicode. 1 & w only sets suspend off, never on, 2 & w only sets suspend on, never off, as to be expected.

Cheers.


And yes, I forgot to mention that intially the script works, but then after activating Suspend ON with SHIFT+2+w or SHIFT+W+2 (W & 2 or 2 & W) : SHIFT+1+W (1 & W) toggles, while SHIFT+w+1 (W & 1) only turns Suspend OFF

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 27 Mar 2019, 22:16
by Bpd
Thanks for finding!
https://autohotkey.com/docs/commands/Suspend.htm wrote:
[v1.1.30+]: The decimal values 1, 0 and -1 may be used in place of On, Off and Toggle, respectively.
By swapping out 'On' for 1 and 'Off' for 0, it seems to work (on the work PC anyways, will check personal when I'm home).

Code: Select all

#if getkeystate("LShift","P")
1 & W::Suspend, 0
W & 1::Suspend, 0
#if

#if getkeystate("LShift","P")
2 & W::Suspend, 1
W & 2::Suspend, 1
#if
Does this solution work for everyone else also?

Thanks.

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 28 Mar 2019, 00:21
by Tigerlily
Bpd wrote:
27 Mar 2019, 22:16
Thanks for finding!
https://autohotkey.com/docs/commands/Suspend.htm wrote:
[v1.1.30+]: The decimal values 1, 0 and -1 may be used in place of On, Off and Toggle, respectively.
By swapping out 'On' for 1 and 'Off' for 0, it seems to work (on the work PC anyways, will check personal when I'm home).

Code: Select all

#if getkeystate("LShift","P")
1 & W::Suspend, 0
W & 1::Suspend, 0
#if

#if getkeystate("LShift","P")
2 & W::Suspend, 1
W & 2::Suspend, 1
#if
Does this solution work for everyone else also?

Thanks.
Yes, that resolves the issue - nice!

Still curious, why the other param syntax is bugging though..

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 28 Mar 2019, 01:44
by Helgef
Thank you gregster for narrowing it down. I see the behaviour with,

Code: Select all

1 & w::Suspend, Off
2 & w::Suspend, On
on 1.1.30.01.

If you check listlines, you will see that 1 & w actually triggers the 2 & w hotkey when the unexpected behaviour occurs. So clearly there is a bug here.

Cheers.

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 29 Mar 2019, 17:00
by lexikos
This affects all AutoHotkey versions - I tested as far back as v1.0.48.05. It will be fixed. The problem is that we stop tracking the "2" key when it is no longer a prefix key in an active custom combination; i.e. we stop tracking it while it is in the pressed state, and do not reset the state. The workaround is to ensure that the key is always a prefix or suffix key:

Code: Select all

1 & w::Suspend, Off
2 & w::Suspend, On
2 & 2::Suspend, Permit
The hotkey 2 & 2 probably can't ever trigger, but marks the key as both prefix and suffix. 2 & vk07 or ~2 would also work.

Bpd's workaround only appears to work because all of the hotkeys are exempt from Suspend. Any use of Suspend as the first line except Suspend, On (where "On" is literal, not a variable) causes a hotkey to be exempt. This only applies to v1, not v2. So Suspend, 1 is effectively the same as Suspend, Permit followed by Suspend, On.

Re: 3-key Hotkey Combination and Suspend Toggling

Posted: 30 Mar 2019, 04:34
by Tigerlily
Thanks for being so quick and awesome lexikos - thanks all for debugging this!

Cheers.

Re: 3-key Hotkey Combination and Suspend Toggling  Topic is solved

Posted: 21 Apr 2019, 17:48
by lexikos
This was fixed in v1.1.30.02.