1

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.

  • As far as I can say: 1) "SetTimer, Keyb, -250" is less than (sleep 80 + Sleep 200). Replace it with "SetTimer, Keyb, -300" 2) "Send {b}" is false. Replace it with "Send b" 3) Replace all "MouseClick, left" with "Click". Click is more reliable. See also: Debugging a Script – user3419297 Nov 22 '16 at 17:21
  • Hi user3419297 I applied the changes, but still the same, the script works, but it need that I manually click somewhere, between two scripts, in other words, it can't run two scripts one after the other, without me to between them make some click manually, why is that? is a very specific issue, like somehow the first script (after run) keeps running, or is left hung. I remember that in AHK there were some chars that can be place before the hotkey, like ~b, perhaps some of them could help here. any idea? where else can I post this issue?? thanks advanced. – litu16 Nov 22 '16 at 17:41
  • I have realized that it only happen with the "b" and "bb" hotkeys, I almost sure it is cuz, when the first click is made a menu appears, so the second click clicks on some of that menu's item. In other macro recorders you have to specically tell the macro recorder that a menu appeared, otherwise the second cick will not work, does it happen the same way with AHK?? Do I need to place some instruction between the first click and the second click in the "b" script??? Thanks Advanced. – litu16 Nov 22 '16 at 18:00
  • solved, I just refocused to ArtRage at the end of the "b" and "bb" actions. So the "b" and "bb" works fine, but I still have some lag in response, when firing "b" and then "1". – litu16 Nov 22 '16 at 18:23
  • hi user3419297 one little doubt, do I need to put the parens in order to set the order in which the math operations must be perform? MouseClick, Left, 13, VarA + (VarB * 2) or how should I put them? Thanks Advanced. – litu16 Nov 23 '16 at 0:53
1

For controlling whether the mouse clicks the right position in the right window, you can use this:

F1::
ARtoolPresetTopY := 125
ARtoolPresetGapY := 29

Ypos := ARtoolPresetTopY + (ARtoolPresetGapY * 8)
MsgBox, %Ypos%  ; Press Enter for closing this MsgBox.

; Click, 13, %Ypos%
; or
ControlClick, x13 y%Ypos%, ahk_class ArtRage 3

MouseMove, 13, %Ypos%, 0 ; this line is only needed for getting the mouse position and the name of the control you want click:
MouseGetPos, MouseX, MouseY, WindowUnderMouse, ControlUnderMouse
WinGetTitle, title, ahk_id %WindowUnderMouse%
WinGetClass, class, ahk_id %WindowUnderMouse%

MsgBox, MouseX = %MouseX%`nMouseY = %MouseY%`n`nWinTitle = %title%`nWinClass = ahk_class %class%`n`nControlUnderMouse = %ControlUnderMouse%
return
  • 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.

  • I'm not quite sure how to use the ControlClick, I did it like this CotrolClick, 195, 55, ahk_class ArtRage 3 but it doesn't click anything, could you please post an example of how to use the control click just using the mouse locationXY and the ahk_class as parameters, thanks advanced. – litu16 Nov 23 '16 at 15:37
  • See ControlClick in my edited answer and examples. – user3419297 Nov 23 '16 at 15:59
  • Hi, user3419297, I have put the 1 and 11 actions into functions, cuz there are 1, 2 ,3 4, 5, 6, 7, 8 and all do almost the same, bust I kinda suspect that since I convert them into a single function, they kinda run a little slower, is it possible? does Functions run slower in AHK?? Thanks Advanced. – litu16 Nov 24 '16 at 21:14
  • Hi user3419297 I have a similar problem here, I had a hard time dealing with a lost of windows focus, I searched on the ahk forum, but I can't figure out how exactly how should I write the code, I made some tries, could you please check it out? superuser.com/questions/1150737/… thanks advanced. – litu16 Nov 28 '16 at 20:39
  • what if instead of %posY% I want to use a parameter, cuz now these actions are inside a function, and its parameters are the cordanetes, can I use ControlClick x%ParamA% y%ParamB% ?? THanks advanced. – litu16 Nov 30 '16 at 17:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.