 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
viciouskinid
Joined: 23 Jun 2007 Posts: 136
|
|
| Back to top |
|
 |
Guest
|
Posted: Thu Feb 28, 2008 7:23 pm Post subject: |
|
|
| got problems with moving windows to other desktops. computer hangs. |
|
| Back to top |
|
 |
viciouskinid
Joined: 23 Jun 2007 Posts: 136
|
Posted: Fri Feb 29, 2008 5:07 am Post subject: |
|
|
My other code was really messy. Here is some better work.
http://www.autohotkey.net/~viciouskinid/OrderdDesk.rar
If anyone wants to have a go at debugging it that would be appreciated. The main issue is that occasionally it makes the desktop icons and taskbar disappear. I cant fix it. |
|
| Back to top |
|
 |
girl_interrupted Guest
|
Posted: Thu Apr 24, 2008 4:11 pm Post subject: |
|
|
I think what this misses is a "gather windows" command. which is, move all windows from other worskpaces to current workspace. I don't know how to do it though  |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Sep 08, 2008 2:30 pm Post subject: |
|
|
I really like this autohotkeyscript and mode some modifications to version Christian Schüler's v1.11 :
Added support for MultiMonTaskbar (a taskbar on a second physical screen)
Added storing of active window per virtual desktop
Added Traytips to inform the user what happened
| Code: |
; DesktopSwitch
;
; AutoHotkey Version: 1.0.40.00 (that's at least the version I'm using)
; Language: English
; Platform: Win9x/NT/XP
; Author: Christian Schüler <c_schueler@gmx.at>
; last changes: 08. Sep. 2008
;
; Script Function:
;
; A small tool for switching between multiple virtual desktops.
; Use Alt-F<desktop index> (e.g. Alt-F2) to switch between desktops and
; Quit the script and all windows on all virtual desktops will be soon
; Currently, 4 desktops are supported, because more will start to confuse me...
;
; Version history:
;
; v1.12, 08 sept 2008 Emiel Witteman
; Code cleanup, removed some redundant code from previous versions.
; Added support for MultiMonTaskbar (a taskbar on a second physical screen)
; Added storing of active window per virtual desktop
; Added Traytips to inform the user what happened
;
; v1.11, 22. Nov. 2005
; Fixed bug: windows are now corrrectly activated after switching/sending
;
; v1.1, 05. Nov. 2005
; Added feature: pressing Ctrl/Alt-<index> sends the active window to the desktop <index>.
;
; v1.0, 04. Nov. 2005
; It works!
; Switching can be done using Alt-<desktop index>, e.g. Alt-1. Pressing
; Alt-0 will exit the script and show all windows from all virtual desktops
; at once.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging ;
; turn off or set high to save cpu ;
; when debug is done ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000
; ***** initialization *****
#WinActivateForce
SetBatchLines, -1 ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp ; clean up in case of error (otherwise some windows will get lost)
numDesktops := 4 ; maximum number of desktops
curDesktop := 1 ; index number of current desktop
; ***** hotkeys *****
!f1::SwitchToDesktop(1)
!f2::SwitchToDesktop(2)
!f3::SwitchToDesktop(3)
!f4::SwitchToDesktop(4)
^!f1::SendActiveToDesktop(1)
^!f2::SendActiveToDesktop(2)
^!f3::SendActiveToDesktop(3)
^!f4::SendActiveToDesktop(4)
;!0::ExitApp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
TrayTip, %A_ScriptName%, updated AutoHotkey script
SetTimer, AutoReloadScriptTrayTip, 2000
}
return
AutoReloadScriptTrayTip:
SetTimer, AutoReloadScriptTrayTip, Off
TrayTip
Reload
return
; ***** functions *****
; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
global
if (curDesktop <> newDesktop)
{
GetCurrentWindows(curDesktop)
ShowHideWindows(curDesktop, false)
ShowHideWindows(newDesktop, true)
activate_window := % active_id%newDesktop%
WinActivate, ahk_id %activate_window%
TrayTip, DesktopSwitch, Switching to desktop %newDesktop%
curDesktop := newDesktop
}
return
}
; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global
RemoveWindowID(curDesktop, windowID)
; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%
windows%newDesktop%%i% := windowID
WinHide, ahk_id %windowID%
TrayTip, DesktopSwitch, Window send to desktop %newDesktop%
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
WinGet, id, ID, A
SendToDesktop(id, newDesktop)
}
; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
global
Loop, % windows%desktopIdx%
{
if (windows%desktopIdx%%A_Index% = ID)
{
RemoveWindowID_byIndex(desktopIdx, A_Index)
Break
}
}
}
; this removes the window id at index <ID_idx> from desktop number <desktopIdx>
RemoveWindowID_byIndex(desktopIdx, ID_idx)
{
global
Loop, % windows%desktopIdx% - ID_idx
{
idx1 := % A_Index + ID_idx - 1
idx2 := % A_Index + ID_idx
windows%desktopIdx%%idx1% := windows%desktopIdx%%idx2%
}
windows%desktopIdx% -= 1
}
; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
global
WinGet, active_id%index%, ID, A ; get the current active window
WinGet, windows%index%, List,,, Program Manager ; get list of all visible windows
; remove windows which we want to see on all virtual desktops
Loop, % windows%index%
{
id := % windows%index%%A_Index%
WinGetClass, windowClass, ahk_id %id%
if windowClass = Shell_TrayWnd ; remove task bar window id
RemoveWindowID_byIndex(index, A_Index)
else if windowClass = #32770 ; Emiel: we also want multimontaskbar on all virtual desktops
RemoveWindowID_byIndex(index, A_Index)
}
}
; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
global
Loop, % windows%index%
{
id := % windows%index%%A_Index%
if show
WinShow, ahk_id %id%
else
WinHide, ahk_id %id%
}
}
; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
ShowHideWindows(A_Index, true)
ExitApp
|
|
|
| Back to top |
|
 |
