Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

cycleWindow()


  • Please log in to reply
26 replies to this topic
JonS
  • Members
  • 49 posts
  • Last active: Sep 26 2013 01:20 AM
  • Joined: 10 Sep 2010
cycleWindow()

A different but faster approach to window-switching, or an alternative to Alt-Tab.

In a nutshell

Allows one to tab through a narrowed subset of windows, as one normally alt-tabs through the set of all visible windows. This is done by assigning a single function-call to a single hotkey with the format "keyOne & keyTwo" (Hotkeys/Custom Combinations).

[slightly old] Video Demo

Parameters: cycleWindow(title, regExp, pathToRun)[*:2xh3zfkb]title - used to determine which windows are in the subset (e.g. windows that belong to a specific app). (see WinGet/Parameters/WinTitle)
  • regExp - used to trim each window's title for how it is displayed in the ListView. The 1st group of the regular expression gets displayed. If regExp is "0", the ListView will not be displayed at all. (see Regular Expressions (RegEx) - Quick Reference)
  • pathToRun - the path to launch the app, if necessary.
Examples
  • All Windows
LAlt & Tab::cycleWindow()
;overrides the default Alt-Tab hotkey in windows (but it can still be activated by using RAlt)
;cycles through all visible windows, just like the standard Alt-Tab
  • Notepad
CapsLock & n::cycleWindow("Notepad")
;cycles through all notepad window
;(specifically, windows with "notepad" in their title)
  • Windows Explorer
CapsLock & e::cycleWindow("ahk_class CabinetWClass")
;cycles through all open windows of Windows Explorer
  • MSPaint
CapsLock & p::cycleWindow("- Paint", "(.*) - Paint", "C:\Windows\System32\mspaint.exe")
;cycles through all MSPaint windows (specifically, windows with "- Paint" in their title)
;Titles are displayed in a ListView, each being trimmed according to the RegEx of the 2nd paramter.
;If no MSPaint windows exist, MSPaint is launched by running the path "C:\Windows\System32\mspaint.exe" in the 3rd parameter.
  • Internet Browserzzz
CapsLock & i::cycleWindow("|ahk_class MozillaUIWindowClass, ahk_class Chrome_WidgetWin_0, ahk_class OperaWindowClass, ahk_class IEFrame")
;cycles through browser windows belonging to Firefox, Chrome, Opera, or InternetExplorer
;the default regex is "([^-]*).*", so title-trimming for the ListView is already handled pretty well without a 2nd parameter.
This example uses the Inclusion/Exclusion feature for the 1st parameter. See the documentation.
  • Exclusions-Only
LAlt & Tab::cycleWindow("||ahk_class BasicWindow")
;cycles all windows, excluding Windows 7 Desktop Gadgets
Also uses Inclusion/Exclusion.

Documentation

cycleWindow.ahk
 
all verions




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Changes
5/10/2011-5/11/2011
- fixed thumbnail-sizing bug occuring when corresponding window was about full height of the screen (‘twas a silly mistake)
- removed obsolete cycleWindow_shrinkThumb setting
- removed Critical command from top of function, fixing some really weird issues resembling buffered hotkey threads (even though “#MaxThreadsBuffer” was off)
- fixed the highlight-fading’s “cutting-out” issue, which was mostly accomplished through the change immediately above
- added ability to change ListView width
The above changes constituted the 1.1 update

5/13/2011
- user can now cycle backwards on the first iteration (in the case that a window in the subset is already active), whereas before user could only cycle backwards on the second iteration and after.
- all parameters for cycleWindow are optional now
- the function always removes windows with blank titles from the list
- +).*” to display the title.
- +).*” as well, instead of “(.*)”

5/20/2011-6/1/2011
- Inclusion/Exclusion - much more flexible and complex way to narrow subset
- function only removes blank titles when the title parameter is blank (or excluded) or there are no inclusions specified within the title parameter (in the inclusion/exclusion mode)
- Added code that removes the specific “Start, ahk_class Button” window from the list rather than simply excluding all windows with “Start” in their title. This code is run whenever the removeBlankTitles code is run.
- modified default regexes
- ListView width is now set initially to 200
The above changes constituted the 1.2 update

6/2/2011
- Removed accidental “.” from the end of the line LV_Modify(i, “+Select”), which may have prevented use with AHK_L. (update 1.21)
- Tidied up code for removing extraneous windows. The code for removeBlankTitles will ALWAYS get run (as before). However, other extraneous windows, like “Start” and “Progman”, get removed when the title parameter is blank, or there are 0 inclusions.
- Fixed bug in removeStart code for “Start, ahk_class Button” where the last window in the list would be excluded. (update 1.22)


Candy_Monkey
  • Guests
  • Last active:
  • Joined: --
This reminds me of my favorite script, Find Firefox Tab! Of course, Find Firefox Tab cycles through FF tabs to find its target. :lol:

Posted Image

MasterFocus
  • Moderators
  • 4322 posts
  • Last active:
  • Joined: 08 Apr 2009
Looks great.
Any chances you include an "exclude title" mode?

j--hn
  • Members
  • 176 posts
  • Last active: Oct 26 2011 02:42 PM
  • Joined: 16 Apr 2011
Nice...

Just a suggestion, could you add generic function 'CycleCurrentWindow' so it would cycle on the current active window class only, for example if i press a hotkey while on firefox it would cycle through all firefox windows, and when i'm on notepad it would cycle through all notepad windows, etc. (i think its quite easy to implement :wink: ). Thank you...

sumon
  • Moderators
  • 1317 posts
  • Last active: Nov 18 2014 12:27 AM
  • Joined: 18 May 2010
Very good idea, and nice execution (I like the RegEx title display).

This is something that might be interesting to include in Sunny Windows, given your permission. Of course if you want a wide variety of settings it might be worth having it on its' own.

Like j[]hn, I think a "Cycle Current Window" would be nice, it's easy to code oneself though (just make a function that WinGets the active class and CycleWindow("ahk_class" CurrentClass) etc.

PS. I like the Screencast.

JonS
  • Members
  • 49 posts
  • Last active: Sep 26 2013 01:20 AM
  • Joined: 10 Sep 2010
Hey, thanks for the feedback.

I made an update, and fixed a few important bugs. Now, I think it's pretty bug-free.


cycleCurrentWindow was a great a idea and very easy to implement, as you can see in the code below. It's now part of "version 1.1"
cycleCurrentWindow(regExp ="(.*)") {
	WinGetClass, class, A
	cycleWindow("ahk_class " . class, regExp)
}
;I like to use "([^\-]+).*" for the regex

sumon, it would be great to see this in Sunny Windows. I had actually thought the same thing. I imagine cycleCurrentWindow wouldn't be very hard to add. Using cycleCurrentWindow, I've noticed undesirable results with some windows (one of them is Google Chrome), but I think this can be improved with some added code. Also, including the various settings could get rather complicated for Sunny Windows. But yes, you are definitely welcome to.

Any chances you include an "exclude title" mode?

I hadn't considered an "exclude title" mode, but I'd thought about adding a "include multiple titles", where you could (for example) cycle through both Foxit PDF and SumatraPDF windows (I sometimes use both simultaneously). If I implemented this, I think an "exclude title" feature would fit in easily. Do you think it would be useful?

PS, sumon, you're Screencasts are "inspirational".

sumon
  • Moderators
  • 1317 posts
  • Last active: Nov 18 2014 12:27 AM
  • Joined: 18 May 2010

Hey, thanks for the feedback.

I made an update, and fixed a few important bugs. Now, I think it's pretty bug-free.


cycleCurrentWindow was a great a idea and very easy to implement, as you can see in the code below. It's now part of "version 1.1"

cycleCurrentWindow(regExp ="(.*)") {
	WinGetClass, class, A
	cycleWindow("ahk_class " . class, regExp)
}
;I like to use "([^\-]+).*" for the regex

sumon, it would be great to see this in Sunny Windows. I had actually thought the same thing. I imagine cycleCurrentWindow wouldn't be very hard to add. Using cycleCurrentWindow, I've noticed undesirable results with some windows (one of them is Google Chrome), but I think this can be improved with some added code. Also, including the various settings could get rather complicated for Sunny Windows. But yes, you are definitely welcome to.

Any chances you include an "exclude title" mode?

