34

Is there a shortcut in Windows 7 to switch between windows in a given application only? I very much like this feature in OS X; what is its equivalent in Windows?

migrated from stackoverflow.com Jun 12 '12 at 5:08

This question came from our site for professional and enthusiast programmers.

  • 1
    Related (but for Linux): Linux Mint – switch between windows of the same application. – Scott Sep 23 '17 at 4:16
  • <rant>I wish Redmond would focus on UX and add more Windows key shortcuts, like for this question. They give us 99% of stuff we don't want but don't just make our lives easier by making Windows easier to use. I guess it would take a junior programmer all of two hours to add a new shortcut for this.</rant> – Pete Alvin May 15 '18 at 14:04

11 Answers 11

42

If it is one of the first ten applications on the taskbar, then (Win)+n, where n is its position number, will select it and cycle through the windows.  (Use 0 (zero) for the tenth application.)  For example, I have Windows Explorer and Internet Explorer pinned as the first two things on my taskbar, so I can use +1 to cycle through my directories and +2 to cycle through my browsers.


Some odd notes:

  • If you press and hold and type (and release) a digit n, Windows will open the nth application on the taskbar.  Repeatedly tapping n will cycle through the windows of that program, as discussed above.  As stated by TranslucentCloud, if you then type Shift+n, it will cycle through them in reverse order, as with Alt+Tab and Ctrl+Tab, etc.

    If the nth application on the taskbar is pinned but not running, then +n will start it. 

  • But, if you press and hold and Shift, right from the beginning, and then type n, Windows will start a new instance (or at least a new window) of that application, even if it’s already running.  (This will fail for some applications, like Windows Media Player, that don’t allow multiple windows to run simultaneously.)
  • +n seems not to work with the numeric keypad.
  • 1
    This doesn't seem to work on a multi screen setup where you extend the taskbar – Erfan Feb 20 '15 at 3:35
  • 1
    Great. And Win+Shift+1 cycles through windows reversely. – TranslucentCloud Jan 10 '18 at 13:23
24

In Windows 7 and 8, although there is no shortcut I know of available from the keyboard alone, you can hold Ctrl while clicking the taskbar icon of the app you're interested in. Each time you do this a different window belonging to that app will come to the forefront.

In addition, the program VistaSwitcher sets up Win+F11 and Alt+` to switch between the current app's windows. (BTW, its web site says Windows 8 is not supported, but I've had luck with it under 8.1; the only problem I've seen so far is that it sometimes lists things like the search sidebar as open windows. I just ignore that, but YMMV.)

  • 2
    HUGE quality of life improvement. While a dedicated hotkey would be more ideal, the WIN+# solution is severely limited by number of keys, poor ergonomics, and a dreadful delay, not to mention creating conflict between accessible hotkeys (1-4) and desired start bar location. – bpcookson Sep 8 '15 at 11:43
  • 1
    VistaSwitcher is beautiful. Thanks for the suggestion. – Dustin Oprea Mar 9 '16 at 19:34
  • You can also add items to the exclude list like the "New notification" and "Cortana" on Windows 10. – dragon788 May 29 '16 at 23:02
  • 1
    i love vista switcher program. – Luke Oct 24 '16 at 8:28
  • 1
    looks like the successor to vistaswitcher, which is named alt-tab terminator doesn't have the feature to tab between same application anymore – starcorn May 7 at 8:00
21

You can use AutoHotkey: www.autohotkey.com

And put this script there:

!`:: ; Next window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
    Return
Else
WinGet, List, List, % "ahk_class " ActiveClass
Loop, % List
{
    index := List - A_Index + 1
    WinGet, State, MinMax, % "ahk_id " List%index%
    if (State <> -1)
    {
        WinID := List%index%
        break
    }
}
WinActivate, % "ahk_id " WinID
return

!^`:: ; Last window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
    Return
Else
WinGet, List, List, % "ahk_class " ActiveClass
Loop, % List
{
    index := List - A_Index + 1
    WinGet, State, MinMax, % "ahk_id " List%index%
    if (State <> -1)
    {
        WinID := List%index%
        break
    }
}
WinActivate, % "ahk_id " WinID
return

Works very well for me. Using Autohotkey I also made my copy/paste/undo,... keys like Mac. Works great!

Eras

  • 1
    This works great with some caveats: 1) For Chrome, it will cycle all Chrome-like windows including applications like Slack! 2) For modern apps -- and if you only have one modern-app window open -- it will open a random other modern app (i.e. if you have Calendar open and that's the only modern app open, it will open "Settings", or "Sports", or "Mail", etc.) – Kirk Woll Mar 7 '16 at 22:02
  • @KirkWoll That's right. There is definitely room to improve it. I have not had the time to really dig into Autohotkey to make it happen... – Seperman Mar 9 '16 at 18:53
  • Great job, used it right away, thanks. A few points: WinGet, List returns the number of windows in the List variable (as opposed to the List%n% pseudoarray in which the handles are stored), so you can skip the WinGet, WinClassCount call and check for List instead. Also, the code seems to be identical for both hotkeys. – Lebenita Sep 1 '16 at 7:01
  • it's doens't work with me on Windows 10 64bit and Microsoft Office 2016. can you help ? – Luke Oct 24 '16 at 8:23
  • 1
    This works well, however, it seems to switch between ALL windows regardless of desktop. I am using task view extensively and need to jump through windows on the same desktop only. – petr Nov 23 '16 at 18:36
8

Thanks, Erasmose, but your version of the autohotkey script will minimize a window if there are no other windows of that type. Sometimes you don't know, and minimizing is an annoying way to find out, so I modified your script like so:

!`::    ; Next window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
    Return
