AutoHotkey Community

It is currently May 27th, 2012, 9:34 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: November 1st, 2004, 2:10 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
The below example shows how to drag a spot anywhere inside a window and make the whole window follow the mouse. Although it uses a GUI window, it could be adapted to work on any particular window, or even on all windows.
Code:
gui, -caption +0x40000  ; 0x40000 is WS_THICKFRAME (needed for AlwaysOnTop).
gui, add, text,, Text to display
gui, show
WinGet, GuiID, ID, A
WinSet, AlwaysOnTop, On, A
return

~LButton::
CoordMode, Mouse
MouseGetPos, MouseStartX, MouseStartY, MouseWin
if MouseWin <> %GuiID%
   return
; Otherwise, track the mouse as the user drags it:
SetTimer, WatchMouse, 10
return

WatchMouse:
GetKeyState, LButtonState, LButton, P
if LButtonState = U  ; Button has been released, so drag is complete.
{
   SetTimer, WatchMouse, off
   return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, MouseX, MouseY
DeltaX = %MouseX%
DeltaX -= %MouseStartX%
DeltaY = %MouseY%
DeltaY -= %MouseStartY%
MouseStartX = %MouseX%  ; Update for the next timer call to this subroutine.
MouseStartY = %MouseY%
WinGetPos, GuiX, GuiY,,, ahk_id %GuiID%
GuiX += %DeltaX%
GuiY += %DeltaY%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %GuiID%,, %GuiX%, %GuiY%
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2004, 10:24 am 
Available in the scripts showcase section ? Yes, or ?
Yes, yes, yes (the "bit" would answer @ Tron)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2004, 12:48 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
It seems a little too obscure for that. But it's here in case anyone ever searches for such a thing.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Universal drag?
PostPosted: November 13th, 2004, 3:55 am 
I'm not a very expereienced AHK user, so my understanding of this script is superficial to say the least. I get the jist of it, though. Would it be possible to apply the concept to all windows, with a hotkey like ALT+Lbutton, instead of just the gui AHK creates? (Linux style)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2004, 3:05 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Here is a revised version that works on any window. Since there is more interest than I expected, I've put it here: http://www.autohotkey.com/docs/scripts/ ... owDrag.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 15th, 2004, 5:13 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Chris, did I ever tell you you're my hero? It took all of 30 seconds to get one of my fave *nix features ported. :shock:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher, nomissenrojb, Stigg and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group