I hadn't considered an "exclude title" mode, but I'd thought about adding a "include multiple titles", where you could (for example) cycle through both Foxit PDF and SumatraPDF windows (I sometimes use both simultaneously). If I implemented this, I think an "exclude title" feature would fit in easily. Do you think it would be useful?

PS, sumon, you're Screencasts are "inspirational".


Great :) I have some concerns though about the hotkeying, it doesn't always work "perfectly". Seems CapsLock is required to make the function persistant enough, otherwise it's just possible to "tap" this alt-tab equalivent, not hold alt and tap tab multiple times. This is all using cycleCurrentWindow with explorer-windows of different names.

Actually, seems bugged using Caps+Tab too. Maybe I did something wrong.

Thanks, glad to hear that!

JonS
  • Members
  • 49 posts
  • Last active: Sep 26 2013 01:20 AM
  • Joined: 10 Sep 2010
Yes, you are right. After some testing, I only had to change 1 line of code to fix it.

I only had to specify the "P" option in the following line:
if (!getKeyState(cycleWindow_holdKey, "P"))

So, any hotkey should work now (given it has the right format). It's a good thing you pointed this out, because I had assumed it was a shortcoming of keyboards.

Here's the code after I made the above change:
cycleWindow

MasterFocus
  • Moderators
  • 4322 posts
  • Last active:
  • Joined: 08 Apr 2009

I'd thought about adding a "include multiple titles"

That should be kind of easily achievable using a proper RegEx.
However, suppose you want to cycle through all your windows except the PDF ones...
So, I would still love to see "exclude title" implemented. :)

j--hn
  • Members
  • 176 posts
  • Last active: Oct 26 2011 02:42 PM
  • Joined: 16 Apr 2011
Hi Jon. Thank's for the update, may I request a generic function again :D :

[*:3qyp5a18] CycleWindow("Next") ==> replacement of AltTab
[*:3qyp5a18] CycleWindow("Prev") ==> replacement of ShiftAltTab
[*:3qyp5a18] CycleVisibleWindow("Next") ==> AltTab but only on visible window
[*:3qyp5a18] CycleVisibleWindow("Prev") ==> ShiftAltTab but only on visible window
[*:3qyp5a18] CycleCurrentWindow("Next") ==> Go to Next Active Class window
[*:3qyp5a18] CycleCurrentWindow("Prev") ==> Go to Prev Active Class windowCycleWindow is great desktop management function, so i think those basic functionality should be included, cause i think it would be useful for newbie/general user (aka me :lol:)who dont want a complex syntax.

I know CycleWindow is operating on visible window only, so I'm proposing CycleVisibleWindow because i think CycleWindow should also include minimized window. But that just me.

Anyway, the way I want to use it was like this :
!Tab:: CycleVisibleWindow("Next") ; Go to next visible window 
+!Tab:: CycleVisibleWindow("Prev") ; Go to previous visible window 
^!Tab:: CycleWindow("Next") ; basically it's an alt tab
^+!Tab:: CycleWindow("Prev")  ; basically it's an Shift alt tab
^Tab:: CycleCurrentWindow("Next") ; Go to Next Active Class window
^+Tab:: CycleCurrentWindow("Prev") ; Go to Previous Active Class window
The hotkeys was just an example, i just want the parameters to be a little bit more simple for generic use. I hope it doesn't complicate things. :roll:

Thank's again.

Edit:
The major point is, I just want the syntax to support a simple parameter for generic functionality such as:
CapsLock & e::cycleCurrentWindow() ; it should behave like cycleCurrentWindow("([^\-]+).*")
CapsLock & w::cycleWindow() ; an alt tab
CapsLock & v::cycleVisibleWindow() ; an alt tab on visible window
rather than
CapsLock & e::cycleCurrentWindow("([^\-]+).*")
CapsLock & w::cycleWindow("param 1", "param 2", "param 3")
CapsLock & v::cycleVisibleWindow("param 1", "param 2", "param 3")
Because i want to use it to replace the regular Alt+tab, i would be grateful if this is possible, Thank you.

JonS
  • Members
  • 49 posts
  • Last active: Sep 26 2013 01:20 AM
  • Joined: 10 Sep 2010