Else
WinSet, Bottom,, A
WinActivate, ahk_class %ActiveClass%
return

!+`::    ; Last window
WinGetClass, ActiveClass, A
WinActivateBottom, ahk_class %ActiveClass%
return

oh, and I also changed last class to use shift instead of ctrl since I that's the modifier to go backwards with several other keyboard shortcuts. I love autohotkey.

  • 1
    Cool. I updated my code based on yours and also a feedback I got on Autohotkey's forum. The new code won't loop through minimized windows just like how it is in Mac. – Seperman Oct 17 '14 at 4:09
  • @Seperman what if I want to loop through minimized windows as well. What do I have to change in your script to do that. – Ghos3t Mar 9 '18 at 9:42
7

Some applications that implement MDI provide Ctrl+Tab to switch between "Documents" under the same application instance. e.g. MS Office. But this is not a windows feature and is application dependent. For other software there are different short-cuts. e.g. Firefox does not provide this feature but there is an add-on that adds the functionality.

Additionally, here's a list of keyboard shortcuts provided in windows.

Also, there are existing discussions about Keyboard short-cuts in Windows.

Hope that helps.

  • 2
    Also, some programs use (Ctrl)+(F6) for this. (Add (Shift) to reverse direction.) – Scott Jan 15 '14 at 22:16
5

Easy Windows Switcher from Neosmart does exactly what you are after.

Here is the description from the Easy Windows Switcher Website

Easy Window Switcher makes switching between different windows as easy as alt+` (that's alt+backtick) like on a Mac. Forget having to alt+tab between a million-and-one different open windows to find the one you are looking for, with Easy Window Switcher, tabbing between windows of the same program is only a alt+` away.

  • 1
    doesnt "always" work. If I'm working on a different application for some time, then come back, it stops working. – Dushyant Bangal Aug 25 '17 at 7:55
4

VistaSwitcher allows or for this feature. Its compatible with Windows 10, (although the name suggests otherwise). On Windows 8 and up, I suggest adding certain metro apps to the exclude list.

The top answer is good, but doesn't work on multi-monitor setups where the taskbar is set to only show icons on active monitor.

  • Win + n does work on my W7 system with multiple screens and the taskbar showing on main monitor only – is this what you meant or is there really a way to make the taskbar switch to the currently active monitor (which I imagine would be distracting)? – Lebenita Sep 1 '16 at 5:24
1

In addition to what Scott (https://superuser.com/users/150988/scott) shared:

ctrl+repeatedly click over the app icon in the task-bar also will do the job.

  • 1
    (this answer already given by another user) – Pete Alvin May 15 '18 at 14:07
1

With AutoHotkey too, a more natural behavior:

; Switch between windows of the same application with Alt+(key above Tab)
; Icon: made by Freepik (www.freepik.com), licence CC 3.0 BY
;       from https://www.flaticon.com/free-icon/switch-window_71630
; Script Licence: CC0 (Public Domain)
; Source: https://framagit.org/dr4Ke/AutoHotkey_scripts

KeyName := GetKeyName("sc029")
Menu, Tray, Tip, Switch between windows of the same applications with 'Alt+%KeyName%'

*!SC029::
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
If WinClassCount = 1
    Return
WinGet, List, List, % "ahk_class " ActiveClass

index := 0
if not GetKeyState("Shift") {
    index := 1
}
;MsgBox, Entering Loop
While GetKeyState("Alt") {
    If GetKeyState("Shift") {
        index := Mod(List + index - 2, List) + 1
    } else {
        index := Mod(List + index, List) + 1
    }
    WinGet, State, MinMax, % "ahk_id " List%index%
    if (State == -1)
    {
        continue
    }
    WinID := List%index%
    WinActivate, % "ahk_id " WinID
    ErrorLevel := 1
    sleep 50
    While (ErrorLevel != 0) and GetKeyState("Alt") {
        KeyWait, sc029, DT1
    }
}
return
0

I created an AutoHotkey script that integrates nicely with Windows Task Switcher (Alt+Tab), providing all of its benefits: previews of app windows, click to select, arrow key navigation, only activate the single window that you want. Invoke/navigate with Alt+` and Alt+Shift+` (backtick) to cycle between windows having the same process name as the current window. I find this more usable than Win+num as it works for any app (rather than having to remember the pinned slot number), window previews are larger, the background doesn't get blurred and it mixes seamlessly with Alt+Tab navigation. Tested on Windows 10.

The main trick is to temporarily hide non-target application windows from Task Switcher by setting WS_EX_TOOLWINDOW and unsetting WS_EX_APPWINDOW. In order to set these windows styles on windows running as administrator, AutoHotkey needs to be signed or run as admin. I followed the very easy signing instructions here.

Some related threads that contributed:

!`::
{
   WS_EX_TOOLWINDOW = 0x80
   WS_EX_APPWINDOW = 0x40000
   tw := []
   aw := []

   WinGet, processName, ProcessName, A

   DetectHiddenWindows, Off
   AltTab_window_list(1)

   Loop, %AltTab_ID_List_0%
   {
      wid := AltTab_ID_List_%A_Index%
      WinGet, processName2, ProcessName, ahk_id %wid%

      if (processName2 != processName)
      {
         WinGet, exStyle2, ExStyle, ahk_id %wid%

         if (!(exStyle2 & WS_EX_TOOLWINDOW))
         {
            tw.InsertAt(0, wid)
            WinSet, ExStyle, ^0x80, ahk_id %wid%
         }

         if ((exStyle2 & WS_EX_APPWINDOW))
         {
            aw.InsertAt(0, wid)
            WinSet, ExStyle, ^0x40000, ahk_id %wid%
         }
      }
   }

   Send {Alt Down}{Tab} ; Bring up switcher immediately

   KeyWait, ``, T.25  ; Go to next window; wait .25s before looping
   if (Errorlevel == 0)
   {
      While ( GetKeyState( "Alt","P" ) )
      {
         KeyWait, ``, D T.25
         if (Errorlevel == 0)
         {
            if (GetKeyState( "Shift","P" ))
            {
               Send {Alt Down}{Shift Down}{Tab}
               Sleep, 200
            }
            else
            {
               Send {Alt Down}{Tab}
               Sleep, 200
            }
         }
      }
   }

   Send {Alt Up} ; Close switcher on hotkey release

   for index, wid in tw
   {
      WinSet, ExStyle, ^0x80, ahk_id %wid%
   }

   for index, wid in aw
   {
      WinSet, ExStyle, ^0x40000, ahk_id %wid%
   }
}
return

AltTab_window_list(excludeToolWindows)
{
   global
   WS_EX_CONTROLPARENT =0x10000
   WS_EX_APPWINDOW =0x40000
   WS_EX_TOOLWINDOW =0x80
   WS_DISABLED =0x8000000
   WS_POPUP =0x80000000
   AltTab_ID_List_ =0
   WinGet, Window_List, List,,, Program Manager ; Gather a list of running programs
   id_list =
   Loop, %Window_List%
   {
      wid := Window_List%A_Index%
      WinGetTitle, wid_Title, ahk_id %wid%
      WinGet, Style, Style, ahk_id %wid%

      If ((Style & WS_DISABLED) or ! (wid_Title)) ; skip unimportant windows
         Continue

      WinGet, es, ExStyle, ahk_id %wid%
      Parent := Decimal_to_Hex( DllCall( "GetParent", "uint", wid ) )
      WinGetClass, Win_Class, ahk_id %wid%
      WinGet, Style_parent, Style, ahk_id %Parent%

      If ((excludeToolWindows & (es & WS_EX_TOOLWINDOW))
         or ((es & ws_ex_controlparent) and ! (Style & WS_POPUP) and !(Win_Class ="#32770") and ! (es & WS_EX_APPWINDOW)) ; pspad child window excluded
         or ((Style & WS_POPUP) and (Parent) and ((Style_parent & WS_DISABLED) =0))) ; notepad find window excluded ; note - some windows result in blank value so must test for zero instead of using NOT operator!
         continue
      AltTab_ID_List_ ++
      AltTab_ID_List_%AltTab_ID_List_% :=wid
   }  
   AltTab_ID_List_0 := AltTab_ID_List_
}

  • Oops; our edits got crossed up.  I tried to put Humpty Dumpty back together again; please check that your code is what you meant it to be. – Scott Feb 17 at 16:57
0

I created an AutoHotkey script to switch between same application's windows that work with regular Window Apps, Chrome Shortcuts and Chrome Apps.

https://github.com/JuanmaMenendez/AutoHotkey-script-Open-Show-Apps/blob/master/AutoHotkey-script-Switch-Windows-same-App.ahk

Extra

In that Github repo there is another AutoHotkey script that could work well in tandem with this one, because you will be able to Open, Restore or Minimize your Apps using the hotkeys you want.

Example:

  • F7:: OpenOrShowAppBasedOnExeName("C:\Windows\System32\SnippingTool.exe")
  • F8:: OpenOrShowAppBasedOnWindowTitle("Gmail", "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --app=https://mail.google.com/mail/")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.