OnExit not triggered when script contains #InstallKeybdHook

Report problems with documented functionality
joefiesta
Posts: 35
Joined: 24 Jan 2016, 13:54

OnExit not triggered when script contains #InstallKeybdHook

03 Aug 2017, 13:44

In the following, the OnExit routine is not triggered by the EXIT command:

Code: [Select all] [Download] GeSHi © Codebox Plus

#InstallKeybdHook
OnExit, ExitRoutine
exit
ExitRoutine:
msgbox exiting test....
exitapp


However, remove the #InstallKeybdHook directive and it works just fine. I can find no documentation about #InstallKeybdHook or OnExit being related.

thank you

Joe Petree
TheDewd
Posts: 798
Joined: 19 Dec 2013, 11:16
Location: USA

Re: OnExit not triggered when script contains #InstallKeybdHook

03 Aug 2017, 14:28

You are not calling the ExitApp command outside of the ExitRoutine label.

This directive (#InstallKeybdHook) also makes a script persistent, meaning that ExitApp should be used to terminate it.
User avatar
derz00
Posts: 301
Joined: 02 Feb 2016, 17:54

Re: OnExit not triggered when script contains #InstallKeybdHook

03 Aug 2017, 18:46

I think people should be slower to post things in Bug Reports. But maybe the moderators don't mind.
either stumped or stunned
joefiesta
Posts: 35
Joined: 24 Jan 2016, 13:54

Re: OnExit not triggered when script contains #InstallKeybdHook

03 Aug 2017, 20:31

I spent 2 hours working on this before I discovered the extremely subtle relationship between EXIT, ONEXIT, a persistent script and #InstallkeybdHook. I read ALL the documentation about each. thoroughly. The DEWD did point me in the right direction to understanding the issue. (However, I DID READ that quote and believed that my code should have made my Exitapp execute.)

Yes, this is not a bug. and should be moved out of the bug forum. That is not to say, however, that I should not have posted the issue. I must also add that I searched both the old and new AHK forums for help on this issue. I found NOTHING even similar to my problem. Having used AHK for about 7 years now, I usually find that my difficulty in understanding comes from the difficulty of wading through the documentation. I feel this is entirely about the idiosyncratic way EXIT works in this context, and just wish there had been one small note about that.

Thank you for you input DEWD. As to the other respondent, I think you were just wasting your time being condescending.
User avatar
derz00
Posts: 301
Joined: 02 Feb 2016, 17:54

Re: OnExit not triggered when script contains #InstallKeybdHook

04 Aug 2017, 12:21

I apologize for my condescending attitude. And now I also realize that I was wasting my time posting that. I should have thought once or twice more before I hit submit. Now I must take more time to undo the damage done. I do find it amusing/annoying the way so many people post things in bug reports when they have no idea how it is actually supposed to work. But reading your second post, I see you did your homework, and the documentation itself can receive the blame. I guess my own attitude of being smart about AHK (which I undoubtedly am not) is to blame for that post.

Thanks for not being too polite to correct me!
either stumped or stunned

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 3 guests