Toggle among several apps with single key stroke Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fazlul Haque
Posts: 12
Joined: 15 Jun 2021, 22:03

Toggle among several apps with single key stroke

15 Jun 2021, 22:34

Hello everyone,
I am a new member of this community.
I am trying to learn the script for my personal use.

On windows 10 most of the time I work with apps like Word, Excel, Abobe Acrobat, Chrome, Notepad etc. I don't like Windows' built-in Alt+Tab toggle command.

Could you please help me with a script that toggle among several apps with a single key stroke when I wish to toggle?

Since I am a newbie, I would like simpler scripts.
I am using Version 1.1.33.09

Thanks in Advance
Fazlul
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Toggle among several apps with single key stroke

16 Jun 2021, 06:27

Code: Select all

F3::
hwnd := []
WinGet, win, List
Loop, %win% {
 WinGet, proc, ProcessName, % "ahk_id " win%A_Index%
 proc := StrReplace(proc, ".exe")
 If proc in WINWORD,EXCEL,Acrobat,chrome,notepad
  hwnd.Push(win%A_Index%)
}
If !hwnd.Count() {
 SoundBeep, 1000
 Return
}
If WinActive(act := "ahk_id " hwnd.1) {
 If hwnd.Count() > 1 {
  WinSet, Bottom
  WinActivate, % "ahk_id " hwnd.2
 } Else SoundBeep, 1500
} Else WinActivate, %act%
Return
Fazlul Haque
Posts: 12
Joined: 15 Jun 2021, 22:03

Re: Toggle among several apps with single key stroke

16 Jun 2021, 08:56

Thank you .....

but there are some problems.
1. I can toggle forward from first app to the last, but cannot toggle back
2. It is not working properly if I open 4 apps.

I have a question here:
If I want to write the names of the apps in the script (eg, Chrome, Word, Adobe Acrobat), what should be the script like?

Thanks in advance.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Toggle among several apps with single key stroke

16 Jun 2021, 09:18

How would you distinguish between stepping (toggling) forward and back with a single keystroke?
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Toggle among several apps with single key stroke

16 Jun 2021, 09:20

I was thinking the same as boiler. This script worked for me when I opened multiple windows of different kinds that are shown in the list of process names. You could change that list to whatever you like. The process list that I used is the same as the one that you provided.
Fazlul Haque
Posts: 12
Joined: 15 Jun 2021, 22:03

Re: Toggle among several apps with single key stroke

16 Jun 2021, 09:25

boiler wrote:
16 Jun 2021, 09:18
How would you distinguish between stepping (toggling) forward and back with a single keystroke?
Got the point, thanks.
Fazlul Haque
Posts: 12
Joined: 15 Jun 2021, 22:03

Re: Toggle among several apps with single key stroke

17 Jun 2021, 04:43

mikeyww wrote:
16 Jun 2021, 09:20
I was thinking the same as boiler. This script worked for me when I opened multiple windows of different kinds that are shown in the list of process names. You could change that list to whatever you like. The process list that I used is the same as the one that you provided.
Is it possible to use GroupAdd and GroupActivate here?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Toggle among several apps with single key stroke

17 Jun 2021, 04:56

That should work and be a pretty simple solution.
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Toggle among several apps with single key stroke

17 Jun 2021, 06:15

A great idea! Probably better than what I wrote.
Fazlul Haque
Posts: 12
Joined: 15 Jun 2021, 22:03

Re: Toggle among several apps with single key stroke

17 Jun 2021, 06:54

mikeyww wrote:
17 Jun 2021, 06:15
A great idea! Probably better than what I wrote.
I knew about it , but unfortunately I don't know how to write the script, because I am a newbie in this whole ocean of scripts.
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Toggle among several apps with single key stroke

17 Jun 2021, 07:20

Code: Select all

GroupAdd, procs, ahk_exe WINWORD.exe
GroupAdd, procs, ahk_exe EXCEL.exe
GroupAdd, procs, ahk_exe Acrobat.exe
GroupAdd, procs, ahk_exe chrome.exe
GroupAdd, procs, ahk_exe notepad.exe
F3::GroupActivate, procs, R
Fazlul Haque
Posts: 12
Joined: 15 Jun 2021, 22:03

Re: Toggle among several apps with single key stroke  Topic is solved

18 Jun 2021, 08:59

mikeyww wrote:
17 Jun 2021, 07:20

Code: Select all

GroupAdd, procs, ahk_exe WINWORD.exe
GroupAdd, procs, ahk_exe EXCEL.exe
GroupAdd, procs, ahk_exe Acrobat.exe
GroupAdd, procs, ahk_exe chrome.exe
GroupAdd, procs, ahk_exe notepad.exe
F3::GroupActivate, procs, R
Thank you very much. It is working great!
You are really helpful.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 219 guests