如何使用 AutoHotKey 右键单击向下拖动 window?
How to drag window using right click down with AutoHotKey?
我想拖动 window 使用带有标题栏的右键单击就像左键单击一样。可以用 AutoHotkey 做到这一点吗?
背景:我使用 Dell Display Manager,它可以让我在 pre-defined 网格中排列我的 windows。我可以直接拖动或 Shift+ 拖动。这两个选项都不是最优的。直接拖动只会强制调整不需要的大小。 Shift 和 Drag 需要键和鼠标。我想知道我是否可以使用右键单击进行拖动。我使用名为 RBTray 的应用程序通过右键单击最小化到托盘。所以,我知道我们绝对可以添加类似的内容。我正在寻找 AutoHotkey 中的一些东西,因为它比 C++ 更容易编码。
这可能是您要查找的内容:https://www.autohotkey.com/docs/scripts/index.htm#EasyWindowDrag
下面是适配右键单击的代码:
~RButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 0 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, RButton, 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
我想拖动 window 使用带有标题栏的右键单击就像左键单击一样。可以用 AutoHotkey 做到这一点吗?
背景:我使用 Dell Display Manager,它可以让我在 pre-defined 网格中排列我的 windows。我可以直接拖动或 Shift+ 拖动。这两个选项都不是最优的。直接拖动只会强制调整不需要的大小。 Shift 和 Drag 需要键和鼠标。我想知道我是否可以使用右键单击进行拖动。我使用名为 RBTray 的应用程序通过右键单击最小化到托盘。所以,我知道我们绝对可以添加类似的内容。我正在寻找 AutoHotkey 中的一些东西,因为它比 C++ 更容易编码。
这可能是您要查找的内容:https://www.autohotkey.com/docs/scripts/index.htm#EasyWindowDrag
下面是适配右键单击的代码:
~RButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 0 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, RButton, 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