For example,
Code: Select all
9::
{
...
}
Is there a clean way for the script to ignore a key being held down?
Basically, I have the opposite problem of this lol: https://www.autohotkey.com/board/topic/87990-hold-down-key-to-trigger-script/
Code: Select all
9::
{
...
}
Code: Select all
9::
SoundBeep ; your code in place of this line
KeyWait, 9
return
Thanks! This work for some of my scripts but not others.boiler wrote: ↑02 Mar 2022, 05:11Use KeyWait:Code: Select all
9:: SoundBeep ; your code in place of this line KeyWait, 9 return
Using { } is not how you define the start and end of a hotkey routine (except in AHK v2 where they are functions). Remove the braces and end with a return as shown above.
Code: Select all
9::
T := !T
if(T){
SetTimer, Loop, -1
}
KeyWait, 9
Return
Loop:
While T
{
SoundBeep ; your code in place of this line
}
Return
boiler wrote: ↑02 Mar 2022, 08:55It's because your While loop has taken control of the code flow, so it never returns to the hotkey subroutine to continue to the KeyWait line. You could add #MaxThreadsPerHotkey 2 at the top so that another press of the 9 hotkey will interrupt and toggle T, but it won't behave as you would like while you hold down the 9 key. If you take those kinds of things into account, you should be able to devise the logic necessary to do what you want.
Code: Select all
9::
SoundBeep ; #NoEnv
#SingleInstance, Force
bWheel := False
Period := 250
Return ; end of auto-execute section
Wheeler: ; timer controlled
ToolTip, %Period%, 0, 0
Send, {%Key%}
Return
;-------------------------------------------------------------------------------
#If Not bWheel ; context
;-------------------------------------------------------------------------------
WheelUp:: ; start auto-scrolling
WheelDown:: ; start auto-scrolling
bWheel := True
Key := A_ThisHotkey
SetTimer, Wheeler, %Period%
Return
;-------------------------------------------------------------------------------
#If bWheel ; other context
;-------------------------------------------------------------------------------
WheelUp::
WheelDown::
If (Key = A_ThisHotkey) { ; same direction -> go faster
If (Period -= 50) < 50
Period := 50
} Else ; other direction -> go slower
If (Period += 50) > 1000
Period := 1000
SetTimer, Wheeler, %Period%
Return
Esc:: ; stop auto-scrolling
bWheel := False
ToolTip ; off
SetTimer, Wheeler, Off
Return
;-------------------------------------------------------------------------------
#If ; end of context
;-------------------------------------------------------------------------------