-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowPuller.ahk
More file actions
96 lines (71 loc) · 2.46 KB
/
Copy pathWindowPuller.ahk
File metadata and controls
96 lines (71 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#Requires AutoHotkey v2.0
#SingleInstance Force
dll := A_ScriptDir "\VirtualDesktopAccessor.dll"
if !FileExist(dll) {
MsgBox "VirtualDesktopAccessor.dll not found.`nPlace it in the same folder as this script."
ExitApp
}
GoToDesktopNumber := DllCall.Bind(dll "\GoToDesktopNumber", "Int")
GetCurrentDesktopNumber := DllCall.Bind(dll "\GetCurrentDesktopNumber", "Int")
GetDesktopCount := DllCall.Bind(dll "\GetDesktopCount", "Int")
MoveWindowToDesktopNumber := DllCall.Bind(dll "\MoveWindowToDesktopNumber", "Ptr", , "Int")
; ------------------------------------------------------
; Remembers the last actual active window
; ------------------------------------------------------
global LastWindow := 0
SetTimer WatchActiveWindow, 100
WatchActiveWindow() {
global LastWindow
hwnd := WinExist("A")
if !hwnd
return
class := WinGetClass("ahk_id " hwnd)
; Ignores the Desktop, taskbar, and some system windows
switch class {
case "Progman", "WorkerW", "Shell_TrayWnd", "Windows.UI.Core.CoreWindow":
return
}
LastWindow := hwnd
}
; ------------------------------------------------------
; Desktop switching (native Windows shortcut)
; ------------------------------------------------------
^#Left::Send "^#{Left}"
^#Right::Send "^#{Right}"
; ------------------------------------------------------
; Move window + follow
; ------------------------------------------------------
^#+Left::MoveWindow(-1)
^#+Right::MoveWindow(1)
MoveWindow(direction)
{
global GetCurrentDesktopNumber
global GetDesktopCount
global MoveWindowToDesktopNumber
global GoToDesktopNumber
global LastWindow
; Uses the active window if possible,
; otherwise the last remembered window.
hwnd := WinActive("A")
if !hwnd
hwnd := LastWindow
if !hwnd
return
current := GetCurrentDesktopNumber()
count := GetDesktopCount()
target := current + direction
if (target < 0 || target >= count)
return
; Moves the window to the target desktop
MoveWindowToDesktopNumber(hwnd, target)
; Lets Windows perform the desktop switch
; in order to keep the native animation.
if (direction < 0)
Send "^#{Left}"
else
Send "^#{Right}"
; Wait for the desktop switch to complete
Sleep 500
; Restore focus to the moved window
try WinActivate("ahk_id " hwnd)
}