AutoHotkey constantly needs restarting.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Abrams1960
Posts: 3
Joined: 13 Feb 2018, 19:17

AutoHotkey constantly needs restarting.

13 Feb 2018, 19:35

I have a simple AutoHotkey script and ahk button.
I'm simply copying hightlighted text to the clipboard and then sending by way of an API call to perform a file retrieval from another database system.

The script works perfectly, no issues whatsoever, performance has been fast and 100% satisfactory.

The problem I am having, is that AutoHotkey stops working. We close it, restart it, and it works flawlessly once more.

The computer is not going to sleep, its not hibernating, and Autohotkey is in the start-menu tray to automatically start, which is does, every morning as the PC's are all booted up for another day of work.

But if left on for a couple of hours, it just stops working, maybe because the API call it makes loses some connection to the server its calling to? Restarting the script solves everything, but constantly restarting AutoHotkey is a pain.

Any suggestions?

Script Sample as follows:

#SingleInstance force
#NoEnv

^Q:: ;CNTRL+Q initializes this routine
clipboard = ;Start with an empty clipboard
Send, ^c ;Perform a CNTRL+C - windows copy command
ClipWait ;Built in method that waits for clipboard to contain text
;MsgBox Control-C copied the following contents to the clipboard: %clipboard% ;This line can be used to display a message control to test clipboard contents. Simply remove beginning semicolon from line.
Run, http://SYS-EDMS-01/ISYNERGY/web/handler ... %clipboard%
Return

The API call above is what the clipboard text copy is passed to, and it instructs the receiving database system to search and find files that area associated with the text value associated with the clipboard text.
Works absolutely perfectly, until AHK decides to stop pushing the API call and needs to be restarted. Any way to keep in 'on' and not in the system tray saying its on, but no longer firing? Seems to be not liking having to send that API call over the network more than once or twice per day. This API call also passes login credentials and search instructions, but I don't think that's the problem, as the AHK button just stops firing altogether. I'm thinking some Windows OS condition that maybe I need to tweak this situation around a bit?

Thanks,

[edit. changed embedded pw for the below mentioned reason] BoBo
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AutoHotkey constantly needs restarting.

13 Feb 2018, 20:42

It's probably getting stuck at the ClipWait.

Code: Select all

clipWait,1
if(!errorlevel)
    run, url
return
Note: it looks like your URL contains a password.. you may consider removing that if it's sensitive material/against company policy. Assuming this is in a business environment, since you said "we."
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: AutoHotkey constantly needs restarting.

13 Feb 2018, 20:54

I have experienced AHK crashing when my system resources are depleted -- if a web browser freezes and demands from Windows more resources, it usually results in AHK getting frozen and requiring I restart the scripts individually. I made a post about it in the past, and the suggestion given was to run the AHK process with high priority. That unfortunately hasn't worked from the little testing I did with it.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AutoHotkey constantly needs restarting.

13 Feb 2018, 21:46

Exaskryz wrote:I have experienced AHK crashing when my system resources are depleted -- if a web browser freezes and demands from Windows more resources, it usually results in AHK getting frozen and requiring I restart the scripts individually. I made a post about it in the past, and the suggestion given was to run the AHK process with high priority. That unfortunately hasn't worked from the little testing I did with it.
This makes a lot of sense actually. When I use to run AHK on my old laptop, I frequently needed to restart them. Do you know if this is a problem with AHK not handling page file (it is the page file right, when "not needed" processes get written to disk?) restoration, or an issue with Windows not handling the restoration properly?
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: AutoHotkey constantly needs restarting.

13 Feb 2018, 22:16

That's a good question. I've only experienced this with AHK needing a reboot personally. I have noticed this only with hotkey commands not executing. So it could be keyboard hooks get uninstalled and not reinstalled, if the process is actually being reactivated? However, I do have a persistent GUI that becomes unresponsive. It uses on-click from the edge of my screen to slide out, so it may be more than keyboard hooks. The code used is

Code: Select all

OnMessage("0x0201","Slide") ; really this is the only part relevant to the thread, that the message 0x0201 is ignored.

...

Slide(){
If (A_Gui="Emotes") || (A_Gui="Streamer_Selection") ; other GUIs
   return
ListLines, Off
global viewable
OnMessage("0x0201","Null") ; this makes further clicks on the GUI not trigger the Slide() command and instead lets me operate buttons normally
WinGetPos, a, b, c, d, Slide Pane   ; from here on it's just sliding the window into view and resizes all other windows
Loop, % c-1
{
WinGetPos, x,y,,,Slide Pane
WinMove, Slide Pane,, % x-1, y
}
WinGet, all, list,,,Slide Pane
ratio:=(A_ScreenWidth-viewable)/A_ScreenWidth
Loop % all
{
WinGet, minmax, minmax, % "ahk_id " all%A_Index%
If minmax=-1
   Continue
WinGetPos, q, r, s, t, % "ahk_id " all%A_Index%
WinMove, % "ahk_id " all%A_Index%,,% Ceil(q*ratio),% r,% Ceil(s*ratio),% t
}
return
}
Because of the nature of this window normally being positioned on the right-most column of pixels on my screen, I can't actually tell if the GUI is unresponsive or if it disappeared... Maybe there is a way to tell, but not easily.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AutoHotkey constantly needs restarting.

13 Feb 2018, 23:16

You can check window hangs fairly easy, though I don't know how reliable it is.

My best guess is that hooks, including (perhaps not limited to) keyboard, mouse, window, and message hooks, don't re-register when they're brought back to memory. lexikos, could we have some input please?
lexikos wrote:.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoHotkey constantly needs restarting.

14 Feb 2018, 00:39

The hooks are never re-registered unless they were previously unregistered due to becoming unnecessary (e.g. Suspend On followed by Suspend Off may re-register the hook if there are no hook hotkeys/hotstrings exempt from suspension and the hook was not needed for any other purpose).

AutoHotkey (like the vast majority of programs, I expect), does not "handle" the page file "restoration". That is the operating system's domain. If AutoHotkey is pushed out to page file and has a keyboard hook installed, the delay which occurs while the system pulls it back into RAM may exceed the system timeout.
#IfTimeout wrote:Note that the system implements its own timeout, defined by the DWORD value LowLevelHooksTimeout in the following registry key:

HKEY_CURRENT_USER\Control Panel\Desktop

If the system timeout value is exceeded, the system may stop calling the script's keyboard hook, thereby preventing hook hotkeys from working until the hook is re-registered or the script is reloaded. The hook can usually be re-registered by suspending and un-suspending all hotkeys.

Microsoft's documentation is unclear about the details of this timeout, but research indicates the following for Windows 7 and later: If LowLevelHooksTimeout is not defined, the default timeout is 300ms. The hook may time out up to 10 times, but is silently removed if it times out an 11th time.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AutoHotkey constantly needs restarting.

14 Feb 2018, 02:07

Hm, interesting. I've never actually looked at that documentation. Then the obvious answer would be to have the process excluded from being paged. Though, I can't find anything about that, if it's even technically possible. I would presume, and as mentioned by Exaskryz, upping the process priority would lessen the chance of it being pushed to the page file, but not necessarily guarantee it won't. If "High" doesn't work, setting to "RealTime" might, but I wouldn't recommend having any long-term processes running in RealTime. At least, I've experienced problems in the past when testing.

I realize that toggling suspend can re-register them, but the documentation does say usually. As it's not a guarantee (or is it?), I don't immediately consider this a solution, but a workaround.

Note to anyone who may be reading: I HIGHLY discourage disabling the page file. That will cause processes to simply crash instead of being paged, which may result in data loss.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: AutoHotkey constantly needs restarting.

14 Feb 2018, 10:55

Interesting, thanks lexikos. I will test out doing a quick Suspend/Unsuspend for these instances and see if it resolves, the next time my system has a crisis. If it does, then it likely means the problem is the hooks being unhooked and not something else. If it doesn't, then it could be that case where it just wouldn't work due to no guarantee, but keeps the door open on there being another problem.

Though, depending on use case, the reload may be easiest to work with because that's one click on the menu instead of two (including opening the menu again). But, if I were to define an AHK script that I launch when I notice other scripts have their hooks unhooked, I would want to go the route of toggling suspend and unsuspend. If I'm going to automate the process, should go with the one least likely to lose data.

Edit: Jeez, that took less than 15 minutes. Suspend/unsuspend did not work out for me to restore functionality. Hotkey activation had been disabled in two separate scripts. Reloading still does the trick.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AutoHotkey constantly needs restarting.

14 Feb 2018, 13:39

