AutoHotkey Community

It is currently May 24th, 2012, 2:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 13th, 2008, 4:21 am 
Offline

Joined: January 13th, 2008, 4:12 am
Posts: 4
I was not entirely happy with the existing scripts for doing this, so I ended up writing my own.

The script itself is a bit simpler then the others for a couple reasons:
1) I did not write or include any other functionality besides window dragging
2) The logic for moving the window is a bit simpler over the other scripts I've seen
3) IMHO, the script is commented and formatted a bit better.


Anyhow, nothing great. :)

EDIT: Updated to be even simpler thanks to a couple tips posted by Lexikos

Code:
;-------------------------------------------------
; Window dragging via alt+lbutton                -
; Author: Lasmori (email AT lasmori D0T com)     -
;-------------------------------------------------
!LButton::

CoordMode, Mouse, Relative
MouseGetPos, cur_win_x, cur_win_y, window_id
WinGet, window_minmax, MinMax, ahk_id %window_id%

; Return if the window is maximized or minimized
if window_minmax <> 0
{
  return
}

CoordMode, Mouse, Screen
SetWinDelay, 0

loop
{
  ; exit the loop if the left mouse button was released
  if !GetKeyState("LButton", "P")
  {
    break
  }

  ; move the window based on cursor position
  MouseGetPos, cur_x, cur_y
  WinMove, ahk_id %window_id%,, (cur_x - cur_win_x), (cur_y - cur_win_y)
}

return
;-------------------------------------------------


Last edited by lasmori on March 16th, 2008, 5:49 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 13th, 2008, 6:12 am 
Offline

Joined: January 11th, 2008, 11:07 am
Posts: 35
Hello, thanks for the script. I alt+left clicked on a window's titlebar and nothing happened. What is the script supposed to do? How do i use it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 7:01 am 
Offline

Joined: January 13th, 2008, 4:12 am
Posts: 4
it lets you move windows. I am using it because my taskbar is on the top and windows tend to get stuck with their titlebars hidden.

It wont work on maximized windows, though it should work great on normal windows.

Its also meant for using on the inside or body or the application, not the title bar... as that already works :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 13th, 2008, 7:09 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
AHKisNice wrote:
Hello, thanks for the script. I alt+left clicked on a window's titlebar and nothing happened. What is the script supposed to do? How do i use it?

The idea is you can "grab" a window by any part (not just the title bar) if you hold down alt.


Last edited by ManaUser on February 9th, 2008, 11:07 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 12:20 pm 
Offline

Joined: January 11th, 2008, 11:07 am
Posts: 35
lol oh thanks, nice script lasmori.
lasmori wrote:
I am using it because my taskbar is on the top and windows tend to get stuck with their titlebars hidden.

Why did you move the taskbar to the top? I am going to try that to see if I like it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2008, 12:58 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
I like how explicitly your variables are named. I'm usually much too lazy. :lol:

I have a few suggestions:
  • A_WinDelay (not A_Win_Delay!) and similar settings need not be reset manually if the thread is going to end.
    the manual wrote:
    SetWinDelay:
    Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).

    Threads:
    When resumed, a thread's settings for things such as ErrorLevel and SendMode are automatically restored to what they were just prior to its interruption;
  • GetKeyState is available as a function, in case you want to avoid an unnecessary variable.
    Code:
    if ! GetKeyState("LButton", "P")
    ; or
    if GetKeyState("LButton", "P") = 0
    ; instead of
    GetKeyState, lbutton_state, LButton, P
    if  lbutton_state = U
  • All purely numeric args (excluding MsgBox) also accept expressions.
    Code:
    WinMove, ahk_id %window_id%,, cur_x - cur_win_x, cur_y - cur_win_y
    ; instead of
    window_x := cur_x - cur_win_x
    window_y := cur_y - cur_win_y
    WinMove, ahk_id %window_id%,, %window_x%, %window_y%


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 28th, 2008, 6:19 am 
Offline

Joined: January 18th, 2008, 12:08 pm
Posts: 15
lasmori wrote:
I was not entirely happy with the existing scripts for doing this, so I ended up writing my own.

The script itself is a bit simpler then the others for a couple reasons:
1) I did not write or include any other functionality besides window dragging
2) The logic for moving the window is a bit simpler over the other scripts I've seen
3) IMHO, the script is commented and formatted a bit better.


Anyhow, nothing great. :)

Code:
;-------------------------------------------------
; Window dragging via alt+lbutton                -
; Author: Lasmori (email AT lasmori D0T com)     -
;-------------------------------------------------
!LButton::
original_win_delay := A_Win_Delay

CoordMode, Mouse, Relative
MouseGetPos, cur_win_x, cur_win_y, window_id
WinGet, window_minmax, MinMax, ahk_id %window_id%

; Return if the window is maximized or minimized
if window_minmax <> 0
{
  return
}

CoordMode, Mouse, Screen
SetWinDelay, 0

loop
{
  ; exit the loop if the left mouse button was released
  GetKeyState, lbutton_state, LButton, P
  if lbutton_state = U
  {
    break
  }

  MouseGetPos, cur_x, cur_y
  window_x := cur_x - cur_win_x
  window_y := cur_y - cur_win_y
  WinMove, ahk_id %window_id%,, %window_x%, %window_y%
}

SetWinDelay, %original_win_delay%

return
;-------------------------------------------------


