(On OP request, I moved answer from comments here)
If you'd like to try 3rd party program, you may try AutoHotKey (let use abbreviation AHK further)
It is open sourced long living project that allow to assign in various way "Hot Keys" to any programs as well to operation system. It isn't limited to common Ctrl+ combinations but also allows creating phrase as string for various automation. It could be just a simple hot key assigner or full feature automation powerful scripts that may be used practically as replacement for bat
, cmd
, vbs
, ps
scripts.
The simplest usage case as OP asked - it could be just a single string in AHK script that looks like:
F4::WinActivate, ahk_exe /full/path/to/program_that_need_to_be_activated
Where F4
- a hot key (functional key on the keyboard), but can be practicality any combinations of keys and even strings.
It could be automated further, for example, - by pressing F4
activate required program and if it isn't running process then start and activate(set focus and bring it to front aka set Z index) this way script would looks like:
F4:: ; Comment: Use F4 key to activate or start firefox
{
if WinExist("ahk_exe firefox.exe")
WinActivate, ahk_exe firefox.exe
else
Run, firefox.exe
}
Return
; next is hot key for another program
; We assigning here Windows key + z to activate Notepad++
#z::
{
np = C:\Program Files (x86)\Notepad++\notepad++.exe
if WinExist("ahk_exe %np%")
WinActivate, ahk_exe "%np%"
else
Run, "%np%"
}
Return
; Find and activate Firefox by Windows class by WinKey+x
DetectHiddenWindows, On
#x::
{
fp = C:\Program Files\Mozilla Firefox\firefox.exe
if WinExist("ahk_class MozillaWindowClass")
WinActivate, ahk_class MozillaWindowClass
else
Run, "%fp%"
}
Return
AHK is pretty easy to setup and it comes with rich chm
(help) file that cover a lot of user cases that include examples from how to set AHK GUI interface and up to using COM objects for automation. AHK scripts can be combined in a single script file or it can be multiple files that can be started on demand.
AHK supporting script compilation that simplify its distribution as compiled program that do the same as standalone AHK setup
P.S.
Below is AHK solution for the Firefox
with extension MinTrayR (that hide firefox in system tray)
I tried to find more elegant solution but after looking at MinTrayR source code, I found that it doesn't use WM_USER
windows messages and accepts only standard OS messages that will require a lot of effort find correct handle of firefox button in system tray programmatically. While I believe it still possible, I used below another strategy: AHK script searching for particular image(firefox's icon in the system tray) on the screen and double click it on hot key pressing.
While it easy to implement it would require some initial steps on user's side:
- Minimize Firefox (FF further).
Make sure that FF icon is visible in sys.tray
(In the Control Panel\All Control Panel Items\Notification Area Icons
set Firefox status as Show icon and notification
)
- Press PrintScreen while the FF icon is visible in the
system tray. (This places a screenshot on the clipboard.)
- Open an image processing program such as
Paint
.
- Paste the contents of the clipboard (that is, the screenshot).
- Select a region that does not vary and that is unique to the
Firefox's icon in the system tray. (Select it as close as possible to catch only globe with fox on it. Use zooming to precisely select icon's area )
Crop
selected area and save it as C:\Users\Public\Pictures\ff.png
After that you can start using following AHK script to maximize Firefox from system tray or start a new instance of Firefox if it not running by pressing WinKey+v hot keys.
(If you using 32bits version of Firefox, replace string
C:\Program Files\Mozilla Firefox\firefox.exe
with
C:\Program Files (x86)\Mozilla Firefox\firefox.exe
)
#NoEnv
#v::
{
ffIconFile = C:\Users\Public\Pictures\ff.png
fp = C:\Program Files\Mozilla Firefox\firefox.exe
Processname=firefox.exe
Process, Exist, %Processname%
If !ErrorLevel
{
MsgBox, % "Process " Processname " does not exist. Going to start a new one"
Run, "%fp%"
Return
}
pid := ErrorLevel
IfWinNotActive, % "ahk_pid " pid
{
CoordMode Pixel
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, %ffIconFile%
if ErrorLevel = 2
MsgBox Could not conduct the search (icon file path ?).
else if ErrorLevel = 1
MsgBox Firefox icon could not be found on the screen.
else
{ ; MsgBox The icon was found at %FoundX%x%FoundY%.
x := FoundX + 10
y := FoundY + 10
Click %x%, %y%, 0
Click 2
}
}
}
Return
F3::WinActivate, Firefox ; activate my browser
– Alex Feb 6 '17 at 9:28