You did make me realize that the simpler uses of cycleWindow are not obvious to the new user. I've made some more changes, and will post the updated code at the bottom of this post.

All parameters are optional now. The following line of code will cycle ALL windows, excluding windows with no title, as well as progman and Start.
Alt & Tab::cycleWindow()
; (to my surprise this is actually almost as good as the standard Alt-Tab)


The following line will cycle the currently active class (excluding windows with no title)

CapsLock & tab::cycleCurrentWindow()

The following line will cycle Notepad windows

CapsLock & n::cycleWindow("Notepad")

The following line will cycle Notepad windows, but they will display in the ListView nicer, and you will be able to open new notepad windows by pressing the Win key.

CapsLock & n::cycleWindow("Notepad", "(.*) - Notepad", "C:\Windows\System32\notepad.exe")


(I thought having 2 separate hotkeys for forwards-cycling and backwards-cycling was unnecessary but also really incompatible with how cycleWindow is coded.)


Also, to clear some things up, the function cycles windows regardless of whether or not they are minimized—thumbnails don't display for minimized windows, but they show up in the ListView. I'm actually not sure if there's a way for a script to know if a window's minimized or not.
And the regex only affects how the titles show in the ListView, not which ones will be included. The actual list-getting was done entirely by AHK's WinGet, list command; until now, there wasn't any code to modify the list after it was retrieved.

I think extra window inclusions and exclusions will be added as a fourth parameter as a parsable string. It might look like:
"includeThisTitle, ahk_class includeThisClass, include This Title Too | exclude this, ahk_class andThis, and this as well"
When included, this will be a lot more processing with the list, so I hope it doesn't add any delay. What do you think?

cycleWindow.ahk
documentation

j--hn
  • Members
  • 176 posts
  • Last active: Oct 26 2011 02:42 PM
  • Joined: 16 Apr 2011

I think extra window inclusions and exclusions will be added as a fourth parameter as a parsable string. It might look like:

"includeThisTitle, ahk_class includeThisClass, include This Title Too | exclude this, ahk_class andThis, and this as well"

Jon, I'm not sure why you want put include&exclude on same param, but I think cycleWindow(title, include, exclude, regExp, pathToRun) would be more consistent

A little more question though:


[*:1nbmagdu] Is it possible to switch back&forth without the use of shift? cycleWindow always use a pair of hotkey right? so for example if i set my hotkey like this :
NumpadMult & NumpadSub::cycleWindow()
So can i go back and forth by alternating my keypress?
[*:1nbmagdu] Is it possible to customize ShiftKey?
[*:1nbmagdu] If both answer is yes, could you add an option to pick a mode on how to switch the window(eg, mode1:ShiftKey, mode2:Alternating keypress)Since this feature is trivial, and im sure it would need a code rewrite to do it, i'm just asking of possibility here.

JonS
  • Members
  • 49 posts
  • Last active: Sep 26 2013 01:20 AM
  • Joined: 10 Sep 2010
Here's what I'm thinking for the include/exclude parameter: both will be included in the first parameter. So, the first parameter can be a simple title like this:

"includeThisWindow"

or a parsable String like this:

"| includeThisWindow, and this window, ahk_class andThis | butExclude ThisWin, and this, goaway, badwindow"

It's determined by whether or not the first character of this parameter is "|" or not. Obviously the parsable-type involves more processing. You like it? I've yet to do all the coding for this (but it will probably be similar to the code that excludes windows with no title).

One more thing, a blank title includes everything (except progman and start), so you could specify just exclusions with something like this:

"| | Exclude ThisWin, and this, goaway, badwindow"

The shift key is easily customizable; I just made it one of the "settings" at the top of the function, called cycleWindow_reverseKey. Here is my current code: http://dl.dropbox.co...1 2227(22)).ahk

As for alternating keypresses, you mean that you would lift and press NumpadMult to go backwards, and lift and press NumpadSub to go forwards, right? That's an interesting idea, but it is departing a lot from the original intent of cycleWindow. It would take some time to get it right, however, I'm not sure I want to invest the time in it right now.

