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
Moving a window via mouse without dragging its title bar
Started by
Chris
, Nov 01 2004 01:10 PM
5 replies to this topic
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.
#1
-
Posted 01 November 2004 - 01:10 PM
Available in the scripts showcase section ? Yes, or ?
Yes, yes, yes (the "bit" would answer @ Tron)
Yes, yes, yes (the "bit" would answer @ Tron)
#2
-
Posted 02 November 2004 - 09:24 AM
It seems a little too obscure for that. But it's here in case anyone ever searches for such a thing.
#3
-
Posted 02 November 2004 - 11:48 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)
#4
-
Posted 13 November 2004 - 02:55 AM
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.autohotke... ... owDrag.htm
#5
-
Posted 13 November 2004 - 02:05 PM
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:
#6
-
Posted 15 November 2004 - 04:13 PM