Hotkeystrings don't work 20% of the time

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar
Posts: 540
Joined: 22 Oct 2015, 17:56

Hotkeystrings don't work 20% of the time

09 Jan 2019, 18:09

It's ALWAYS been like this
20% of the time they won't work
Maybe more actually

I've just got used to it
It doesn't work, so I'll type again. Sometimes I have to reload the textshortcuts file.

I came from PhrasExpress sometime ago.
That was a little better - not as bad - but still suffered the problem

On Mac, I have a program - I can't remember what it's called.
It work flawlessly EVERY time.

Linux: I'm using Autokey. Better than AHK for reliability. But still has hiccups.

Why are there problems?
Just wondering.

I would add that I have many hundreds and hundreds of shortcuts.
50% of which I use all the time.
The file is more than 4500 lines! Many Hotkeys output many paragraphs of text.
The Hotstrings that fail mostly are ones I declare like this:

Code: Select all

::]mytext::My text shortcut
Should I consider converting ALL to long format?
Like:

Code: Select all

::]mytext::
SendInput My text shortcut
Return
?
borgill
Posts: 5
Joined: 14 Feb 2019, 13:37

Re: Hotkeystrings don't work 20% of the time

14 Feb 2019, 13:52

I also see issues where the hot keys don't work 20% of the time. Like right now, I have a hot key that's supposed to open an .xlsx file in Excel 2016. I also have Excel 2010 on my system and need that one to be the default, hence the reason I setup this HK. The HK works 80% of the time, but there are times it just doesn't work, like now. The strange thing is, other HK's work. Here is my code below if anyone see's any issues:

Code: Select all

#u::  ; Opens files with Excel
    OpenWithExcel()
return