Very nice!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: moving windows
PostPosted: January 29th, 2008, 9:11 pm 
Offline

Joined: November 5th, 2007, 7:25 pm
Posts: 454
Location: canada
Didnt test the script but many people dont know that if you

ALT+Space ona window

then press M = move

You can use the arrrow keys to move a window then press enter to "execute" the move

this is part of windows not ahk.

Anyhow.. my 2 copper


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2008, 10:03 pm 
Offline

Joined: December 6th, 2007, 12:48 pm
Posts: 364
Nice script brother! i'm using it! Are you planning to write a clean code for the Window resize function too? :)

_________________
AHK is perfect.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 5:37 pm 
Offline

Joined: January 13th, 2008, 4:12 am
Posts: 4
Da Rossa wrote:
Nice script brother! i'm using it! Are you planning to write a clean code for the Window resize function too? :)


Sister, not brother :)

Hmm... I had no plans to do so but could if someone wants it bad enough. I obviously haven't been paying attention to the forum for a while. (Actually just had surgery...)


I also wanted to thank the above poster on the tips.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 6:06 pm 
Offline

Joined: January 13th, 2008, 4:12 am
Posts: 4
AHKisNice wrote:
lol oh thanks, nice script lasmori.
lasmori wrote:
I am using it because my taskbar is on the top and windows tend to get stuck with their titlebars hidden.

Why did you move the taskbar to the top? I am going to try that to see if I like it.


I dunno... I am a mac user so its just more familiar :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 11:24 pm 
Offline

Joined: December 6th, 2007, 12:48 pm
Posts: 364
lasmori wrote:
Da Rossa wrote:
Nice script brother! i'm using it! Are you planning to write a clean code for the Window resize function too? :)


Sister, not brother :)

Hmm... I had no plans to do so but could if someone wants it bad enough. I obviously haven't been paying attention to the forum for a while. (Actually just had surgery...)


I also wanted to thank the above poster on the tips.

_________________
AHK is perfect.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 18th, 2008, 5:48 pm 
Offline

Joined: April 18th, 2008, 5:43 pm
Posts: 1
Location: Finland
Thanks, this script really works nicely! I had one problem with it though. When I dragged a window it stayed beneath other windows. I added this line to make it be the top window:

Code:
SetWinDelay, 0 ; After this
WinSet, Top,, ahk_id %window_id%

The problem might be because some third party program or the TweakUI xmouse feature, I don't know, but it probably doesn't add much overhead.. :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 26th, 2009, 11:43 pm 
I found that the background windows would not move properly because the mouse position was calculated relative to the active window. This version of the code corrects the movement of background windows.

Code:
;--------------------------------------------------
; Window dragging via alt+lbutton                 -
; Author: Lasmori (email AT lasmori D0T com)      -
; http://www.autohotkey.com/forum/topic27487.html -
;--------------------------------------------------
!LButton::

; Fixed to move background windows properly
CoordMode, Mouse, Screen

MouseGetPos, , , id ; get ID of window under cursor
WinGetTitle, title, ahk_id %id% ; get title of window under cursor
SetTitleMatchMode 3 ; match window that has the exact name as %title%
WinGetPos, win_x, win_y, , , %title% ; get upper left corner of window
MouseGetPos, current_x, current_y, window_id ; get cursor position on the screen (not relative to window)
cur_win_x := current_x - win_x ; calculate relative cursor position
cur_win_y := current_y - win_y
WinGet, window_minmax, MinMax, ahk_id %window_id%

; Return if the window is maximized or minimized
if window_minmax <> 0
{
  return
}

CoordMode, Mouse, Screen
SetWinDelay, 0

loop
{
  ; exit the loop if the left mouse button was released
  if !GetKeyState("LButton", "P")
  {
    break
  }

  ; move the window based on cursor position
  MouseGetPos, cur_x, cur_y
  WinMove, ahk_id %window_id%,, (cur_x - cur_win_x), (cur_y - cur_win_y)
}

return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2009, 6:07 pm 
I cleaned up my code a touch by using the window ID instead of the window title when retrieving the upper left corner coordinates. The result is 2 fewer lines.

Code:
;--------------------------------------------------
; Window dragging via alt+lbutton                 -
; Author: Lasmori (email AT lasmori D0T com)      -
; http://www.autohotkey.com/forum/topic27487.html -
;--------------------------------------------------
!LButton::

; Fixed to move background windows properly
CoordMode, Mouse, Screen

MouseGetPos, , , id ; get ID of window under cursor
WinGetPos, win_x, win_y, , , ahk_id %id% ; get upper left corner of window
MouseGetPos, current_x, current_y, window_id ; get cursor position on the screen (not relative to window)
cur_win_x := current_x - win_x ; calculate relative cursor position
cur_win_y := current_y - win_y
WinGet, window_minmax, MinMax, ahk_id %window_id%

; Return if the window is maximized or minimized
if window_minmax <> 0
{
  return
}

CoordMode, Mouse, Screen
SetWinDelay, 0

loop
{
  ; exit the loop if the left mouse button was released
  if !GetKeyState("LButton", "P")
  {
    break
  }

  ; move the window based on cursor position
  MouseGetPos, cur_x, cur_y
  WinMove, ahk_id %window_id%,, (cur_x - cur_win_x), (cur_y - cur_win_y)
}

return


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], maraskan_user, RaptorX and 20 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