PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/AutoHotkey.docset/Contents/Resources/Documents/scripts/EasyWindowDrag_(KDE).htm

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