I have two scripts in AHK, both triggered by "key sequences" (b pressed twice) and (1 pressed twice), here is the code
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode RegEx ; matchs apps windows names using RegEx
; Delay A between key sequence triggers
ARkeySeqDelayA := 250
; if Presets Panel is in 100%
; Y axis top in tool presets is 122 pixels
; Y axis gap between tool presets is 29 pixels
ARtoolPresetTopY := 125
ARtoolPresetGapY := 29
return
#If WinActive("ahk_class ArtRage 3")
b::
if Keyb_presses > 0 ; SetTimer already started, so we log the keypress instead.
{
Keyb_presses += 1
return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
Keyb_presses = 1
SetTimer, Keyb, -250 ; Wait for more presses within a 250 millisecond window.
return
Keyb:
if Keyb_presses = 1 ; The key was pressed once.
{
BlockInput, MouseMove
Send {b}
sleep 80
MouseClick, left, 195, 55
Sleep 200
MouseClick, left, 200, 85
BlockInput, MouseMoveOff
}
else if Keyb_presses = 2 ; The key was pressed twice.
{
BlockInput, MouseMove
Send {b}
sleep 80
MouseClick, left, 195, 55
Sleep 200
MouseClick, left, 200, 110
BlockInput, MouseMoveOff
}
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
Keyb_presses = 0
return
1::
if Key1_presses > 0 ; SetTimer already started, so we log the keypress instead.
{
Key1_presses += 1
return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
Key1_presses = 1
SetTimer, Key1, -250 ; Wait for more presses within a 250 millisecond window.
return
Key1:
if Key1_presses = 1 ; The key was pressed once.
{
BlockInput, MouseMove
MouseClick, left, 13, ARtoolPresetTopY
BlockInput, MouseMoveOff
}
else if Key1_presses = 2 ; The key was pressed twice.
{
BlockInput, MouseMove
MouseClick, left, 13, ARtoolPresetTopY + (ARtoolPresetGapY * 8)
BlockInput, MouseMoveOff
}
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
Key1_presses = 0
return
but somehow when I trigger the "1" script, and then few seconds later I want to use the "11" script, it will not work unless I have clicked anywhere previously myself (manually), it seems like AHK previous script is somehow still running and needs me to end it by clicking myself anywhere.
Also when I trigger the "bb" script, and then a 1 second later I want to use the "1" script it will not work, again it seems that somehow AHK is still running the previuos script or something, and I have to make a click my self, and then only then it will work the "1" script. So I can't run "bb" and "1" script one after another (which is something I always do, very necesary) without me having to do some mouseclicks myself between them, how can I avoid this??
after further test, I replace all the executing parts of the script with just
Run C:\Users\myname\Desktop\AR4 bb.exe ; the same script done in a macro recorder
click up left
and I have notice that the problem persist, so is the way how the script is doing differenciating the single and double keypresses that is interfering with the script to be run two times consecutively. If I press "b" wait one sec, but don't do any mouse click by myself and the press "bb" (b two times) it will execute the "b", but if I do some mouseclicks by myselft before, it will execute the "bb". why is that happening?
what can I do?? is there some command that I could add in order to make this script more responsive?
Thanks Advanced.
Best Answer
For controlling whether the mouse clicks the right position in the right window, you can use this:
Instead of Click you can use ControlClick (then you don´t need BlockInput).
Try also replacing "b::" and "1::" with "$b::" and "$1::". (Keyboard hooks always have precedence).
See also: Debugging a Script.