Run a 2 step close down of a program

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
alanj
Posts: 3
Joined: 22 Oct 2021, 05:42

Run a 2 step close down of a program

Post by alanj » 22 Oct 2021, 06:31

Hi
I'm new to AutoHotKey (today) and would like to run a script which would activate a shortcut to close a program and then stop running. There's two stages - Pressing INSERT+Q followed by ENTER. What I have so far is below but it only gets me to the dialog box appearing (INSERT+Q) - any ideas why the ENTER does not appear to send?
------------------------------

Code: Select all

Send {INS down}
Send {q down}
Sleep, 1000
Send {INS up}
Send {q up}
Sleep, 3000
Send {ENTER}
return
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Run a 2 step close down of a program

Post by mikeyww » 22 Oct 2021, 07:34

Welcome to AHK! :)

I do not know what your program is, but one can usually simply use WinClose to close a program.

Code: Select all

#IfWinExist ahk_exe notepad.exe ; Hotkey works if this window exists
F3::                            ; Press F3 to trigger the subroutine
WinClose                        ; Close Notepad
SoundBeep, 1500                 ; Provide a confirmational signal
ExitApp                         ; Exit this script (can change this to Return to keep the script running)
#IfWinExist
Regarding your question, it's hard to say without knowing more. In some cases, the sleep is wrong, or the wrong window is active. WinWaitActive is often helpful in such situations.
alanj
Posts: 3
Joined: 22 Oct 2021, 05:42

Re: Run a 2 step close down of a program

Post by alanj » 22 Oct 2021, 08:07

Apologies for the scarcity of info :o

I'm running a text to speech program called NVDA. When running, it will reside in the taskbar and it and its settings can be controlled via keyboard shortcuts
User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Run a 2 step close down of a program

Post by mikeyww » 22 Oct 2021, 09:48

Thank you. You could adjust my script accordingly, and see whether it works. Change notepad to the name of the NVDA process.
alanj
Posts: 3
Joined: 22 Oct 2021, 05:42

Re: Run a 2 step close down of a program

Post by alanj » 22 Oct 2021, 10:40

Thanks for your help with this - Some fun trying out your suggestions over the weekend ahead
Post Reply

Return to “Ask for Help (v1)”