- Thanks for bringing up this issue. It makes AHK almost unusable on a low-spec mini-laptop that I have, intended for commutes/travel. Hotkeys regularly stop working for all scripts, and the scripts need to be reloaded.
- Btw did you get this error when you tried to reload?
Could not close the previous instance of this script. Keep waiting?
I regularly get that message, multiple times, when I try to reload a script whose hotkeys have been 'forgotten'. I would love any explanation generally for what causes this message.
- In theory, a message to a script to reregister its hotkeys, or to force reload a script, or to check if a script's hotkeys are still working, could help to resolve the problem.
- Btw does anyone have any tips to deliberately cause the problem, for testing purposes. Perhaps setting AHK to low priority, and trying to clear Internet Explorer's cache. Thanks for reading.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AutoHotkey constantly needs restarting.

14 Feb 2018, 17:06

I've never gotten your error (at least not in your specific case anyway), jeeswg, but perhaps that is occurring because there's not enough room in memory to load it back from the page file? Just a guess. Is your RAM 1GB or less? Unless you're force killing the process, it would need to load back into memory to honor any possible onExit routines (even if they aren't present). Perhaps you should make a script to (on open, not relying on hotkeys) force close and re-open all of them?

WARNING: the following script may crash your system and is for testing purposes ONLY. Please use with caution!
Spoiler
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: AutoHotkey constantly needs restarting.

14 Feb 2018, 18:31

The way I seem to be crashing my system is using 3 browsers simultaneously and doing memory intensive tasks like video watching while viewing maps in one browser, leaving up a chat application (Discord) in another browser, and doing general internet surfing in yet another browser. This is on top of having Notepad++ launched with a hundred or so files open, a dozen or two Notepads open, running an MS Office application, and having an instance of Paint open.
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoHotkey constantly needs restarting.

16 Feb 2018, 23:30

Masonjar13 wrote:I realize that toggling suspend can re-register them, but the documentation does say usually. As it's not a guarantee (or is it?), I don't immediately consider this a solution, but a workaround.
The conditions for Suspend to re-register the hook are as noted in my previous post.

Of course it's a workaround; even if you had a 100% reliable way to re-register the hook, you still need to tell it to re-register, either after somehow detecting the problem or at arbitrary times.
Note to anyone who may be reading: I HIGHLY discourage disabling the page file. That will cause processes to simply crash instead of being paged, which may result in data loss.
No, it may cause processes to crash, or would under specific conditions, namely that the system runs out of RAM. If it is enabled, the pagefile is used long before the system runs out of RAM. If the system never uses more virtual memory than the total amount of RAM, paging is a waste of time (and SSD write cycles if you have an SSD). In the 8-9 years I've had pagefile disabled, I've run out of RAM only once as far as I can recall, and in that instance enabling the pagefile didn't help. But then, I invest in hardware capable of doing what I need.
jeeswg wrote:It makes AHK almost unusable on a low-spec mini-laptop that I have,
If it's that bad, I would advise against using the hooks on that system at all. Use only registered hotkeys. (But you could try increasing the LowLevelHooksTimeout first.)
I regularly get that message, multiple times, when I try to reload a script whose hotkeys have been 'forgotten'.
The script is not responding to messages (such as the message used by the new instance of the script to close the old one) fast enough, which is probably the reason hotkeys stopped working in the first place.
Btw does anyone have any tips to deliberately cause the problem, for testing purposes.
You can try decreasing LowLevelHooksTimeout to a very low number.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AutoHotkey constantly needs restarting.

17 Feb 2018, 21:44

