Advertisement
Guest User

Untitled

a guest
Nov 25th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. ; Note: You can optionally release the ALT key after pressing down the mouse button
  2. ; rather than holding it down the whole time.
  3.  
  4. ~Alt & LButton::
  5. if WinActive("ahk_class MultitaskingViewFrame")
  6. Click
  7. CoordMode, Mouse ; Switch to screen/absolute coordinates.
  8. MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
  9. WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
  10. WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
  11. if EWD_WinState = 0 ; Only if the window isn't maximized
  12. SetTimer, EWD_WatchMouse_L, 10 ; Track the mouse as the user drags it.
  13. return
  14.  
  15. ~Alt & RButton::
  16. CoordMode, Mouse ; Switch to screen/absolute coordinates.
  17. MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
  18. WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
  19. WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
  20. if EWD_WinState = 0 ; Only if the window isn't maximized
  21. SetTimer, EWD_WatchMouse_R, 10 ; Track the mouse as the user drags it.
  22. return
  23.  
  24. EWD_WatchMouse_L:
  25. GetKeyState, EWD_LButtonState, LButton, P
  26. if EWD_LButtonState = U ; Button has been released, so drag is complete.
  27. {
  28. SetTimer, EWD_WatchMouse_L, off
  29. return
  30. }
  31.  
  32. GetKeyState, EWD_EscapeState, Escape, P
  33. if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
  34. {
  35. SetTimer, EWD_WatchMouse_L, off
  36. WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
  37. return
  38. }
  39.  
  40. ; Otherwise, reposition the window to match the change in mouse coordinates
  41. ; caused by the user having dragged the mouse:
  42. CoordMode, Mouse
  43. MouseGetPos, EWD_MouseX, EWD_MouseY
  44. WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
  45. SetWinDelay, -1 ; Makes the below move faster/smoother.
  46. WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
  47. EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
  48. EWD_MouseStartY := EWD_MouseY
  49. return
  50.  
  51. EWD_WatchMouse_R:
  52. GetKeyState, EWD_LButtonState, RButton, P
  53. if EWD_LButtonState = U ; Button has been released, so drag is complete.
  54. {
  55. SetTimer, EWD_WatchMouse_R, off
  56. return
  57. }
  58.  
  59. GetKeyState, EWD_EscapeState, Escape, P
  60. if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
  61. {
  62. SetTimer, EWD_WatchMouse_R, off
  63. WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
  64. return
  65. }
  66.  
  67. ; Otherwise, reposition the window to match the change in mouse coordinates
  68. ; caused by the user having dragged the mouse:
  69. CoordMode, Mouse
  70. MouseGetPos, EWD_MouseX, EWD_MouseY
  71. WinGetPos, EWD_WinX, EWD_WinY, EWD_WinW, EWD_WinH, ahk_id %EWD_MouseWin%
  72. SetWinDelay, -1 ; Makes the below move faster/smoother.
  73. WinMove, ahk_id %EWD_MouseWin%,,,, EWD_WinW + EWD_MouseX - EWD_MouseStartX, EWD_WinH + EWD_MouseY - EWD_MouseStartY
  74. EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
  75. EWD_MouseStartY := EWD_MouseY
  76. return
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement