The primary issue is that the window reacts only to every second (skips odd) click (&drag). I can't seem to pin down the problem - my only guess is that Hotkey,On/KeyWait lines somehow interrupt WM_LBUTTONDOWN. The secondary issue - it skips double-clicks in the same manner.
Could someone please give me a hint as to what causes this, and can this be resolved?
Thanks in advance.
Code: Select all
#SingleInstance Force
Gui newWnd:New
Gui newWnd: -ToolWindow -SysMenu -Caption -Theme -Resize +AlwaysOnTop
Gui newWnd: Color, FFFFFF
rectCoordStr := % "x" . 100 . " y" . 100 . " w" . 100 . " h" . 100
Gui newWnd:Show, %rectCoordStr% NoActivate, TEST: CLICK&DRAG ME
OnMessage(0x203, "WM_LBUTTONDBLCLK") ;; window message for the mouse left double-click
OnMessage(0x201, "WM_LBUTTONDOWN") ;; window message for the mouse left click
Return
WM_LBUTTONDBLCLK()
{
MsgBox reserved for other functions
}
WM_LBUTTONDOWN()
{
Hotkey LButton, _WhileHolding, On ;; hotkey for mouse button hold-down
}
_WhileHolding:
CoordMode Mouse, Screen ;; set coordinates relative to the screen
MouseGetPos x1, y1, actWndId
WinGetPos actWndULx, actWndULy, , , ahk_id %actWndId%
x1 := x1 - actWndULx, y1 := y1 - actWndULy
SetTimer _MoveWindow, 15
KeyWait LButton ;; wait for LButton release
SetTimer _MoveWindow, Off
Hotkey LButton, _WhileHolding, Off
Return
_MoveWindow:
CoordMode Mouse, Screen ;; set coordinates relative to the screen
MouseGetPos x2, y2
WinMove ahk_id %actWndId%, , (x2 - x1), (y2 - y1)
Return
ESC::
ExitApp
Return