It was my implication that page file is only used after RAM is expended, as I've read quite a few articles stating so (perhaps an older version did in fact page prior to running out of room?). I've also never seen any actual proof that the page file is used prior to running out of room, or of any instances of slowdown pointing to the page file if there's still enough available RAM. I can also speak from experience: I've always had page file enabled, and on my desktop, I've never had slowdown that indicates such, and I've also never run out of RAM. Never on this machine have I had any hotkeys lose their hooks either, and I have AHK running with hotkeys at all times my desktop is on. Unless you have legitimate evidence (specifically of recent iterations, as they're the only ones that matter at this point), which I'd be very interested in knowing of so please let me know, I'll have to defer to Occam's Razor. In comparison, my laptop very often uses the page file, noticeably, but it also is constantly running out of RAM.

Regarding LowLevelHooksTimeout, can you change the allowed timeout amount instead of the time it takes to timeout, and would it even matter? Purely speculation, but it would make sense to me that the system would have more time to process page file-to-RAM in-between timeouts (while it would be very, very tiny, could be useful for low-spec machines as mentioned). There also isn't an entry for it by default, which seems strange. Even if not explicitly defined, I'd have expected there to still be an entry with the default timeout mentioned. It also only applies to the current user; is there an entry to apply it to all accounts, already existing and future created ones? Ntuser.dat would take care of newly created ones, but I don't know how to edit it.

In the mean time, I'm going to take logs on the page file, some personal testing.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
Abrams1960
Posts: 3
Joined: 13 Feb 2018, 19:17

Re: AutoHotkey constantly needs restarting.

17 Feb 2018, 22:35

This is all great information, thanks to all who have responded. Wonder if any future script modification(s) could be appended to an existing script, that would auto-re-register the keyboard hooks? While this is in the OS domain, the registry keys should be accessible, even by web pages and AHK scripts. I am using a web-architecture ECM/Document Management application with my AHK script. The ECM system is fully web-architecture, so web pages are being called by the AHK script. And browsers, yes, seem to time-out often, especially with such lovely browsers as MS Edge and some recent buggy versions of Firefox.

It's obvious if there is a script-modification solution, adjustments to the registry and DWORD, will have to almost run on a scheduler-type of routine to keep the key hooks registered and timely with their use. That being said, exiting and restarting the script buttons is not the end of the world.
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoHotkey constantly needs restarting.

18 Feb 2018, 17:14

Masonjar13 wrote:It was my implication that page file is only used after RAM is expended,
And yet, I explicitly stated otherwise. What I did not say anything about was "slowdowns" or programs being paged out. If, as you say, the page file is never used before the RAM is expended, and if RAM is never expended, then it is just a waste of disk space (an important factor on systems with small SSDs), and any time spent by the system to maintain its presence is time wasted. However, that is not necessarily the case.
Some feel having no paging file results in better performance, but in general, having a paging file means Windows can write pages on the modified list (which represent pages that aren’t being accessed actively but have not been saved to disk) out to the paging file, thus making that memory available for more useful purposes (processes or file cache). So while there may be some workloads that perform better with no paging file, in general having one will mean more usable memory being available to the system (never mind that Windows won’t be able to write kernel crash dumps without a paging file sized large enough to hold them).
Source: Pushing the Limits of Windows: Virtual Memory – Mark's Blog
Note that I never recommended disabling the page file, only argued against your reasoning for discouraging it. A person can make their own choice based on their system, requirements and experience. In my case, I am confident that my system has quite enough available memory for caching without pushing other things out to a page file.
Regarding LowLevelHooksTimeout, can you change the allowed timeout amount instead of the time it takes to timeout, and would it even matter?
I assume you mean the number of times it can time out (otherwise I have no idea what distinction you are making). As far as I am aware, this number is neither officially documented nor possible to customize. I am not aware of any other registry keys relating to this.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AutoHotkey constantly needs restarting.

18 Feb 2018, 20:52

lexikos wrote:And yet, I explicitly stated otherwise.
I acknowledged such, but I don't immediately take what someones says as the truth. If it can be cross-referenced with several reputable sources, then I would take it as true.

Besides what you just posted (which I've never heard of the "modified list," I'll look into that more), I've been reading up and it does appear that it may write to the page file prior to running out of RAM, but I've been monitoring my system and I don't see any i/o activity to the page file, even while running intensive games. Regardless, it still wasn't close to my max. Though, I was stating the discouragement for people who may come across this thread and assume it as a fix, but then have their applications crash all the time.
lexikos wrote:I assume you mean the number of times it can time out
Yes, exactly. I've been looking and haven't found anything, so I'm assuming not at this point.
Abrams1960 wrote:the registry keys should be accessible
Then as it is, you can add the following line (adjust timeout as necessary):

Code: Select all

regWrite,REG_DWORD,HKCU\Control Panel\Desktop,LowLevelHooksTimeout,1000 ; timeout in ms
I mentioned this earlier: there should be at least some way to disable paging for a particular process, even if the process has to do something to keep "active." Though, I'm not sure how it determines what is active or not. Perhaps making it a service will give it a better chance at doing so?
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
Abrams1960
Posts: 3
Joined: 13 Feb 2018, 19:17

Re: AutoHotkey constantly needs restarting.

19 Apr 2018, 15:51

I've seen similar tools that are a service-bound facsimile of Auto-Hotkey, and they also stop any and every time the PC sleeps, hibernates or may be inactive for too long a time. Being a service does not seem to offer an advantage, because at least so far, no one has programmed one that will re-connect itself with persistence if it loses connection with the service, times out, or is running client server and loses touch with the server for even a short amount of time. Both the auto-hotkey and the service bound hotkey need restarting to resume proper functions.

Its my hope someone in the forum or with auto-hotkey might come up with a way for the key-application to restart itself if it does not connect or succeed with its own execution.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 120 guests