Guest
|
Posted: Mon Sep 08, 2008 3:34 pm Post subject: |
|
|
Squashed some nasty array housekeeping bugs which explained the faulty hide/show of some windows.
Can some array expert conform this is the correct way to erase a two demensional array?
| Code: |
emptyString =
StringSplit, windows%index%, emptyString
|
This version seems to working fine now:
| Code: |
; DesktopSwitch
;
; AutoHotkey Version: 1.0.40.00 (that's at least the version I'm using)
; Language: English
; Platform: Win9x/NT/XP
; Author: Christian Schüler <c_schueler@gmx.at>
; last changes: 08. Sep. 2008
;
; Script Function:
;
; A small tool for switching between multiple virtual desktops.
; Use Alt-F<desktop index> (e.g. Alt-F2) to switch between desktops and
; Quit the script and all windows on all virtual desktops will be soon
; Currently, 4 desktops are supported, because more will start to confuse me...
;
; Version history:
;
; v1.13, 08 sept 2008 Emiel Witteman
; Fixed bugs in array housekeeping, explained the faulty hide/show of some windows
;
; v1.12, 08 sept 2008 Emiel Witteman
; Code cleanup, removed some redundant code from previous versions.
; Added support for MultiMonTaskbar (a taskbar on a second physical screen)
; Added storing of active window per virtual desktop
; Added Traytips to inform the user what happened
;
; v1.11, 22. Nov. 2005
; Fixed bug: windows are now corrrectly activated after switching/sending
;
; v1.1, 05. Nov. 2005
; Added feature: pressing Ctrl/Alt-<index> sends the active window to the desktop <index>.
;
; v1.0, 04. Nov. 2005
; It works!
; Switching can be done using Alt-<desktop index>, e.g. Alt-1. Pressing
; Alt-0 will exit the script and show all windows from all virtual desktops
; at once.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging ;
; turn off or set high to save cpu ;
; when debug is done ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000
; ***** initialization *****
#WinActivateForce
SetBatchLines, -1 ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp ; clean up in case of error (otherwise some windows will get lost)
numDesktops := 4 ; maximum number of desktops
curDesktop := 1 ; index number of current desktop
; ***** hotkeys *****
!f1::SwitchToDesktop(1)
!f2::SwitchToDesktop(2)
!f3::SwitchToDesktop(3)
!f4::SwitchToDesktop(4)
^!f1::SendActiveToDesktop(1)
^!f2::SendActiveToDesktop(2)
^!f3::SendActiveToDesktop(3)
^!f4::SendActiveToDesktop(4)
;!0::ExitApp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
TrayTip, %A_ScriptName%, updated AutoHotkey script
SetTimer, AutoReloadScriptTrayTip, 2000
}
return
AutoReloadScriptTrayTip:
SetTimer, AutoReloadScriptTrayTip, Off
TrayTip
Reload
return
; ***** functions *****
; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
global
if (curDesktop <> newDesktop)
{
GetCurrentWindows(curDesktop)
ShowHideWindows(curDesktop, false)
ShowHideWindows(newDesktop, true)
activate_window := % active_id%newDesktop%
WinActivate, ahk_id %activate_window%
TrayTip, DesktopSwitch, Switching to desktop %newDesktop%
curDesktop := newDesktop
}
return
}
; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global
RemoveWindowID(curDesktop, windowID)
; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%
windows%newDesktop%%i% := windowID
WinHide, ahk_id %windowID%
TrayTip, DesktopSwitch, Window send to desktop %newDesktop%
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
WinGet, id, ID, A
SendToDesktop(id, newDesktop)
}
; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
global
Loop, % windows%desktopIdx%
{
if (windows%desktopIdx%%A_Index% = ID)
{
windows%desktopIdx%%A_Index%= ;Emiel: just empty the array element, array will be emptied by next switch anyway
Break
}
}
}
; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
global
WinGet, active_id%index%, ID, A ; get the current active window
emptyString =
StringSplit, windows%index%, emptyString ; Emiel: delete the entire windows_index_ array
WinGet, windows%index%, List,,, Program Manager ; get list of all visible windows
; remove windows which we want to see on all virtual desktops
Loop, % windows%index%
{
id := % windows%index%%A_Index%
WinGetClass, windowClass, ahk_id %id%
if windowClass = Shell_TrayWnd ; remove task bar window id
windows%index%%A_Index%= ; Emiel: just empty the array element, array will be emptied by next switch anyway
if windowClass = #32770 ; Emiel: we also want multimontaskbar on all virtual desktops
windows%index%%A_Index%= ; Emiel: just empty the array element, array will be emptied by next switch anyway
}
}
; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
global
Loop, % windows%index%
{
id := % windows%index%%A_Index%
if show
WinShow, ahk_id %id%
else
WinHide, ahk_id %id%
}
}
; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
ShowHideWindows(A_Index, true)
ExitApp
|
BTW my previous post can be deleted |
|
| Back to top |
|
 |
