Jump to content

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

Alt-Tab Replacement


  • Please log in to reply
3 replies to this topic
Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
This script will display all open windows in a menu when you middle click. Click on the windows name to view that window. It works in a similar way to alt-tab.

I'm working on grouping the window title based on the progam that is running.

/*
Alter the value of "shorten" below to change where characters are removed from the title

1 = remove from right
2 = remove from middle
3 = don't remove any characters

Alter the value of "shorten_length" below to specify how many characters long 
you would like the menu times to be.

*/

shorten=1
shorten_length=35

del=

~MButton::

if del <>
menu, tabs, DeleteAll

del++

index=0

WinGet, WinList, List,,,Program Manager

WinGet, active_titleid, Id, A


loop, %WinList%
{
StringTrimRight, element, WinList%a_index%, 0

if element =
break

WinGetTitle, title, ahk_id %element%

StringLen, title_len, title


if title_len >= %shorten_length%
{

if shorten=1
{

no_char_to_remove=%title_len%
no_char_to_remove-=%shorten_length%

StringTrimRight, title, title, %no_char_to_remove%

title=%title%...
}

if shorten=2
{
no_char_to_remove=%title_len%
no_char_to_remove-=%shorten_length%

half_remove=%no_char_to_remove%
half_remove/=2

half_len=%title_len%
half_len/=2
half_len-=%half_remove%

StringMid, to_replace, title, %half_len%, %no_char_to_remove% 

StringReplace, title, title, %to_replace%, ...
}

}


  if title<>
  {
    index++

	if active_titleid=%element%
	{
	  menu, tabs, add, %index%) *%title%, activate
	}
	else
	{
	  menu, tabs, add, %index%) %title%, activate
	}

    item%index%=%element%
  }

}

menu, tabs, add,
menu, tabs, add, Show Desktop, desktop

MouseGetPos, X, Y

Menu, tabs,Show, %x%, %y%

return

activate:

loop, %A_ThisMenuItemPos%
{
	StringTrimRight, id, item%a_index%, 0
}

winactivate, ahk_id %id%

menu, tabs, deleteall

return

desktop:
WinMinimizeAll
return


jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Works great! Thanks for sharing it, with a few tweaks I'll start using this right away. One tiny bug right away though, PSPad shows twice in the menu, but only after it's activated the first time using the menu. The first entry is the title in the titlebar (PSPad - [drive]), and the second entry is the title in the taskbar (filename.ahk). I'm still trying to isolate it, I'll tell you if I can find out why it's doing that.

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
I've just downloaded PSPad and got the same 2 windows showing. It could just be that the program is using two windows for some reason. I also noticed that if you close all open tabs then PSPad shows twice.

I have found that using the middle mouse button interferes with firefox's autoscroll. I use the following code to stop this if anyone wants it-

~MButton::

HowLong = 0
Loop
{
	HowLong ++
	Sleep, 10
	GetKeyState, MButton, MButton, P
	IfEqual, MButton, U, Break
}
if HowLong <  20
Return
else
send, {mbutton}

The menu will only show after holding the middle mouse button down for 20ms otherwise it will carry out it's normal function. I took that bit of code from Rajats mouse menu and modified it a bit.

TheGreatSwami Woo
  • Members
  • 237 posts
  • Last active: Jan 22 2012 03:31 PM
  • Joined: 26 May 2011
It;s an oldie but goodie just lacked the ability to screen out windows you don't want in the list, added some code from iswitchw-plus
/* 
 I HAVE MADE CAPSLOCK TO BE THE HOTKEY
Alter the value of "shorten" below to change where characters are removed from the title 

1 = remove from right 
2 = remove from middle 
3 = don't remove any characters 

Alter the value of "shorten_length" below to specify how many characters long 
you would like the menu times to be. 

*/ 

shorten=1 
shorten_length=35 

del= 

CAPSLOCK:: 

if del <> 
menu, tabs, DeleteAll 

del++ 

index=0 

WinGet, WinList, List,,,Program Manager 

WinGet, active_titleid, Id, A 


loop, %WinList% 
{ 
StringTrimRight, element, WinList%a_index%, 0 

if element = 
break 

WinGetTitle, title, ahk_id %element% 

StringLen, title_len, title 


if title_len >= %shorten_length% 
{ 

if shorten=1 
{ 

no_char_to_remove=%title_len% 
no_char_to_remove-=%shorten_length% 

StringTrimRight, title, title, %no_char_to_remove% 

title=%title%... 
} 

 
if shorten=2 
{ 
no_char_to_remove=%title_len% 
no_char_to_remove-=%shorten_length% 

half_remove=%no_char_to_remove% 
half_remove/=2 

half_len=%title_len% 
half_len/=2 
half_len-=%half_remove% 

StringMid, to_replace, title, %half_len%, %no_char_to_remove% 

StringReplace, title, title, %to_replace%, ... 
} 

} 
; don't add titles which match any of the filters
            if filterlist <>
            {
                filtered =

                loop
                {
                    stringtrimright, filter, filters%a_index%, 0
                    if filter =
                      break
                    else
                        ifinstring, title, %filter%
                        {
                           filtered = yes
                           break
                        }
                }

                if filtered = yes
                    continue
            }
;put stuff you dont want showing in this list
filterlist = Bar|Physimem|clock|TaskWnd|PowerPro pproconf|Quicknote|Clock|NoteButton|*Blackbox|utils|sTabLauncher|Blackbox
if filterlist <>
{
    loop, parse, filterlist, |
    {
        filters%a_index% = %A_LoopField%
    }
}
  if title<> 
  { 
    index++ 

   if active_titleid=%element% 
   { 
     menu, tabs, add, %index%) *%title%, activate 
   } 
   else 
   { 
     menu, tabs, add, %index%) %title%, activate 
   } 

    item%index%=%element% 
  } 

} 


menu, tabs, add, 



MouseGetPos, X, Y 

Menu, tabs,Show, %x%, %y% 

return 

activate: 

loop, %A_ThisMenuItemPos% 
{ 
   StringTrimRight, id, item%a_index%, 0 
} 

winactivate, ahk_id %id% 

menu, tabs, deleteall 

return