Simple script doesn't always execute - why?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Simple script doesn't always execute - why?

27 Nov 2021, 07:42

The first time it executes is always the problem (nothing happens). I either have to retype the hotkey, or simply refresh the script for it to work, and it will work reliably thereafter.

Is there anything I missed that causes it not to work the first time, intermittently?

Code: Select all

Drives := "CDE"
Loop Parse, Drives
    if FileExist(A_LoopField ":\Dropbox"){
        Drive:=A_Loopfield
        break
        }
        
        GroupAdd, SaveDialogs, ahk_class CabinetWClass
GroupAdd, SaveDialogs, ahk_class WorkerW
GroupAdd, SaveDialogs, Browse...
GroupAdd, SaveDialogs, Open

        #If WinActive("ahk_group SaveDialogs") 
        
        ::;ahk::
SendInput %Drive%:\Dropbox\AHK{Enter}
return
User avatar
mikeyww
Posts: 26880
Joined: 09 Sep 2014, 18:38

Re: Simple script doesn't always execute - why?

27 Nov 2021, 07:52

A simple debugging strategy is to run the following.

Code: Select all

;#If WinActive("ahk_group SaveDialogs")
:X:;ahk::SendInput %Drive%:\Dropbox\AHK{Enter}
#If
If it stops working when you uncomment the first line, then it means that you have the wrong window.

I have found, in some cases, that hotstrings do not always work when you are positioned in an empty edit control. I think that it is because there is nothing to trigger the hotstring (e.g., if you do not first type Space). This behavior has varied in my testing.
User avatar
boiler
Posts: 16920
Joined: 21 Dec 2014, 02:44

Re: Simple script doesn't always execute - why?

27 Nov 2021, 08:15

mikeyww wrote: I have found, in some cases, that hotstrings do not always work when you are positioned in an empty edit control. I think that it is because there is nothing to trigger the hotstring (e.g., if you do not first type Space). This behavior has varied in my testing.
That’s a good observation, and I believe it’s likely because the last thing you typed before clicking in the edit box is part of what AHK is considering when evaluating hotstrings. It’s not based on text that appears rather than key presses. You can initiate a hotstring by typing the triggering keys without any window being active that displays what you type. So what may appear in one window is not necessarily reflective of the keys being tracked by AHK for hotstrings.

Example: If you have a hotstring triggered by tbd, and you just typed hello in Notepad before clicking to MS Word and typing tbd (followed by a space), AHK wouldn’t trigger the hotstring because the last string of keys you typed since the last end char that would have reset it is hellotbd.
User avatar
mikeyww
Posts: 26880
Joined: 09 Sep 2014, 18:38

Re: Simple script doesn't always execute - why?

27 Nov 2021, 08:30

Thanks, boiler! I hadn't thought of that, but it makes sense.
User avatar
boiler
Posts: 16920
Joined: 21 Dec 2014, 02:44

Re: Simple script doesn't always execute - why?

27 Nov 2021, 08:40

Sure. But I guess my contrived example wasn’t a good one because a click is supposed to reset the hotstring. But basically, be cognizant of the last keys pressed even if they don’t all appear in a string of displayed text.
User avatar
boiler
Posts: 16920
Joined: 21 Dec 2014, 02:44

Re: Simple script doesn't always execute - why?

27 Nov 2021, 08:43

In fact, everything I said may be a bunch of hooey. From the docs:
The hotstring recognizer checks the active window each time a character is typed, and resets if a different window is active than before.
I should have experimented first!
User avatar
mikeyww
Posts: 26880
Joined: 09 Sep 2014, 18:38

Re: Simple script doesn't always execute - why?

27 Nov 2021, 08:46

That's OK. I never figured out the conditions where it works vs. doesn't work anyway.
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: Simple script doesn't always execute - why?

28 Nov 2021, 07:57

boiler wrote:
27 Nov 2021, 08:15
mikeyww wrote: I have found, in some cases, that hotstrings do not always work when you are positioned in an empty edit control. I think that it is because there is nothing to trigger the hotstring (e.g., if you do not first type Space). This behavior has varied in my testing.
That’s a good observation, and I believe it’s likely because the last thing you typed before clicking in the edit box is part of what AHK is considering when evaluating hotstrings. It’s not based on text that appears rather than key presses. You can initiate a hotstring by typing the triggering keys without any window being active that displays what you type. So what may appear in one window is not necessarily reflective of the keys being tracked by AHK for hotstrings.

Example: If you have a hotstring triggered by tbd, and you just typed hello in Notepad before clicking to MS Word and typing tbd (followed by a space), AHK wouldn’t trigger the hotstring because the last string of keys you typed since the last end char that would have reset it is hellotbd.
your example makes it so much clearer. If that's the case, is there a way to tell AutoHotkey to ignore my previous keypresses, especially when I'm trying to trigger a Sendinput for a directory? For instance, I can't just type in Win Explorer (without first clicking on the address bar), since it will open some random file (whatever that last character ends up)..

I did try using a Click on the top of the window to "reset" the status, but that didn't resolve the intermittent issue.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Nerafius and 100 guests