poser101 Guest
|
Posted: Thu Mar 12, 2009 3:10 pm Post subject: |
|
|
I fixed the bug where the window disappears if you send it to its current desktop. (e.g. sending Window X in Desktop 1 to Desktop 1 resulted in Window X disappearing forever)
Replace this section with the updated code:
; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global
if (CurDesktop <> newDesktop)
{
RemoveWindowID(curDesktop, windowID)
; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%
windows%newDesktop%%i% := windowID
WinHide, ahk_id %windowID%
TrayTip, DesktopSwitch, Window send to desktop %newDesktop%
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
} |
|
| Back to top |
|
 |
Emiel Guest
|
Posted: Thu Jun 25, 2009 9:50 am Post subject: |
|
|
The full code with the fix mentioned in the previous post by poser101
| Code: |
; DesktopSwitch
;
; AutoHotkey Version: 1.0.40.00 (that's at least the version I'm using)
; Language: English
; Platform: Win9x/NT/XP
; Author: Christian Schüler <c_schueler@gmx.at>
; last changes: 25. jun. 2009
;
; Script Function:
;
; A small tool for switching between multiple virtual desktops.
; Use Alt-F<desktop index> (e.g. Alt-F2) to switch between desktops and
; Quit the script and all windows on all virtual desktops will be soon
; Currently, 4 desktops are supported, because more will start to confuse me...
;
; Version history:
;
; v1.14, 25 jun 2009 Emiel Witteman
; Fixed bug window disappearing when sending it to the current desktop
; v1.13, 08 sept 2008 Emiel Witteman
; Fixed bugs in array housekeeping, explained the faulty hide/show of some windows
;
; v1.12, 08 sept 2008 Emiel Witteman
; Code cleanup, removed some redundant code from previous versions.
; Added support for MultiMonTaskbar (a taskbar on a second physical screen)
; Added storing of active window per virtual desktop
; Added Traytips to inform the user what happened
;
; v1.11, 22. Nov. 2005
; Fixed bug: windows are now corrrectly activated after switching/sending
;
; v1.1, 05. Nov. 2005
; Added feature: pressing Ctrl/Alt-<index> sends the active window to the desktop <index>.
;
; v1.0, 04. Nov. 2005
; It works!
; Switching can be done using Alt-<desktop index>, e.g. Alt-1. Pressing
; Alt-0 will exit the script and show all windows from all virtual desktops
; at once.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging ;
; turn off or set high to save cpu ;
; when debug is done ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000
; ***** initialization *****
#WinActivateForce
SetBatchLines, -1 ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp ; clean up in case of error (otherwise some windows will get lost)
numDesktops := 4 ; maximum number of desktops
curDesktop := 1 ; index number of current desktop
; ***** hotkeys *****
!f1::SwitchToDesktop(1)
!f2::SwitchToDesktop(2)
!f3::SwitchToDesktop(3)
!f4::SwitchToDesktop(4)
^!f1::SendActiveToDesktop(1)
^!f2::SendActiveToDesktop(2)
^!f3::SendActiveToDesktop(3)
^!f4::SendActiveToDesktop(4)
;!0::ExitApp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
TrayTip, %A_ScriptName%, updated AutoHotkey script
SetTimer, AutoReloadScriptTrayTip, 2000
}
return
AutoReloadScriptTrayTip:
SetTimer, AutoReloadScriptTrayTip, Off
TrayTip
Reload
return
; ***** functions *****
; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
global
if (curDesktop <> newDesktop)
{
GetCurrentWindows(curDesktop)
ShowHideWindows(curDesktop, false)
ShowHideWindows(newDesktop, true)
activate_window := % active_id%newDesktop%
WinActivate, ahk_id %activate_window%
TrayTip, DesktopSwitch, Switching to desktop %newDesktop%
curDesktop := newDesktop
}
return
}
; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global
if (curDesktop <> newDesktop)
{
RemoveWindowID(curDesktop, windowID)
; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%
windows%newDesktop%%i% := windowID
WinHide, ahk_id %windowID%
TrayTip, DesktopSwitch, Window send to desktop %newDesktop%
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
}
; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
WinGet, id, ID, A
SendToDesktop(id, newDesktop)
}
; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
global
Loop, % windows%desktopIdx%
{
if (windows%desktopIdx%%A_Index% = ID)
{
windows%desktopIdx%%A_Index%= ;Emiel: just empty the array element, array will be emptied by next switch anyway
Break
}
}
}
; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
global
WinGet, active_id%index%, ID, A ; get the current active window
emptyString =
StringSplit, windows%index%, emptyString ; Emiel: delete the entire windows_index_ array
WinGet, windows%index%, List,,, Program Manager ; get list of all visible windows
; remove windows which we want to see on all virtual desktops
Loop, % windows%index%
{
id := % windows%index%%A_Index%
WinGetClass, windowClass, ahk_id %id%
if windowClass = Shell_TrayWnd ; remove task bar window id
windows%index%%A_Index%= ; Emiel: just empty the array element, array will be emptied by next switch anyway
if windowClass = #32770 ; Emiel: we also want multimontaskbar on all virtual desktops
windows%index%%A_Index%= ; Emiel: just empty the array element, array will be emptied by next switch anyway
if windowClass = cygwin/x X rl-xosview-XOsview-0 ; Emiel: xosviews e.d.
windows%index%%A_Index%=
if windowClass = cygwin/x X rl-xosview-XOsview-1 ; Emiel: xosviews e.d.
windows%index%%A_Index%=
if windowClass = MozillaUIWindowClass ; Mozilla thunderbird
{
WinGet, ExStyle, ExStyle, ahk_id %id%
if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST. ; Alleen de mailboxalertmelding!
windows%index%%A_Index%=
}
}
}
; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
global
Loop, % windows%index%
{
id := % windows%index%%A_Index%
if show
WinShow, ahk_id %id%
else
WinHide, ahk_id %id%
}
}
; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
ShowHideWindows(A_Index, true)
ExitApp
|
|
|
| Back to top |
|
 |
small_c0d3r
Joined: 29 Nov 2009 Posts: 46 Location: Queensland
|
Posted: Thu Mar 04, 2010 6:51 am Post subject: |
|
|
| how would you go about using a shortcut to make a window remain within all desktops |
|
| Back to top |
|
 |
small_c0d3r
Joined: 29 Nov 2009 Posts: 46 Location: Queensland
|
Posted: Thu Apr 08, 2010 7:31 am Post subject: |
|
|
can you make it run on startup
would be very handy |
|
| Back to top |
|
 |
Bobmonkey07
Joined: 06 Oct 2009 Posts: 58
|
Posted: Thu Apr 08, 2010 2:19 pm Post subject: |
|
|
seems like a good idea to make sure it's only running one instance. simple i know, but probably good for stability. _________________ <ellipsis>...</ellipsis> |
|
| Back to top |
|
 |
bluez
Joined: 23 Oct 2009 Posts: 1
|
Posted: Mon Jun 07, 2010 8:39 am Post subject: |
|
|
Thanks ~,i really like this scrip~  |
|
| Back to top |
|
 |
John Searle Guest
|
Posted: Fri Jul 16, 2010 6:00 am Post subject: |
|
|
I realize this is an old thread, but I just found it...
When using Windows XP I found that it allowed me to switch faster than Windows could handle it, causing windows to be lost, tray tips to be frozen, etc.
To solve this problem I merely added a lock mechanism and timer between window switches to give Windows an appropriate time to switch.
| Code: |
; ---- Snip
USE_PAUSE = 4000
lock = 0
#1::
if(lock = 0)
{
lock = 1
SwitchToDesktop(1)
sleep, %USE_PAUSE%
lock = 0
}
return
#2::
if(lock = 0)
{
lock = 1
SwitchToDesktop(2)
sleep, %USE_PAUSE%
lock = 0
}
return
; ---- Snip
|
I'm about to share this script with other non-tech user and I don't want them to mess their systems up from crazy behaviour. This should curb that behaviour.
Cheers,
John |
|
| Back to top |
|
 |
John Searle Guest
|
Posted: Mon Jul 19, 2010 10:33 pm Post subject: |
|
|
Another update:
Fixed the mutual exclusion lock to properly unlock after execution, instead of waiting for a period and then unlocking.
Fixed two bugs where the Program Manager and the task bar can be sent to another window.
| Code: | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging ;
; turn off or set high to save cpu ;
; when debug is done ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000
; ***** initialization *****
#WinActivateForce
SetBatchLines, -1 ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp ; clean up in case of error (otherwise some windows will get lost)
numDesktops := 4 ; maximum number of desktops
curDesktop := 1 ; index number of current desktop
USE_PAUSE = 1000 ; Tray Tip Pause Length
lock = 0 ; lock to prevent running both hotkeys at same time
; ***** hotkeys *****
#1::
if(lock = 0)
{
lock = 1
SwitchToDesktop(1)
}
return
#2::
if(lock = 0)
{
lock = 1
SwitchToDesktop(2)
}
return
#3::
if(lock = 0)
{
lock = 1
SwitchToDesktop(3)
}
return
#4::
if(lock = 0)
{
lock = 1
SwitchToDesktop(4)
}
return
^!1::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(1)
}
return
^!2::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(2)
}
return
^!3::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(3)
}
return
^!4::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(4)
}
return
#0::goto, cleanup
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
TrayTip, %A_ScriptName%, updated AutoHotkey script
SetTimer, AutoReloadScriptTrayTip, 2000
}
return
AutoReloadScriptTrayTip:
SetTimer, AutoReloadScriptTrayTip, Off
TrayTip
Reload
return
; ***** functions *****
; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
global
if (curDesktop <> newDesktop)
{
GetCurrentWindows(curDesktop)
ShowHideWindows(curDesktop, false)
ShowHideWindows(newDesktop, true)
activate_window := % active_id%newDesktop%
WinActivate, ahk_id %activate_window%
TrayTip, DesktopSwitch, Switching to desktop %newDesktop%
curDesktop := newDesktop
}
SetTimer, RemoveTrayTip, %USE_PAUSE%
sleep, 1000
lock = 0
return
}
; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global
if (curDesktop <> newDesktop)
{
RemoveWindowID(curDesktop, windowID)
; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%
windows%newDesktop%%i% := windowID
WinHide, ahk_id %windowID%
TrayTip, DesktopSwitch, Window send to desktop %newDesktop%
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
SetTimer, RemoveTrayTip, %USE_PAUSE%
}
; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
global
WinGet, id, ID, A
WinGetActiveTitle, curWin
sleep, 200
; If Window Does not have a title, do not send it
if( (curWin = "") || (curWin = "Program Manager"))
{
lock = 0
sleep, 1000
return
}
SendToDesktop(id, newDesktop)
sleep, 1000
lock = 0
}
; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
global
Loop, % windows%desktopIdx%
{
if (windows%desktopIdx%%A_Index% = ID)
{
windows%desktopIdx%%A_Index%= ;Emiel: just empty the array element, array will be emptied by next switch anyway
Break
}
}
}
; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
global
WinGet, active_id%index%, ID, A ; get the current active window
emptyString =
StringSplit, windows%index%, emptyString ; delete the entire windows_index_ array
WinGet, windows%index%, List,,, Program Manager ; get list of all visible windows
; remove windows which we want to see on all virtual desktops
Loop, % windows%index%
{
id := % windows%index%%A_Index%
WinGetClass, windowClass, ahk_id %id%
if windowClass = Shell_TrayWnd ; remove task bar window id
windows%index%%A_Index%= ; just empty the array element, array will be emptied by next switch anyway
if windowClass = #32770 ; we also want multimontaskbar on all virtual desktops
windows%index%%A_Index%= ; just empty the array element, array will be emptied by next switch anyway
if windowClass = cygwin/x X rl-xosview-XOsview-0 ; xosviews e.d.
windows%index%%A_Index%=
if windowClass = cygwin/x X rl-xosview-XOsview-1 ; xosviews e.d.
windows%index%%A_Index%=
if windowClass = MozillaUIWindowClass ; Mozilla thunderbird
{
WinGet, ExStyle, ExStyle, ahk_id %id%
if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST.
windows%index%%A_Index%=
}
}
}
; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
global
Loop, % windows%index%
{
id := % windows%index%%A_Index%
if show
WinShow, ahk_id %id%
else
WinHide, ahk_id %id%
}
}
; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
ShowHideWindows(A_Index, true)
ExitApp
RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return
|
Only bugs left that I can see is the shadow of hidden windows that stick around sometimes when switching windows. For example, the tooltip shadow will sometimes remain after switching, or the start menu shadow will remain if open during a switch.
If anyone has a suggestion on how to fix this last bug, then let me know.
Best,
John |
|
| Back to top |
|
 |
