how to deal with daily driver script hanging - detecting, reloading from outside script?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
redrum
Posts: 100
Joined: 25 Jan 2015, 22:57

how to deal with daily driver script hanging - detecting, reloading from outside script?

24 May 2024, 16:32

I have a daily driver script that contains all my regularly used hotkeys. Occasionally it will hang (or I guess execution never gets handed back to the main script). I usually find out only when I go to press a hotkey and it doesn't work. Since this is my trading computer, finding out this way can be costly.

1. Apart from trying to make all the hotkeys as robust as possible, including the obvious error handling (the not so obvious error handling is something I only discover when there's an error), is there a way to get alerted if the script is hung?

2. When the script hangs, obviously the hotkey to reload the script won't work - maybe a good solution is a separate ahk script with a hotkey to reload the first script?
Edit: Created a separate script with a hotkey to run my daily driver script (the latter has `#SingleInstance` so no worries about multiple instances).

Code: Select all

+#r::
{
    Run("dailydriver.ahk /restart")
}
Not sure if this is preferred method, but seems like a decent solution to issue #2.

3. I have a couple of important hotkeys, where it's not obvious, without looking very closely, that they executed. For situations like this, is there an easy way to visually see that the hotkey worked? Nothing that interrupts flow like a MsgBox that I have to dismiss. Maybe the mouse cursor flashing or being highlighted for a couple of seconds?
Edit: Tooltip with a timer seems to be a good solution for this last issue. But if any other ideas, I'm all ears.
Last edited by redrum on 24 May 2024, 21:02, edited 2 times in total.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: how to deal with daily driver script hanging - detecting, reloading from outside script?

24 May 2024, 20:47

If you can open the script's main window via the tray icon and view the Lines/Key history in the View menu, you may find that the script isn't hung, just not responding to hotkeys. That would usually be a result of the OS silently deregistering the keyboard hook, perhaps because of an unresponsive #HotIf expression or some external issue. InstallKeybdHook(true, true) reregisters the hook, but you would need some way to call it (perhaps a menu item or registered, not keyboard hook, hotkey).

If you are using AutoHotkey 32-bit, switch to 64-bit. The OS is apparently more likely to deregister the hook for 32-bit processes.
redrum
Posts: 100
Joined: 25 Jan 2015, 22:57

Re: how to deal with daily driver script hanging - detecting, reloading from outside script?

26 May 2024, 16:59

lexikos wrote:
24 May 2024, 20:47
If you can open the script's main window via the tray icon and view the Lines/Key history in the View menu, you may find that the script isn't hung, just not responding to hotkeys.
Was not aware this viewer existed. That's pretty cool, thanks.
lexikos wrote:
24 May 2024, 20:47
That would usually be a result of the OS silently deregistering the keyboard hook, perhaps because of an unresponsive #HotIf expression or some external issue. InstallKeybdHook(true, true) reregisters the hook, but you would need some way to call it (perhaps a menu item or registered, not keyboard hook, hotkey).

If you are using AutoHotkey 32-bit, switch to 64-bit. The OS is apparently more likely to deregister the hook for 32-bit processes.
I'm using 64-bit AHK.

Is there a way to monitor if one AHK script becomes unresponsive via another AHK script?
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: how to deal with daily driver script hanging - detecting, reloading from outside script?

27 May 2024, 02:55

There is no easy way to detect when the hook stops getting called. KeyHistory will not update (except by the script's own Send); A_PriorKey and A_TimeIdleKeyboard will not update; hotkeys will not execute and InputHook will not receive input. If you can detect that any of these things should have happened but didn't, you can try reinstalling the hook.
User avatar
xMaxrayx
Posts: 237
Joined: 06 Dec 2022, 02:56
Contact:

Re: how to deal with daily driver script hanging - detecting, reloading from outside script?

27 May 2024, 03:27

Why it's hang?

simplay use a key on that script that can reload the script, do not use inputhock unless you know what you are doing because if everything go bad you can't use other Hotkeys, including that one be used to reloads

another solution is use outside 1-click program and put it on the desktop or on Taskbar since most scripts don't touch mouse, you may add to that scrip "{Win up}{ Ctrl Up} etc. to fix down-ed modifiers key.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Google [Bot] and 54 guests