Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Easy Windows Dragging... as it was intended


  • Please log in to reply
2 replies to this topic
songsoverruins
  • Members
  • 46 posts
  • Last active: Sep 25 2015 08:43 PM
  • Joined: 01 Oct 2005
After using AutoHotkey for a while now (fantastic app I have to say :D) I would like to share an improved version (in my opinion) of the Easy Window Dragging script with you all.

When I first tried the Easy Window Dragging script I was a bit disappointed by the fact that you have to invoke a second key for the activation. I had hoped it would turn your mouse into something more powerful. Following is an adaptation of the original EWD script (credit for that goes to whoever the original author was, website nor script mention him or her...). With this adaptation it is possible to easily drag a window using just the right mouse button, without the right mouse button losing its native function (invoking a context menu).

I hope this works as well for you as it does for me. In case of any problems, please post a message and I'll try to fix it.


; Easy Windows Dragging V2 (requires XP/2k/NT)
; Author: songsoverruins
; Thanks to the original author of this script, this is merely a perfection of it
; Normally, a window can only be dragged by clicking on its title bar. This script extends that so that any point
; inside a window can be dragged with the right mouse button.
; This script requires v1.0.25+.

RButton::
Loop
{
   If A_TimeSinceThisHotkey > 200                ; If the right mouse button has been held for 
      Break                                       ;more than 200ms                        
   else                                       ; stop this loop and start with the actual EWD code.
      GetKeyState, RButtonState, RButton, P     ; Else, check what the current state of the button is
   If RButtonState = U                          ; If it has been released in the meantime a click was
   {                                       	; intended by the user, so send that. And exit this 
      Send, {RButton}                           ;script.
      Exit
   }
   else                                       	; else, if the button is still depressed, continue 
      continue                                 	; the loop until one of the two above conditions is 
                                                   ;met.
}
; This extra check for the buttonstate within the window
; 0-200 ms is done to make sure this script doesn't block
; the native function of the right mouse button, which is
; is sending a click! If instead ~RButton would have been
; used as hotkey, the click is carried along to the end of
; the script, resulting in the (intended) displacement of
; your window but also an (unintended) right mouse click
; after the window is in its new position.

CoordMode, Mouse  ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return

EWD_WatchMouse:
GetKeyState, EWD_RButtonState, RButton, P
if EWD_RButtonState = U  ; Button has been released, so drag is complete.
{
   SetTimer, EWD_WatchMouse, off
   return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D  ; Escape has been pressed, so drag is cancelled.
{
   SetTimer, EWD_WatchMouse, off
   WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
   return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX  ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return

For the music lover who can sit and enjoy the sound of someone else's evolving nightmare.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for posting this variation.

website nor script mention him or her...

I wrote the original script and Jonny wrote the KDE-style window dragging script.

TheLeO
  • Members
  • 264 posts
  • Last active: Jan 02 2012 01:51 AM
  • Joined: 11 Jun 2005

website nor script mention him or her...

lolies...

btw i dont really have a problem with using a 2nd button cuz my button has the XButton1 and 2 ,
~I use XButton2 to replace alt...

:)
::
I Have Spoken
::