John Searle Guest
|
Posted: Tue Jul 20, 2010 9:03 pm Post subject: |
|
|
And my last update, I promise...
| Code: | #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging ;
; turn off or set high to save cpu ;
; when debug is done ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000
; ***** initialization *****
#WinActivateForce
#NoTrayIcon
SetBatchLines, -1 ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp ; clean up in case of error (otherwise some windows will get lost)
numDesktops := 4 ; maximum number of desktops
curDesktop := 1 ; index number of current desktop
USE_PAUSE = 1000 ; Tray Tip Pause Length
lock = 0 ; lock to prevent running both hotkeys at same time
; ***** hotkeys *****
#1::
if(lock = 0)
{
lock = 1
SwitchToDesktop(1)
}
return
#2::
if(lock = 0)
{
lock = 1
SwitchToDesktop(2)
}
return
#3::
if(lock = 0)
{
lock = 1
SwitchToDesktop(3)
}
return
#4::
if(lock = 0)
{
lock = 1
SwitchToDesktop(4)
}
return
^!1::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(1)
}
return
^!2::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(2)
}
return
^!3::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(3)
}
return
^!4::
if(lock = 0)
{
lock = 1
SendActiveToDesktop(4)
}
return
#0::goto, cleanup
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
ToolTip, %A_ScriptName% updated AutoHotkey script, -1000, -1000
SetTimer, AutoReloadScriptToolTip, 2000
}
return
AutoReloadScriptToolTip:
SetTimer, AutoReloadScriptToolTip, Off
ToolTip
Reload
return
; ***** functions *****
; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
global
WinGetActiveTitle, curWin
sleep, 200
; Removes the chance of getting Start Menu Shadow Frozen on Screen
if(curWin = "")
WinActivate, Program Manager
; Removes the chance of getting Tray or Tooltip shadows frozen on screen
ToolTip
TrayTip
sleep, 200
if (curDesktop <> newDesktop)
{
GetCurrentWindows(curDesktop)
ShowHideWindows(curDesktop, false)
ShowHideWindows(newDesktop, true)
activate_window := % active_id%newDesktop%
WinActivate, ahk_id %activate_window%
ToolTip, Switching to desktop %newDesktop%, -1000, -1000
curDesktop := newDesktop
}
SetTimer, RemoveToolTip, %USE_PAUSE%
sleep, 1000
lock = 0
return
}
; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global
if (curDesktop <> newDesktop)
{
RemoveWindowID(curDesktop, windowID)
; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%
windows%newDesktop%%i% := windowID
WinHide, ahk_id %windowID%
ToolTip, Window sent to desktop %newDesktop%, -1000, -1000
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
SetTimer, RemoveToolTip, %USE_PAUSE%
}
; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
global
WinGet, id, ID, A
WinGetActiveTitle, curWin
sleep, 200
; If Window Does not have a title, do not send it
if( (curWin = "") || (curWin = "Program Manager"))
{
lock = 0
sleep, 1000
return
}
SendToDesktop(id, newDesktop)
sleep, 1000
lock = 0
}
; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
global
Loop, % windows%desktopIdx%
{
if (windows%desktopIdx%%A_Index% = ID)
{
windows%desktopIdx%%A_Index%= ;Emiel: just empty the array element, array will be emptied by next switch anyway
Break
}
}
}
; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
global
WinGet, active_id%index%, ID, A ; get the current active window
emptyString =
StringSplit, windows%index%, emptyString ; delete the entire windows_index_ array
WinGet, windows%index%, List,,, Program Manager ; get list of all visible windows
; remove windows which we want to see on all virtual desktops
Loop, % windows%index%
{
id := % windows%index%%A_Index%
WinGetClass, windowClass, ahk_id %id%
if windowClass = Shell_TrayWnd ; remove task bar window id
windows%index%%A_Index%= ; just empty the array element, array will be emptied by next switch anyway
if windowClass = #32770 ; we also want multimontaskbar on all virtual desktops
windows%index%%A_Index%= ; just empty the array element, array will be emptied by next switch anyway
if windowClass = cygwin/x X rl-xosview-XOsview-0 ; xosviews e.d.
windows%index%%A_Index%=
if windowClass = cygwin/x X rl-xosview-XOsview-1 ; xosviews e.d.
windows%index%%A_Index%=
if windowClass = MozillaUIWindowClass ; Mozilla thunderbird
{
WinGet, ExStyle, ExStyle, ahk_id %id%
if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST.
windows%index%%A_Index%=
}
}
}
; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
global
Loop, % windows%index%
{
id := % windows%index%%A_Index%
if show
WinShow, ahk_id %id%
else
WinHide, ahk_id %id%
}
}
; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
ShowHideWindows(A_Index, true)
ExitApp
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
|
Fixes at least two possible sources of the shadow bug. If the start menu is open, then it activates the desktop before hiding windows. If tooltip or traytips are open, then it closes them.
Cheers,
John |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|