Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a newbie to AHK, learning the basics. I'm using Notepad as an example - I want to hit the Cancel key every time I close Notepad and it asks if I want to Save/Don't Save/Cancel.

I've come up with the script below and it works once but then I have to reload the script to do it again. I want it to hit Cancel every time the question box comes up. I thought Loop would work but am doing something wrong. Any ideas why, anyone?

IfWinExist Notepad,
    WinWait Notepad
    Click 312, 109
share|improve this question
Use the { } or code button on the toolbar while editing to indent your code 4 spaces so it shows up properly. I've edited your post to show you how. – Karan Jun 29 '13 at 4:06
up vote 0 down vote accepted
    WinWait, Notepad ahk_class #32770

will do what you want. I've used WinWait to identify the close dialog and WinClose to close it, which is the same as clicking Cancel. I obtained the ahk_class using AutoIt3 Window Spy of course, which is installed along with AHK.

share|improve this answer
Many thanks. Your solutions are always simple and precise. I was using Notepad to get my head round clicking on a certain button. What I am actually trying to achieve is this. I use accounting software which generates statements which should automatically email (using Outlook) to clients. However Outlook complains about each and every email, it pops up a box (with the word "Outlook" in the titlebar) saying that an external program is trying to access email address information, and it gives three choices "Allow/Deny/Help" with Deny being the default key. – John Jun 29 '13 at 13:18
continued : What I want to do is use AHK to wait for this window to pop up, then move the mouse to the "Allow" key and click the button. I need the script to repeat itself the next time the box pops up. We send out a thousand statements a month and this box pops up for each of them, I want AHK to click the "Allow" button for me in each of them. I can get AHK to click the Allow key the first time the box pops up but it won't do the successive ones, but I always seem to struggle with the Looping. Thanks for your assistance – John Jun 29 '13 at 13:18
If the dialog with Allow/Deny/Help has Deny focussed by default, SendInput {Enter} would press the Enter key and thus select Deny. If you need to focus and click other buttons such as Allow you can use something like SendInput {Tab}{Enter}. – Karan Jun 29 '13 at 16:48
Thanks Karan, I'm away from home right now - will try it when I get back. I think I always tend to over-complicate these scripts whereas the solution always seems pure and simple when I see it. Thanks again for your help. – John Jun 29 '13 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .