 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Mon Nov 01, 2004 2:10 pm Post subject: Moving a window via mouse without dragging its title bar |
|
|
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 |
|
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Nov 02, 2004 10:24 am Post subject: |
|
|
Available in the scripts showcase section ? Yes, or ?
Yes, yes, yes (the "bit" would answer @ Tron) |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Tue Nov 02, 2004 12:48 pm Post subject: |
|
|
| It seems a little too obscure for that. But it's here in case anyone ever searches for such a thing. |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Nov 13, 2004 3:55 am Post subject: Universal drag? |
|
|
| 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) |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3005 Location: Minnesota
|
Posted: Mon Nov 15, 2004 5:13 pm Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|