Advertisement
RiDeag

Untitled

Jan 8th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. ; Easy Window Dragging -- KDE style (requires XP/2k/NT) -- by Jonny
  2. ; http://www.autohotkey.com
  3. ; This script makes it much easier to move or resize a window: 1) Hold down
  4. ; the ALT key and LEFT-click anywhere inside a window to drag it to a new
  5. ; location; 2) Hold down ALT and RIGHT-click-drag anywhere inside a window
  6. ; to easily resize it; 3) Press ALT twice, but before releasing it the second
  7. ; time, left-click to minimize the window under the mouse cursor, right-click
  8. ; to maximize it, or middle-click to close it.
  9.  
  10. ; This script was inspired by and built on many like it
  11. ; in the forum. Thanks go out to ck, thinkstorm, Chris,
  12. ; and aurelian for a job well done.
  13.  
  14. ; Change history:
  15. ; November 07, 2006: Optimized resizing code in !RButton, courtesy of bluedawn.
  16. ; February 05, 2006: Fixed double-alt (the ~Alt hotkey) to work with latest versions of AHK.
  17.  
  18. ; The Double-Alt modifier is activated by pressing
  19. ; Alt twice, much like a double-click. Hold the second
  20. ; press down until you click.
  21. ;
  22. ; The shortcuts:
  23. ; Alt + Left Button : Drag to move a window.
  24. ; Alt + Right Button : Drag to resize a window.
  25. ; Double-Alt + Left Button : Minimize a window.
  26. ; Double-Alt + Right Button : Maximize/Restore a window.
  27. ; Double-Alt + Middle Button : Close a window.
  28. ;
  29. ; You can optionally release Alt after the first
  30. ; click rather than holding it down the whole time.
  31. #NoTrayIcon
  32.  
  33. If (A_AhkVersion < "1.0.39.00")
  34. {
  35. MsgBox,20,,This script may not work properly with your version of AutoHotkey. Continue?
  36. IfMsgBox,No
  37. ExitApp
  38. }
  39.  
  40.  
  41. ; This is the setting that runs smoothest on my
  42. ; system. Depending on your video card and cpu
  43. ; power, you may want to raise or lower this value.
  44. SetWinDelay,2
  45.  
  46. CoordMode,Mouse
  47. return
  48.  
  49. !LButton::
  50. If DoubleAlt
  51. {
  52. MouseGetPos,,,KDE_id
  53. ; This message is mostly equivalent to WinMinimize,
  54. ; but it avoids a bug with PSPad.
  55. PostMessage,0x112,0xf020,,,ahk_id %KDE_id%
  56. DoubleAlt := false
  57. return
  58. }
  59. ; Get the initial mouse position and window id, and
  60. ; abort if the window is maximized.
  61. MouseGetPos,KDE_X1,KDE_Y1,KDE_id
  62. WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
  63. If KDE_Win
  64. return
  65. ; Get the initial window position.
  66. WinGetPos,KDE_WinX1,KDE_WinY1,,,ahk_id %KDE_id%
  67. Loop
  68. {
  69. GetKeyState,KDE_Button,LButton,P ; Break if button has been released.
  70. If KDE_Button = U
  71. break
  72. MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
  73. KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
  74. KDE_Y2 -= KDE_Y1
  75. KDE_WinX2 := (KDE_WinX1 + KDE_X2) ; Apply this offset to the window position.
  76. KDE_WinY2 := (KDE_WinY1 + KDE_Y2)
  77. WinMove,ahk_id %KDE_id%,,%KDE_WinX2%,%KDE_WinY2% ; Move the window to the new position.
  78. }
  79. return
  80.  
  81. !RButton::
  82. If DoubleAlt
  83. {
  84. MouseGetPos,,,KDE_id
  85. ; Toggle between maximized and restored state.
  86. WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
  87. If KDE_Win
  88. WinRestore,ahk_id %KDE_id%
  89. Else
  90. WinMaximize,ahk_id %KDE_id%
  91. DoubleAlt := false
  92. return
  93. }
  94. ; Get the initial mouse position and window id, and
  95. ; abort if the window is maximized.
  96. MouseGetPos,KDE_X1,KDE_Y1,KDE_id
  97. WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
  98. If KDE_Win
  99. return
  100. ; Get the initial window position and size.
  101. WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
  102. ; Define the window region the mouse is currently in.
  103. ; The four regions are Up and Left, Up and Right, Down and Left, Down and Right.
  104. If (KDE_X1 < KDE_WinX1 + KDE_WinW / 2)
  105. KDE_WinLeft := 1
  106. Else
  107. KDE_WinLeft := -1
  108. If (KDE_Y1 < KDE_WinY1 + KDE_WinH / 2)
  109. KDE_WinUp := 1
  110. Else
  111. KDE_WinUp := -1
  112. Loop
  113. {
  114. GetKeyState,KDE_Button,RButton,P ; Break if button has been released.
  115. If KDE_Button = U
  116. break
  117. MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
  118. ; Get the current window position and size.
  119. WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
  120. KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
  121. KDE_Y2 -= KDE_Y1
  122. ; Then, act according to the defined region.
  123. WinMove,ahk_id %KDE_id%,, KDE_WinX1 + (KDE_WinLeft+1)/2*KDE_X2 ; X of resized window
  124. , KDE_WinY1 + (KDE_WinUp+1)/2*KDE_Y2 ; Y of resized window
  125. , KDE_WinW - KDE_WinLeft *KDE_X2 ; W of resized window
  126. , KDE_WinH - KDE_WinUp *KDE_Y2 ; H of resized window
  127. KDE_X1 := (KDE_X2 + KDE_X1) ; Reset the initial position for the next iteration.
  128. KDE_Y1 := (KDE_Y2 + KDE_Y1)
  129. }
  130. return
  131.  
  132. ; "Alt + MButton" may be simpler, but I
  133. ; like an extra measure of security for
  134. ; an operation like this.
  135. !MButton::
  136. If DoubleAlt
  137. {
  138. MouseGetPos,,,KDE_id
  139. WinClose,ahk_id %KDE_id%
  140. DoubleAlt := false
  141. return
  142. }
  143. return
  144.  
  145. ; This detects "double-clicks" of the alt key.
  146. ~Alt::
  147. DoubleAlt := A_PriorHotKey = "~Alt" AND A_TimeSincePriorHotkey < 400
  148. Sleep 0
  149. KeyWait Alt ; This prevents the keyboard's auto-repeat feature from interfering.
  150. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement