This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinDrag.ahk
85 lines (76 loc) · 3.32 KB
/
WinDrag.ahk
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
; Original ahk script:
; Easy Window Dragging (requires XP/2k/NT)
; https://www.autohotkey.com
; Normally, a window can only be dragged by clicking on its title bar.
; This script extends that so that any point inside a window can be dragged.
; To activate this mode, hold down CapsLock or the middle mouse button while
; clicking, then drag the window to a new position.
; Note: You can optionally release CapsLock or the middle mouse button after
; pressing down the mouse button rather than holding it down the whole time.
; This script requires v1.0.25+.
#if AltDragToggle
~RWin & MButton::
~LWin & MButton::
CoordMode, Mouse
MouseGetPos, , , win
WinGetClass,aClass,ahk_id %win%
if (aClass = "WorkerW" or aClass = "Windows.UI.Core.CoreWindow" or aClass = "Shell_TrayWnd")
Return
WinClose, ahk_id %win%
return
~RWin & LButton::
~LWin & LButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
; except Windows desktop and windows basic UI ( like windows search and control panel)
WinGetClass,aClass,ahk_id %EWD_MouseWin%
if (aClass = "WorkerW" or aClass = "Windows.UI.Core.CoreWindow" or aClass = "Shell_TrayWnd")
Return
; Only if the window isn't maximized
CheckAndResetMaximizedWindow(aClass)
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, winState, MinMax, ahk_id %EWD_MouseWin%
if winState = 0
WinActivate, ahk_id %EWD_MouseWin%
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return
ResetWindowToNormal(winId) {
WinGet, winState, MinMax, ahk_id %winId%
if winState = 1 ; 1 means maximized
WinRestore, ahk_id %winId%
}
CheckAndResetMaximizedWindow(appClass) {
WinGet, winList, List, ahk_class %appClass%
MouseGetPos, , , mouseWinId ; 获取鼠标下窗口的ID
Loop, %winList%
{
this_id := winList%A_Index%
if (this_id = mouseWinId) ; 检查当前窗口是否与鼠标下的窗口匹配
ResetWindowToNormal(this_id)
}
}
#If