A
A
Anton Kiselyov2018-05-14 14:51:20
Programming
Anton Kiselyov, 2018-05-14 14:51:20

How to run the program with a hotkey once? Will the batch fit?

There are several different programs that I launch with global hotkeys.
When you press the hotkey again, two scenarios of behavior are obtained, depending on the program:
1. "Correct" behavior: the software expands if it was minimized, or the focus is simply transferred to it
2. "Incorrect": a duplicate of the program is launched
How to make it always when you click on the hotkey again, the behavior was according to scenario 1. "correct"?
If this can be done through a batch file (on which .lnk with a hotkey is then made), I will be grateful for a piece of code.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2018-05-14
@Stalker_RED

The scheme is something like this: check whether the program is already running (this can also be done through a batch file)
Depending on the result of the check, launch it or activate an existing window.
For the activation of the window, only a batch file, without third-party programs, is not enough.
wsh has a wsh.AppActivate() method that will put the focus on the desired window by its title, for example

var wsh = WScript.CreateObject("WScript.Shell");
wsh.AppActivate("Notepad");

R
res2001, 2018-05-14
@res2001

In the batch file, you can catch whether the process is running using the tasklist filters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question