; Opens files with Excel
OpenWithExcel()
{
    ClipSaved := ClipboardAll
    Clipboard =

    Send ^c
    ClipWait
    FullPath := Clipboard

    Sort, FullPath
    FullPathArray := StrSplit(FullPath, "`n", "`r")

    cntr := 0
    Loop % FullPathArray.Length()
    {
        IfNotExist, % FullPathArray[A_Index]
            continue

        cntr++
        If (cntr = 1)
            Files := """" . FullPathArray[A_Index] . """"
        Else
            Files := Files . " """ . FullPathArray[A_Index] . """"
    }
    Run "C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE" %Files%, , , OutputVarPID
    WinWait, ahk_pid %OutputVarPID%
    WinActivate, ahk_pid %OutputVarPID%

    Clipboard := ClipSaved
    OutExt =
    ClipSaved =
    return
}
User avatar
rommmcek
Posts: 1474
Joined: 15 Aug 2014, 15:18

Re: Hotkeystrings don't work 20% of the time

18 Feb 2019, 06:14

@omar: First try to run your script as administrator. If it doesn't help, you should test each your Hotkey/Hotstring separately in new script (not running original script) and then report if some particular Hotkey/Hotstring not works.
Finally you'll add consecutively them together into one script with interim testing of course! Tedious work!

@borgill: Your script has some inconsistencies!

Code: Select all

#u::  ; Opens files with Excel
    OpenWithExcel()
return

; Opens files with Excel
OpenWithExcel()
{
    ClipSaved := ClipboardAll
    Clipboard =

;    Send ^c ; works
;    ClipWait, .75
   While (Clipboard = "" && A_Index <= 5) { ; more reliable
       Send, ^c               
       Sleep, 150
   }

/* ; your way works with some fixes
    FullPath := Clipboard
    Sort, FullPath
    FullPathArray := StrSplit(FullPath, "`n", "`r")

    cntr := 0
    Loop % FullPathArray.Length() ; your loop works, but consider using: for i, Path in FullPathArray
    {
        IfNotExist, % FullPathArray[A_Index]
            continue

        cntr++
        If (cntr = 1)
            Files := """" . FullPathArray[A_Index] . """"
        Else
            Files := Files . "`n""" . FullPathArray[A_Index] . """" ; added "line break" in place of space
    }

	loop, parse, Files, `n
		{
			Run, "C:\Program Files (x86)\Microsoft Office\OFFICE16\EXCEL.EXE" %A_loopField%, , , OutputVarPID
	    		WinWait, ahk_pid %OutputVarPID%,, 6
;		    	WinActivate, ahk_pid %OutputVarPID% ; I beleve this is redundant
		}
;	msgbox % Files
*/

; =============  my proposal
	FullPath2 = %ClipBoard% ; Converting to text
	loop, parse, FullPath2, `n, `r
		If FileExist(A_LoopField) 
		{
			Run, % """C:\Program Files (x86)\Microsoft Office\OFFICE16\EXCEL.EXE""" " """ A_loopField """", , , OutputVarPID
			WinWait, ahk_pid %OutputVarPID%,, 6
;		   	WinActivate, ahk_pid %OutputVarPID% ; I beleve this is redundant
		}
;	msgbox % FullPath2
; =============

    Clipboard := ClipSaved
    OutExt =
    ClipSaved =
    return
}
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Hotkeystrings don't work 20% of the time

18 Feb 2019, 12:40

Next time the hotkeys doesn't trigger, open AHK's main window and see the last lines executed and key history, to see whether it actually triggered the hotkey or whether it's just not doing what you expect. With the Excel hotkey for example, a previous instance of the hotkey may still be halted at the WinWait or something, preventing the triggering of a second thread.
?
With the hotstring, perhaps the hotstring is conditional, or you pressed a key in between which reset the buffer? I a triggering fails, does a string typed after it trigger without reloading the script?
borgill
Posts: 5
Joined: 14 Feb 2019, 13:37

Re: Hotkeystrings don't work 20% of the time

19 Feb 2019, 15:41

@rommmcek - Your edits and proposed code don't seem to work for me. Your code is trying to use a loop to open a new instance of Excel for each file. If I have 5 Excel files that I'm trying to open all together, your edited version only opens the first two files and that's it (your proposed code didn't do anything). My version called just one instance of Excel with a string input of multiple files. This worked, but only 80% of the time. I think you're newer version doesn't quite work as add-ins are still loading while I try to load a new file during the looping. I could put a longer wait, but I think I prefer a single instance without the looping.

Also, in regards to your comment on my line of code where I use the "WinActivate". I have started to use this some time ago as I have had instances of AHK where I start (Run) a program but the window is not active (forefront). This was a very annoying issue and took several days to debug. I saw this issue more on Windows 7 and not really Windows 10 (I saw some mis-activates with W-10).

@Nextron - Normally I just compile the exe from the script and start it. It sounds like you're saying you can view the key history in the "AHK's main window". How do you do this? I would like to do this as I have had problems with scripts in the past.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Hotkeystrings don't work 20% of the time

19 Feb 2019, 16:01

If you want to view the latest information it ran, just run the .ahk file (should run fine) and in your task bar find your .ahk that is running and right click it. The top option is open. Click that option and it should open the window the shows what ran last. It is a little hard to read, but should tell you if the hotstring fired.
borgill
Posts: 5
Joined: 14 Feb 2019, 13:37

Re: Hotkeystrings don't work 20% of the time

19 Feb 2019, 17:11

@MannyKSoSo - Oh cool, I didn't know about that. So I have the .ahk running now instead of the compiled .exe. So, next time this doesn't work. I'll check this log. Currently, my script is working so I can't troubleshoot it now.
borgill
Posts: 5
Joined: 14 Feb 2019, 13:37

Re: Hotkeystrings don't work 20% of the time

19 Feb 2019, 21:18

So now the process is held up again, which is good since I can look at the place that's giving an error. After looking at the log file, it's still processing this line, which is the second line in the code snippet below. I also list below the local variables with the OpenWithExcel() function. It seems like maybe something with the clipboard isn't processing correctly. 728 of 728 items?

Error from log:
617: STILL WAITING (9831.85): WinWait,ahk_pid %OutputVarPID%

Local Variables for OpenWithExcel():
ClipSaved[728 of 728]: ?...
cntr[1 of 3]: 1
Files[75 of 259]: "C:\Users\...\Desktop\Rev2_225_ESD_and_LU_Request_Form_...
FullPath[73 of 259]: C:\Users\...\Desktop\Rev2_225_ESD_and_LU_Request_Form_E...
FullPathArray: Object object {address: 0x54695C0}
OutExt[0 of 0]:
OutputVarPID[5 of 7]: 20204


Code: Select all

    Run "C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE" %Files%, , , OutputVarPID
    WinWait, ahk_pid %OutputVarPID%
    WinActivate, ahk_pid %OutputVarPID%
User avatar
rommmcek
Posts: 1474
Joined: 15 Aug 2014, 15:18

Re: Hotkeystrings don't work 20% of the time

19 Feb 2019, 21:34

Second attempt:

Code: Select all

; =============  my proposal2
	FullPath2 = %ClipBoard% ; Converting to text
	Xl := ComObjCreate("Excel.Application")
	loop, parse, FullPath2, `n, `r
		If FileExist(A_LoopField)
			Xl.Workbooks.Open(A_LoopField) ;open an existing file
	Xl.Visible := true
;	msgbox % FullPath2
; =============
Edit: Check File instead just String!
Last edited by rommmcek on 19 Feb 2019, 21:57, edited 1 time in total.
User avatar
rommmcek
Posts: 1474
Joined: 15 Aug 2014, 15:18

Re: Hotkeystrings don't work 20% of the time

19 Feb 2019, 21:38

You should use WinWait, ahk_pid %OutputVarPID%,, 6, to avoid script being stuck.
Edit: And uncomment ; msgbox % Files to see "Files" content!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Hotkeystrings don't work 20% of the time

06 Mar 2019, 07:44

- There are some points here:
Hotstrings not always fire. - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=61200
- Does it happen on certain programs?
- Could there be any issues such as the window changing as you type?
- You could put in a hotstring that does SoundBeep, to test if they're working.
- You could try setting the process to high priority.

- One other point: there was a problem with hotstrings in AHK v1.1.28.00:
[v1.1.28.01 solved] AutoHotkey doesn't work on Excel - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=14&t=44527&p=209543#p209543
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Hotkeystrings don't work 20% of the time

07 Mar 2019, 03:53

We should be careful about blaming the software or making absolute statements. Most of the time, the problem is us. We who wrote the program.
borgill
Posts: 5
Joined: 14 Feb 2019, 13:37

Re: Hotkeystrings don't work 20% of the time

07 Mar 2019, 15:20

@SOTE - If you're speaking to me, I'm not trying to pass blame solely on the AHK software. I am highlighting some things that haven't worked for me and I comment on them here, so I can get some help. It helps to have information on how something is performing so fixes can be addressed in the future. In my personal experience AHK is a powerful tool and one I use on a daily basis, which I'm grateful for. But there are some quirks about it where simple commands need additional workarounds to work. I deem these as buggy because, in a sense they are an issue and they required extra time of debugging, which gave me some headaches in the past. For example, I have a simple command on Windows that's supposed to open up GVim. It does, but it doesn't bring the window to the fore front. It's been a common issue for some AHK users. I have to also include a WinWait and WinActivate command to make this work. That makes it work now, but I think it's a little inefficient that I need three commands for something to simply open. Why can't the "Run" command take care of that? I also shouldn't need sleep commands in my code to wait for something to work as some users suggested above. Why are there commands that hang without a time default? So yes, I'm pointing out some true issues here so maybe the software designers might see them and fix them. We also need to be careful about not getting offended when issues are presented. Otherwise, we don't move forward. One lesson I've learned in life is if you can improve something so it takes out any inefficiencies, potential headaches for your customers, then you're listening/helping them out.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jameswrightesq, wpulford and 415 guests