Advertisement
eggbrow

Untitled

Nov 29th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. SetWinDelay,0
  2.  
  3. CoordMode,Mouse
  4. return
  5.  
  6. !LButton::
  7. If DoubleAlt
  8. {
  9. MouseGetPos,,,KDE_id
  10. ; This message is mostly equivalent to WinMinimize,
  11. ; but it avoids a bug with PSPad.
  12. PostMessage,0x112,0xf020,,,ahk_id %KDE_id%
  13. DoubleAlt := false
  14. return
  15. }
  16. ; Get the initial mouse position and window id, and
  17. ; abort if the window is maximized.
  18. MouseGetPos,KDE_X1,KDE_Y1,KDE_id
  19. WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
  20. If KDE_Win
  21. return
  22. ; Get the initial window position.
  23. WinGetPos,KDE_WinX1,KDE_WinY1,,,ahk_id %KDE_id%
  24. Loop
  25. {
  26. GetKeyState,KDE_Button,LButton,P ; Break if button has been released.
  27. If KDE_Button = U
  28. break
  29. MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
  30. KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
  31. KDE_Y2 -= KDE_Y1
  32. KDE_WinX2 := (KDE_WinX1 + KDE_X2) ; Apply this offset to the window position.
  33. KDE_WinY2 := (KDE_WinY1 + KDE_Y2)
  34. WinMove,ahk_id %KDE_id%,,%KDE_WinX2%,%KDE_WinY2% ; Move the window to the new position.
  35. }
  36. return
  37.  
  38. !RButton::
  39. If DoubleAlt
  40. {
  41. MouseGetPos,,,KDE_id
  42. ; Toggle between maximized and restored state.
  43. WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
  44. If KDE_Win
  45. WinRestore,ahk_id %KDE_id%
  46. Else
  47. WinMaximize,ahk_id %KDE_id%
  48. DoubleAlt := false
  49. return
  50. }
  51. ; Get the initial mouse position and window id, and
  52. ; abort if the window is maximized.
  53. MouseGetPos,KDE_X1,KDE_Y1,KDE_id
  54. WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
  55. If KDE_Win
  56. return
  57. ; Get the initial window position and size.
  58. WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
  59. ; Define the window region the mouse is currently in.
  60. ; The four regions are Up and Left, Up and Right, Down and Left, Down and Right.
  61. If (KDE_X1 < KDE_WinX1 + KDE_WinW / 2)
  62. KDE_WinLeft := 1
  63. Else
  64. KDE_WinLeft := -1
  65. If (KDE_Y1 < KDE_WinY1 + KDE_WinH / 2)
  66. KDE_WinUp := 1
  67. Else
  68. KDE_WinUp := -1
  69. Loop
  70. {
  71. GetKeyState,KDE_Button,RButton,P ; Break if button has been released.
  72. If KDE_Button = U
  73. break
  74. MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
  75. ; Get the current window position and size.
  76. WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
  77. KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
  78. KDE_Y2 -= KDE_Y1
  79. ; Then, act according to the defined region.
  80. WinMove,ahk_id %KDE_id%,, KDE_WinX1 + (KDE_WinLeft+1)/2*KDE_X2 ; X of resized window
  81. , KDE_WinY1 + (KDE_WinUp+1)/2*KDE_Y2 ; Y of resized window
  82. , KDE_WinW - KDE_WinLeft *KDE_X2 ; W of resized window
  83. , KDE_WinH - KDE_WinUp *KDE_Y2 ; H of resized window
  84. KDE_X1 := (KDE_X2 + KDE_X1) ; Reset the initial position for the next iteration.
  85. KDE_Y1 := (KDE_Y2 + KDE_Y1)
  86. }
  87. return
  88.  
  89. ; "Alt + MButton" may be simpler, but I
  90. ; like an extra measure of security for
  91. ; an operation like this.
  92. !MButton::
  93. If DoubleAlt
  94. {
  95. MouseGetPos,,,KDE_id
  96. WinClose,ahk_id %KDE_id%
  97. DoubleAlt := false
  98. return
  99. }
  100. return
  101.  
  102. ; This detects "double-clicks" of the alt key.
  103. ~Alt::
  104. DoubleAlt := A_PriorHotkey = "~Alt" AND A_TimeSincePriorHotkey < 400
  105. Sleep 0
  106. KeyWait Alt ; This prevents the keyboard's auto-repeat feature from interfering.
  107. return
  108.  
  109.  
  110. ;add finer movement using control
  111. ;add undo option
  112. ;add snapping to edges and corners of other windows and monitor edge
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement