could you help me with next challenge, pls.
I created s script (some parts was copied and modified from existing projects) to use CapsLock with mouse for moving and resizing window dragging for any place on window. Now I want to modify it do the same but with mouse only. Scenario is next:
1. LButton+RButton - drag
2. RButton+Lbutton - resize
Both actions work but not perfect. E.g. Lbutton does a click action and selecting/modifying text in window in action 1. RButton fired context menu after finishing action 2.
I tried different approaches (took from google and this forum) but they didn't work for me.
So, any help on this will be much appreciated.
Probably script can be refactored in better way, in this case you are welcome to correct me. Thank you!
Code: Select all
; Drag windows anywhere
Capslock & LButton::
CoordMode, Mouse
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
mv_mode = mv
SetTimer, EWD_WatchMouse, 10
return
; Resize windows
Capslock & RButton::
CoordMode, Mouse
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, ,, EWD_OriginalPosX, EWD_OriginalPosY, ahk_id %EWD_MouseWin%
mv_mode = sz
SetTimer, EWD_WatchMouse, 10
return
;---------------------------------------------------
; Drag windows anywhere
~LButton & RButton::
While GetKeyState("RButton", "P") {
CoordMode, Mouse
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
mv_mode = mv
SetTimer, EWD_WatchMouse, 10
}
Send {Escape}
return
; Resize windows
~RButton & LButton::
While GetKeyState("LButton", "P") {
CoordMode, Mouse
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, ,, EWD_OriginalPosX, EWD_OriginalPosY, ahk_id %EWD_MouseWin%
mv_mode = sz
SetTimer, EWD_WatchMouse, 10
}
Send {Escape}
return
;---------------------------------------------------
; Function for move and resize windows
EWD_WatchMouse:
if mv_mode = mv
{
GetKeyState, EWD_MButtonState, LButton, P
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
}
if mv_mode = sz
{
GetKeyState, EWD_MButtonState, RButton, P
WinGetPos, ,, EWD_WinX, EWD_WinY, ahk_id %EWD_MouseWin%
}
if EWD_MButtonState = U
{
SetTimer, EWD_WatchMouse, off
return
}
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
SetWinDelay, -1 ; Makes the below move faster/smoother.
if mv_mode = mv
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
if mv_mode = sz
WinMove, ahk_id %EWD_MouseWin%,,,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX
EWD_MouseStartY := EWD_MouseY
WinActivate ahk_id %EWD_MouseWin%
return