home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 October - Disc 3 / PCNET_CD_2006_10_3.iso / apps / AutoHotkey104411_Install.exe / AutoHotkey.chm / docs / scripts / easywindowdrag.ahk < prev    next >
Encoding:
Text File  |  2006-09-09  |  1.8 KB  |  44 lines

  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.  
  8. ; Note: You can optionally release Capslock or the middle mouse button after
  9. ; pressing down the mouse button rather than holding it down the whole time.
  10. ; This script requires v1.0.25+.
  11.  
  12. ~MButton & LButton::
  13. CapsLock & LButton::
  14. CoordMode, Mouse  ; Switch to screen/absolute coordinates.
  15. MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
  16. WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
  17. SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
  18. return
  19.  
  20. EWD_WatchMouse:
  21. GetKeyState, EWD_LButtonState, LButton, P
  22. if EWD_LButtonState = U  ; Button has been released, so drag is complete.
  23. {
  24.     SetTimer, EWD_WatchMouse, off
  25.     return
  26. }
  27. GetKeyState, EWD_EscapeState, Escape, P
  28. if EWD_EscapeState = D  ; Escape has been pressed, so drag is cancelled.
  29. {
  30.     SetTimer, EWD_WatchMouse, off
  31.     WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
  32.     return
  33. }
  34. ; Otherwise, reposition the window to match the change in mouse coordinates
  35. ; caused by the user having dragged the mouse:
  36. CoordMode, Mouse
  37. MouseGetPos, EWD_MouseX, EWD_MouseY
  38. WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
  39. SetWinDelay, -1   ; Makes the below move faster/smoother.
  40. WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
  41. EWD_MouseStartX := EWD_MouseX  ; Update for the next timer-call to this subroutine.
  42. EWD_MouseStartY := EWD_MouseY
  43. return
  44.