This makes me wonder....It seems that cycleWindow is liked as an Alt-Tab replacement, which isn't how it was intended. I saw it as extension of the "launch or activate" hotkeys I described in the "Backstory" part of the first post. In my "philosophy of window-switching", the majority of window switches should involve little or no cycling at all—just quick hotkey presses, and you're immediately looking at the window you want to see (so you would make a cycleWindow hotkey for each of your most-frequently-used apps). Any thoughts on either "window-switching philosophy"?

Regardless, I will try to work on the inclusion/exclusion stuff tomorrow evening, and see if I can make some progress on it.

_________________________
Composed/Posted with WYSIWYG BBCode Editor

j--hn
  • Members
  • 176 posts
  • Last active: Oct 26 2011 02:42 PM
  • Joined: 16 Apr 2011
[quote name="JonS"]Here's what I'm thinking for the include/exclude parameter: both will be included in the first parameter. So, the first parameter can be a simple title like this:

"includeThisWindow"
[/quote]
I totally agree with this.
[quote]
or a parsable String like this:

"| includeThisWindow, and this window, ahk_class andThis | butExclude ThisWin, and this, goaway, badwindow"

It's determined by whether or not the first character of this parameter is "|" or not. Obviously the parsable-type involves more processing. You like it? I've yet to do all the coding for this (but it will probably be similar to the code that excludes windows with no title). One more thing, a blank title includes everything (except progman and start), so you could specify just exclusions with something like this:

"| | Exclude ThisWin, and this, goaway, badwindow"[/quote]
Its fine for me, but I still insist that it's a bit unconventional.

[quote]The shift key is easily customizable; I just made it one of the "settings" at the top of the function, called cycleWindow_reverseKey. Here is my current code: http://dl.dropbox.co...1 2227(22)).ahk
[/quote]
Thank you, Jon
[quote]As for alternating keypresses, you mean that you would lift and press NumpadMult to go backwards, and lift and press NumpadSub to go forwards, right?[/quote]
Yes that is correct.
[quote]That's an interesting idea, but it is departing a lot from the original intent of cycleWindow. It would take some time to get it right, however, I'm not sure I want to invest the time in it right now.[/quote]
It's Ok, it would be better to spend time&resource to improving window detection & inclusion/exclusion.
[quote]This makes me wonder....It seems that cycleWindow is liked as an Alt-Tab replacement, which isn't how it was intended. I saw it as extension of the "launch or activate" hotkeys I described in the "Backstory" part of the first post. In my "philosophy of window-switching", the majority of window switches should involve little or no cycling at all—just quick hotkey presses, and you're immediately looking at the window you want to see (so you would make a cycleWindow hotkey for each of your most-frequently-used apps).[/quote]
Then the function should be named switchWindow() instead. :wink:
[quote]Any thoughts on either "window-switching philosophy"?[/quote]
I'm seeing cycleWindow as Alt+Tab on STEROID :lol:

Allright joke aside, here's my opinion:
[*:d4zce5n9]I thought cycleWindow has a great potential as a window/desktop management, so why limit(hide) it's ability by excluding general functionality.
[*:d4zce5n9]You've already working on the hard part, that is window detection&filtering, a general alt tab functionality could simply be achieved by removing filtering criteria, so i don't see any reason why not doing this.
[*:d4zce5n9]Also i doubt any new user would use the advanced function straight away, so simple altTab/shift+altTab would be a great as a start.
[*:d4zce5n9]"philosophy of window-switching" = habit, thus its personal and cannot be easily changed, it need time to adapt. So If (for example) one think cycleWindow() is not compatible with his/her habit of window switching, or it was to complicated to use, the chance are he/she wont use it, thus put cycleWindow wasted, despite it's potential.
[quote]Regardless, I will try to work on the inclusion/exclusion stuff tomorrow evening, and see if I can make some progress on it.[/quote]
Thank's again.
_________________________
Composed/Posted with WYSIWYG BBCode Editor[/quote]

JonS
  • Members
  • 49 posts
  • Last active: Sep 26 2013 01:20 AM
  • Joined: 10 Sep 2010
I am proud to present: Inclusion/Exclusion!!!

Sorry this was so long in the making. I had much less time to work on it than I thought I would. Here are the links.

http://dl.dropbox.co...cycleWindow.ahk

http://dl.dropbox.co...ycleWindow.html

I plan to make this a 1.2 update, and make a better, more understandable first-post for this thread.