a hierarch of presession ?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
fizzle6325
Posts: 12
Joined: 06 Jul 2023, 21:50

a hierarch of presession ?

Post by fizzle6325 » 23 May 2024, 17:33

there are explanations of what takes precedence (order of operations) between threads in the help file. I have a script that has timers but they behave erratically. maybe more so with the hotif command.

but the timers used in the functions seem to bleed thru to other hotkeys if they are done to quick, and by quick i mean a few seconds, but with the cpu speed theses days im surprised some logic is ignored.

it usually isnt much of a bother so i should probably quit my complaining. after all AHK does a fine job to give us more control of our environment. am i missing something ? perhaps a 'wait command'?
im sure we can all agree that waiting sux. i would rather wait then sleep an 'More time then needed amount if time" . is there a feed back cue i'm missing to see?

here is a for instance:

Code: Select all

if not KeyWait('RButton', 'T0.5') {
is there a way to stop this timer if a different condition has already been reached ?

because it's bleeding over to other hot key routines.
if there was a sorta map on what the priories of treads i could navigate this loosely coupled language better.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: a hierarch of presession ?

Post by mikeyww » 23 May 2024, 18:53

Hello,

KeyWait with a timeout will wait for the timeout or the wait condition to be met, whichever comes first. With default thread priorities, a triggered hotkey interrupts other threads unless the other thread uses an uninterruptible statement. An interrupted thread resumes when the interrupting thread ends. Suggestions are below.
  1. Post the script that does not work.
  2. Describe what the script does when you run it.
  3. Describe what the script should do, step by step. If possible, include a detailed example.
If you are waiting for a key to be released or something else to happen, you might want to use a different approach. One option is adding a key-up hotkey that then does what you want when the key is released. That hotkey can check to see if something else has happened.

A demonstration is below.

Code: Select all

#Requires AutoHotkey v2.0
timer := 0

F2 Up:: {              ; F2 = Start to wait for RButton to be released, or F3 to be pressed
 Global timer
 SetTimer wait, timer := -500
 SoundBeep 1500
}

#HotIf timer                                ; Hotkeys are active only when timer is running
~RButton Up::
F3:: {
 Global timer
 SetTimer wait, timer := 0                  ; Stop the timer
 MsgBox ThisHotkey, 'First action', 'Iconi' ; Show which hotkey was triggered
}
#HotIf

wait() {                                    ; Timer expired before a hotkey was triggered
 Global timer := 0
 MsgBox 'NONE', 'First action', 'Icon!'
}
You can also do it more simply as follows.

Code: Select all

#Requires AutoHotkey v2.0

RButton:: {
 timeout := !KeyWait(ThisHotkey, 'T.5')
 If A_ThisHotkey = ThisHotkey
      MsgBox timeout, 'Timeout', 'Iconi'
 Else MsgBox 'A_ThisHotkey = ' A_ThisHotkey '`n`nThisHotkey    = ' ThisHotkey, 'Hotkeys', 'Icon!'
}

#HotIf GetKeyState('RButton', 'P')
F3::MsgBox ThisHotkey, 'Pressed', 'Icon!'
#HotIf
The key with this latter script is that, although you are not canceling the KeyWait, the desired action occurs in the other function (F3), and the statement after the KeyWait is conditional.
Post Reply

Return to “Ask for Help (v2)”