PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ahk_scripts/tools/lib/EasyWindowDrag.ahk

http://github.com/jixiuf/my_autohotkey_scripts
AutoHotKey | 45 lines | 31 code | 3 blank | 11 comment | 3 complexity | 0e5d98aa794c51f6e270113e60369377 MD5 | raw file
Possible License(s): GPL-3.0
  1. ; Easy Window Dragging (requires XP/2k/NT)
  2. ; http://www.autohotkey.com
  3. ; Normally, a window can only be dragged by clicking on its title bar.
  4. ; This script extends that so that any point inside a window can be dragged.
  5. ; To activate this mode, hold down CapsLock or the middle mouse button while
  6. ; clicking, then drag the window to a new position.
  7. ; Note: You can optionally release Capslock or the middle mouse button after
  8. ; pressing down the mouse button rather than holding it down the whole time.
  9. ; This script requires v1.0.25+.
  10. ~MButton & LButton::
  11. CapsLock & LButton::
  12. CoordMode, Mouse ; Switch to screen/absolute coordinates.
  13. MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
  14. WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
  15. WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
  16. if EWD_WinState = 0 ; Only if the window isn't maximized
  17. SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
  18. return
  19. EWD_WatchMouse:
  20. GetKeyState, EWD_LButtonState, LButton, P
  21. if EWD_LButtonState = U ; Button has been released, so drag is complete.
  22. {
  23. SetTimer, EWD_WatchMouse, off
  24. return
  25. }
  26. GetKeyState, EWD_EscapeState, Escape, P
  27. if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
  28. {
  29. SetTimer, EWD_WatchMouse, off
  30. WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
  31. return
  32. }
  33. ; Otherwise, reposition the window to match the change in mouse coordinates
  34. ; caused by the user having dragged the mouse:
  35. CoordMode, Mouse
  36. MouseGetPos, EWD_MouseX, EWD_MouseY
  37. WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
  38. SetWinDelay, -1 ; Makes the below move faster/smoother.
  39. WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
  40. EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
  41. EWD_MouseStartY := EWD_MouseY
  42. return