guilryder / clavier-plus

Clavier+ keyboard shortcuts manager for Windows
https://gryder.org/software/clavier-plus/
GNU General Public License v3.0
334 stars 22 forks source link

[Feature Request] press hotkey to launch a program, press hotkey a second time to minimse/close the program (toggle). #40

Closed KXDyana closed 7 months ago

KXDyana commented 1 year ago

It would be convenient to add an option for hotkeys to toggle on programs which would only have a single instance in the system(e.g. Spotify). Press the hotkey once to launch the program, and if the program is active as a window, press the same hotkey to minimise or close the program.

A working example it the hotkey provided by Wechat to show/hide the program.

guilryder commented 12 months ago

This use case looks similar to what the [{FocusOrLaunch,...}] command does, with the added complexity of "minimize or close". (There's a difference between minimizing and closing a window, and the way to do so is sometimes program-specific.)

Depending on how Spotify works you might be able to use [[...]] to launch Spotify, immediately followed by [{Focus,...}] to find it if was already launched and stop the shortcut if not, then finally simulate a keystroke to minimize or close it. The "Enable for" feature could be handy too and allow you to create 2 different shortcuts depending on whether Spotify is active.

In any case, the necessary mechanism seems too complex for Clavier+ to offer natively. Consider writing a script instead that does what you need, and triggering the script via Clavier+.