35

I am looking for a way to switch between two open windows of the same app with a key shortcut, I have found this https://neosmart.net/EasySwitch/ but it is not open source and I don't trust it even works. Does anyone has an alternative ? This is OOTB in Unity and Mac OS it is absurd that Windows doesn't have it.

Some time ago a Microsoft employee made this tool : https://switcher.en.softonic.com/ not sure what is the official website, it is GREAT but works only on Windows 7 and doesnt work on 10, also not open source.

The closest thing I have found that is open source is this one https://github.com/JochenBaier/fastwindowswitcher but is less then ideal.

is there an alternative ?

JOKe
  • 451
  • 1
  • 4
  • 4
  • 7
    alt+tab switches between ALL windows of ALL applications. in Mac OS (Cmd+Tab) and Linux (Alt+Tab) it works the same, however both Mac OS and Ubuntu Unity have a "switch between Windows in the same app" which is ALT+ ` or CMD + ` respectively, this doesnt seems to exist in Windows. – JOKe Nov 25 '20 at 11:11
  • 1
    I find if you hold Alt and just quickly tap Tab it will switch back and forth between the two most recently focussed windows regardless of how many other windows are open. It doesn't cycle through all windows, only back and forth between two of them. It's only if I hold Alt+Tab down for longer that I get the other behaviour. – RedGrittyBrick Nov 25 '20 at 11:19
  • Hey @RedGrittyBrick yes but this doesn't help if you have 3 windows :) It kinda helps for 2 :) indeed. – JOKe May 10 '22 at 14:37
  • 1
    duplicates: [Shortcut in Windows 7 to switch between same application's windows, like Cmd + ` in OS X](https://superuser.com/q/435602/241386), [What's the windows 10 equivalent of "Command `" on a mac](https://superuser.com/q/1043932/241386), [Windows 8: Switch between windows of current application](https://superuser.com/q/621140/241386) – phuclv May 16 '22 at 08:36
  • You've tried Ctrl + Tab? – Arctiic May 09 '23 at 20:40

5 Answers5

30

You may implement the Alt+` shortcut yourself using the free AutoHotkey.

The following script will cycle through all the windows of the active process:

!`::
WinGetClass, OldClass, A
WinGet, ActiveProcessName, ProcessName, A
WinGet, WinClassCount, Count, ahk_exe %ActiveProcessName%
IF WinClassCount = 1
    Return
loop, 2 {
  WinSet, Bottom,, A
  WinActivate, ahk_exe %ActiveProcessName%
  WinGetClass, NewClass, A
  if (OldClass <> "CabinetWClass" or NewClass = "CabinetWClass")
    break
}

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

Useful AutoHotkey documentation:

harrymc
  • 455,459
  • 31
  • 526
  • 924
29

There are three ways for doing this:

  1. You can hold Ctrl + Click on the icon of the app in the taskbar
  2. Use Win + position of app on taskbar. For example, if Google Chrome is on third position, do Win+3 to switch between windows of Chrome. Note that this cycles through the different windows, so for opening 4th window you'll have to press 3 four times.
  3. The fastest of all, Using Win + ctrl + n does exactly what you want. (where n is position of the app on taskbar)

Note that in 2nd and 3rd options if n is specified such that no window of that program is already open, windows will open a new window. This effect can also be acheived by pressing Win + shift + n, regardless of if windows of that app were already open or not.

Saaransh Garg
  • 2,596
  • 14
  • 27
  • 2
    What if n is greater than 9 ? – Lucifer May 18 '22 at 11:16
  • 1
    @Lucifer, make it lesser than 9 :P. Okay, sorry, there is no real way to do this but you can def rearrange taskbar programs – Saaransh Garg May 18 '22 at 11:31
  • 2
    This is a good option as does not need to install and add something to OS. Of course with the limitations as mentioned above. – jethar Aug 13 '22 at 07:35
  • 2
    In my opinion this does not answer the OP well because you need to remember the order of windows in the taskbar and also I would assume that using the mouse is not an option here – elonderin Oct 20 '22 at 04:21
  • 1
    3rd option is nice, thanks! – amordo Nov 14 '22 at 11:47
  • 1
    I remapped the third option to `win` + `n` with Microsoft PowerToys. works even faster than ubuntu. – Mizu Haque Mar 19 '23 at 09:30
  • Can you use PowerToys to actually switch between windows of the same app without catering to their order, as the OP asked and as you can do out of the box e.g. on Ubuntu? – matt May 06 '23 at 09:45
6

I've updated the script of harrymc to be executable in AutoHotkey v2:

#Requires AutoHotkey v2.0

!`::{
  OldClass := WinGetClass("A")
  ActiveProcessName := WinGetProcessName("A")
  WinClassCount := WinGetCount("ahk_exe" ActiveProcessName)
  IF WinClassCount = 1
      Return
  loop 2 {
    WinMoveBottom("A")
    WinActivate("ahk_exe" ActiveProcessName)
    NewClass := WinGetClass("A")
    if (OldClass != "CabinetWClass" or NewClass = "CabinetWClass")
      break
  }
}

From this it should also be easy to convert the script of EugeneK.

I tried to implement EugeneK's script as well in v2. I'm not sure if it has all the intended features, but it works fine and will be what I'll be using

#Requires AutoHotkey v2.0

!`::
{
    win_id := WinActive("A")
    win_class := WinGetClass("A")
    active_process_name := WinGetProcessName("A")
    ; We have to be extra careful about explorer.exe since that process is responsible for more than file explorer
    if (active_process_name = "explorer.exe")
        win_list := WinGetList("ahk_exe" active_process_name " ahk_class" win_class)
    else
        win_list := WinGetList("ahk_exe" active_process_name)
    
    ; Calculate index of next window. Since activating a window puts it at the top of the list, we have to take from the bottom.
    next_window_i := win_list.Length
    next_window_id := win_list[next_window_i]
    
    ; Activate the next window and send it to the top.
    WinMoveTop("ahk_id" next_window_id)
    WinActivate("ahk_id" next_window_id)
}

In addition: I like having this functionality tied to the key Alt + |. So, in case you also like this better, change !':: to !|::.

9cco
  • 61
  • 1
  • 2
  • Is it possible to have a version which also displays a preview of a window (like Ubuntu) or at least a list – Lutosław Jul 31 '23 at 17:23
2

I've modified ahk script in order to have an Ubuntu style switching. Pressing ` while holding an alt key will cycle through all application windows putting the next one on top rather than sending top window to the bottom. And single alt + ` combinations will cycle between last two windows.

!`::
WinGet, ActiveProcessName, ProcessName, A
WinGet, WinClassCount, List, ahk_exe %ActiveProcessName%

if (WinClassCount = 1)
    return

if (NextWindow = "")
    NextWindow := 2

element := % WinClassCount%NextWindow%

WinSet, Top,, ahk_id %element%
WinActivate, ahk_id %element%

NextWindow += 1

if (NextWindow > WinClassCount || !getKeyState("Alt"))
    NextWindow := 2

return
EugeneK
  • 21
  • 1
2

I've implemented a script using AutoHotkey v2 which does what Ubuntu can do out of the box: switch between windows of the current app by pressing Alt+; (which is what the key in the top left corner types by default on my keyboard layout; you will probably want to adjust for yourself).
It counts with multiple presses so works even in cases there are multiple windows of the app, not just two. Feel free to use, PRs for improving welcome :-D

https://github.com/jendakol/autohotkey/blob/main/window-switch-multiple.ahk

Current version:

!;::
{
    static LastRun := 0
    static QuickPress := 0

    Now := A_TickCount

    if (Now - LastRun < 400)
        QuickPress++
    else
        QuickPress := 0

    OutputDebug '`n`nNow: ' Now ' LastRun: ' LastRun ' QuickPress: ' QuickPress '`n'



    OldClass := WinGetClass("A")
    ActiveProcessName := WinGetProcessName("A")
    WinClassCount := WinGetCount("ahk_exe " ActiveProcessName)
    ActiveId := WinGetID("A")
    OutputDebug 'Current:    ' ActiveId '/' OldClass '/' ActiveProcessName '/' WinGetTitle("ahk_id" ActiveId) "`n"

    if (WinClassCount = 1)
        Return

    ToSkip := QuickPress
    OutputDebug 'Will skip ' ToSkip ' of ' WinClassCount '`n'

    ids := WinGetList("ahk_exe " ActiveProcessName)
    for SiblingId in ids {
        if (WinGetClass("ahk_id" SiblingId) != OldClass)
            continue

        OutputDebug 'Found:      ' SiblingId '/' WinGetClass("ahk_id" SiblingId) '/' WinGetProcessName("ahk_id" SiblingId) '/' WinGetTitle("ahk_id" SiblingId) '`n'

        if (SiblingId != ActiveId && ToSkip-- <=0) {
            OutputDebug 'Switch to:  ' SiblingId '/' WinGetClass("ahk_id" SiblingId) '/' WinGetProcessName("ahk_id" SiblingId) '/' WinGetTitle("ahk_id" SiblingId) '`n'
            WinActivate("ahk_id" SiblingId)
            break
        }
    }


    LastRun := A_TickCount
}
jenda
  • 121
  • 3
  • Is it very stable to use on Windows 11? – matt May 06 '23 at 09:46
  • This is the only one that worked as expected. You should paste the code here and add instructions on modifying the key to make it work with the backtick. – vega May 23 '23 at 17:33
  • @matt I use it quite often. It seems stable, yes :) – jenda May 25 '23 at 10:46
  • 1
    @vega Thanks! I did post the repo link instead intentionally so anyone can get the most updated version every time I commit it ;-) – jenda May 25 '23 at 12:01
  • @jenda yes this is true, however on SE, links to answers are not considered answers, see https://meta.stackoverflow.com/questions/265552/when-to-flag-an-answer-as-not-an-answer. You'd be surprised, I've often been helped by 10 year old answers with code where the links didn't work anymore. I think this is why SE asks for code instead of links. But you are free to link to your repo of course. Cheers. – vega May 25 '23 at 17:00
  • 1
    @vega I know the reason but... OK, let me add current version and keep the repo link so everyone is happy :) Cheers – jenda May 26 '23 at 17:16