Created
August 18, 2016 19:36
-
-
Save elken/74e056c560a19bb7027cc35df58ef0e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
; #Warn ; Enable warnings to assist with detecting common errors. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
FileInstall, VirtualDesktopAccessor.dll, %A_ScriptDir%\VirtualDesktopAccessor.dll, 1 | |
SetTitleMatchMode 2 | |
DetectHiddenWindows, On | |
hVirtualDesktopAccessor := DllCall("LoadLibrary", Str, "VirtualDesktopAccessor.dll", "Ptr") | |
GoToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GoToDesktopNumber", "Ptr") | |
GetCurrentDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GetCurrentDesktopNumber", "Ptr") | |
IsWindowOnCurrentVirtualDesktopProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "IsWindowOnCurrentVirtualDesktop", "Ptr") | |
MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "MoveWindowToDesktopNumber", "Ptr") | |
RegisterPostMessageHookProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "RegisterPostMessageHook", "Ptr") | |
UnregisterPostMessageHookProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "UnregisterPostMessageHook", "Ptr") | |
IsPinnedWindowProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "IsPinnedWindow", "Ptr") | |
;GetWindowDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GetWindowDesktopNumber", "Ptr") | |
activeWindowByDesktop := {} | |
MoveCurrentWindowToDesktop(number, handle) { | |
global MoveWindowToDesktopNumberProc, GoToDesktopNumberProc, activeWindowByDesktop | |
activeWindowByDesktop[number] := 0 ; Do not activate | |
DllCall(MoveWindowToDesktopNumberProc, UInt, handle, UInt, number) | |
;DllCall(GoToDesktopNumberProc, UInt, number) | |
} | |
GoToDesktopNumber(num) { | |
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc, IsPinnedWindowProc, activeWindowByDesktop | |
; Store the active window of old desktop, if it is not pinned | |
WinGet, activeHwnd, ID, A | |
current := DllCall(GetCurrentDesktopNumberProc, UInt) | |
isPinned := DllCall(IsPinnedWindowProc, UInt, activeHwnd) | |
if (isPinned == 0) { | |
activeWindowByDesktop[current] := activeHwnd | |
} | |
; Try to avoid flashing task bar buttons, deactivate the current window if it is not pinned | |
if (isPinned != 1) { | |
WinActivate, ahk_class Shell_TrayWnd | |
} | |
; Change desktop | |
DllCall(GoToDesktopNumberProc, Int, num) | |
return | |
} | |
GoToNextDesktop() { | |
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc | |
current := DllCall(GetCurrentDesktopNumberProc, UInt) | |
if (current = 7) { | |
GoToDesktopNumber(0) | |
} else { | |
GoToDesktopNumber(current + 1) | |
} | |
return | |
} | |
#Persistent | |
#SingleInstance | |
Menu, tray, add | |
Menu, tray, add, Send Window, Send | |
Menu, tray, add, Get Window, Get | |
return | |
Send: | |
WinGet, ibid, ID, IB Trader Workstation | |
MoveCurrentWindowToDesktop(1, ibid) | |
return | |
Get: | |
WinGet, ibid, ID, IB Trader Workstation | |
MoveCurrentWindowToDesktop(0, ibid) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment