AutoHotkey Community

It is currently May 27th, 2012, 3:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: cycleWindow()
PostPosted: May 6th, 2011, 6:52 pm 
Offline

Joined: September 10th, 2010, 9:44 pm
Posts: 47
Location: Virginia
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)
  1. title - used to determine which windows are in the subset (e.g. windows that belong to a specific app). (see WinGet/Parameters/WinTitle)
  2. 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)
  3. pathToRun - the path to launch the app, if necessary.


Examples
  • All Windows
    Code:
    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
    Code:
    CapsLock & n::cycleWindow("Notepad")
    ;cycles through all notepad window
    ;(specifically, windows with "notepad" in their title)

  • Windows Explorer
    Code:
    CapsLock & e::cycleWindow("ahk_class CabinetWClass")
    ;cycles through all open windows of Windows Explorer

  • MSPaint
    Code:
    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
    Code:
    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
    Code:
    LAlt & Tab::cycleWindow("||ahk_class BasicWindow")
    ;cycles all windows, excluding Windows 7 Desktop Gadgets

    Also uses Inclusion/Exclusion.


Documentation

cycleWindow.ahk




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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)


Last edited by JonS on June 4th, 2011, 2:42 am, edited 9 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 7th, 2011, 2:38 am 
This reminds me of my favorite script, Find Firefox Tab! Of course, Find Firefox Tab cycles through FF tabs to find its target. :lol:

Image


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2011, 4:07 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Looks great.
Any chances you include an "exclude title" mode?

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2011, 4:41 am 
Offline

Joined: April 16th, 2011, 7:18 am
Posts: 176
Location: Jogjakarta, Indonesia
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 9th, 2011, 12:48 pm 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
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.

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2011, 10:03 pm 
Offline

Joined: September 10th, 2010, 9:44 pm
Posts: 47
Location: Virginia
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"
Code:
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.

Quote:
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".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2011, 10:32 pm 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
JonS wrote:
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"
Code:
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.

Quote:
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!

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 12th, 2011, 3:04 am 
Offline

Joined: September 10th, 2010, 9:44 pm
Posts: 47
Location: Virginia
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:
Code:
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 12th, 2011, 3:43 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
JonS wrote:
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. :)

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 12th, 2011, 4:03 am 
Offline

Joined: April 16th, 2011, 7:18 am
Posts: 176
Location: Jogjakarta, Indonesia
Hi Jon. Thank's for the update, may I request a generic function again :D :
  • CycleWindow("Next") ==> replacement of AltTab
  • CycleWindow("Prev") ==> replacement of ShiftAltTab
  • CycleVisibleWindow("Next") ==> AltTab but only on visible window
  • CycleVisibleWindow("Prev") ==> ShiftAltTab but only on visible window
  • CycleCurrentWindow("Next") ==> Go to Next Active Class window
  • CycleCurrentWindow("Prev") ==> Go to Prev Active Class window

CycleWindow 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 :
Code:
!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:
Code:
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
Code:
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2011, 3:41 am 
Offline

Joined: September 10th, 2010, 9:44 pm
Posts: 47
Location: Virginia
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.
Code:
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)

Code:
CapsLock & tab::cycleCurrentWindow()


The following line will cycle Notepad windows

Code:
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.

Code:
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:
Code:
"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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2011, 5:52 pm 
Offline

Joined: April 16th, 2011, 7:18 am
Posts: 176
Location: Jogjakarta, Indonesia
JonS wrote:
I think extra window inclusions and exclusions will be added as a fourth parameter as a parsable string. It might look like:
Code:
"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:

  • 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 :
    Code:
    NumpadMult & NumpadSub::cycleWindow()

    So can i go back and forth by alternating my keypress?
  • Is it possible to customize ShiftKey?
  • 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.

_________________
AHK_Lw 1.1.05, OS: XP SP3, Firefox 3


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2011, 4:18 am 
Offline

Joined: September 10th, 2010, 9:44 pm
Posts: 47
Location: Virginia
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.com/u/1780553/AHK/cycleWindow%285.15.2011%202227%2822%29%29.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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2011, 3:12 pm 
Offline

Joined: April 16th, 2011, 7:18 am
Posts: 176
Location: Jogjakarta, Indonesia
JonS wrote:
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"

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"

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.com/u/1780553/AHK/cycleWindow%285.15.2011%202227%2822%29%29.ahk

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?

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.

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).

Then the function should be named switchWindow() instead. :wink:
Quote:
Any thoughts on either "window-switching philosophy"?

I'm seeing cycleWindow as Alt+Tab on STEROID :lol:

Allright joke aside, here's my opinion:
  • I thought cycleWindow has a great potential as a window/desktop management, so why limit(hide) it's ability by excluding general functionality.
  • 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.
  • 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.
  • "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.

Thank's again.
_________________________
Composed/Posted with WYSIWYG BBCode Editor[/quote]

_________________
AHK_Lw 1.1.05, OS: XP SP3, Firefox 3


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 12:41 am 
Offline

Joined: September 10th, 2010, 9:44 pm
Posts: 47
Location: Virginia
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.com/u/1780553/AHK/cycleWindow/%285.31.2011%201931%2843%29%29%20to%20become%20v1.2/cycleWindow.ahk

http://dl.dropbox.com/u/1780553/AHK/cycleWindow/%285.31.2011%201931%2843%29%29%20to%20become%20v1.2/cycleWindow.html

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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group