Open and close a program using the same hotkey (Autohotkey?)

I am trying to open and close a program (eg Notepad) with the same hokey on Windows, say Strg + Alt + X. Therefore, when the program is closed, I want to open it with "X", and when it is open, I want to close her using the "X".

This is very easy to do with two hot keys: one to open and one to close the program. But I do not know how to do this for the same hotkey. Can someone point me in the right direction? Perhaps this is possible with Autohotkey?

+4
source share
2 answers

I believe that this is what you are looking for. I created the StartClose method for future use if you want to also create keyboard shortcuts for other applications. You can find window titles and classes using Window Spy, which can be found by right-clicking your autorun icon.

 x::StartClose("ahk_class Notepad", "notepad.exe") StartClose(title, exe) { IfWinExist, %title% WinClose else { Run, %exe% WinActivate } } 
+5
source

Elliot's answer pointed me in the right direction (I am completely unfamiliar with the AutoHotKey syntax). His approach uses a window title that works well for programs that don't come down to a system drive. But if you have such a program, it is better to close it based on the process identifier:

 ^!x::StartClose("XMouseButtonControl.exe") StartClose(exe) { Process, Exist, %exe% ; check to see if program is running If (ErrorLevel = 0) ; If program is not running -> Run { Run, %exe% } Else ; If program is running, ErrorLevel = process id for the target program -> Close { Process, Close, %ErrorLevel% } } 
0
source

Source: https://habr.com/ru/post/1446273/


All Articles