AutoHotkey Community

It is currently May 26th, 2012, 7:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: July 25th, 2004, 9:54 pm 
Offline

Joined: July 25th, 2004, 8:00 pm
Posts: 8
I did promise Chris to post this too, so here it is.
But first some quick

Background:
========

Do you ever work with multiple monitors? If you do, you probably have to move windows from one screen to the other quite a lot. Did it ever happen to you that one window for some reason managed to appear off-screen, so you couldn't grab the title bar anymore?

It happened to me last Friday...

I had to laugh out loud when I learned what loops you have to jump through in WindowsXP to remedy this situation.
Get this:
- You have to hover your mouse cursor on the window you want to move.
- Then you have to press [Alt]+[SPACE] to trigger the window menu
- Next you press [M] for move. (Warning: This key is localized, [V] in a German Windows version for example (yeah, I'm forced to use this version at work :( ))
- Now you can use your keyboard (!) cursor keys [UP],[DOWN],[LEFT],[RIGHT] to move the window around.

Yeah, right.... :roll: Well, I already knew AutoHotKey from my recent Umlaute Convenience script so it didn't take me long to glimpse at AutoHotKeys' features to capture mouse input and to move windows around. Well it can do all that, too. :)

Idea:
===

I have worked with KDE on top of Linux a number of times and really liked their solution to move windows around. Here you press [ALT] and click ANYWHERE within ANY window and just start dragging it around with your mouse. Just release [ALT] when you are done.

Well, my idea was to re-produce this behavior in Windows XP.

In this script, I also stumbled upon one minor AutoHotKey (or rather Windows API probably) limitation.
You will notice this when moving maximized windows. I will not go into more details here. See my posting "minor request: ToggleWindowFlags" in the "Wish List" sub forum.

Oh, btw. this script has one unexpected positive side effect. Sometimes windows freeze on me (due to network latencies) for an arbitrary amount of time. Moving these windows around with the AutoHotKey script immediately unfreezes them. :D

Enjoy:

Script:
====

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                      ;;
;; KDE-Style Alt-Grab Window Move Convenience Script    ;;
;;                                                      ;;
;; version 0.1 - 07/24/04                               ;;
;; ck <use www.autohotkey.com forum to contact me>      ;;
;;                                                      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Usage Instructions:
;; -------------------
;; Load Script into AutoHotKey (only verified to work properly with 1.0.16 and Windows XP)
;; - Hold down the Alt key and lef-click anywhere in a window to move the window

LAlt & LButton::
; If this command isn't used, all commands except those documented otherwise (e.g. WinMove and InputBox)
; use coordinates that are relative to the active window
CoordMode, Mouse, Screen

; speed things up
SetWinDelay, 0

; get current mouse position
MouseGetPos, OLDmouseX, OLDmouseY, WindowID

; get the postition and ID of the window under the mouse cursor
WinGetPos, winX, winY, winW, winH ,ahk_id %WindowID%

; Turn off Window Animation
;RegRead, BoolMinAni, HKEY_CURRENT_USER,Control Panel\Desktop\WindowMetrics, MinAnimate
;if BoolMinAni = 1
;{
;   ; this has no effect until it's reloaded / re-logon... (-> disabled code)
;   RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, MinAnimate, 0
;}

; this restore (= undo max or min) call tells the OS that originally
; maximized windows are now restored/normal and can be moved even after this script takes off
; this is absolutely mandatory for windows which remember their last location like IE windows
; otherwise you cannot properly maximize them anymore

;WinHide, ahk_id %WindowID%
WinRestore, ahk_id %WindowID%
WinMove, ahk_id %WindowID%,,%winX%,%winY%,%winW%,%winH%
;WinShow, ahk_id %WindowID%

Loop
{
   ; is the User still keeping that Alt key down?
   GetKeyState, AltKeyState, Alt, P
   if AltKeyState = U ; key has been released
   {
      break
   }
      
   ; get new mouse position
   MouseGetPos, newMouseX, newMouseY

   ; get relative mouse X movement
   if newMouseX < %OLDmouseX%
   {
      ; mouse was moved to the left
      Xdistance = %OLDmouseX%
      EnvSub, Xdistance, %newMouseX%   
      EnvSub, winX, %Xdistance%
   }
   else if newMouseX > %OLDmouseX%
   {
      ; mouse was moved to the right
      Xdistance = %newMouseX%
      EnvSub, Xdistance, %OLDmouseX%   
      EnvAdd, winX, %Xdistance%
   }
   else
   {
      ; mouse X coordinate wasn't changed
   }
   
   ; set OLDmouseX
   OLDmouseX = %newMouseX%

   ; repeat the same stuff for the Y-axis
   if newMouseY < %OLDmouseY%
   {
      Ydistance = %OLDmouseY%
      EnvSub, Ydistance, %newMouseY%   
      EnvSub, winY, %Ydistance%
   }
   else if newMouseY > %OLDmouseY%
   {
      Ydistance = %newMouseY%
      EnvSub, Ydistance, %OLDmouseY%   
      EnvAdd, winY, %Ydistance%
   }
   else
   {
   }
   OLDmouseY = %newMouseY%

   ; move Window accordingly
   WinMove, ahk_id %WindowID%,,%winX%,%winY%
}
return


Last edited by ck on August 9th, 2004, 10:35 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2004, 2:37 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I finally got a chance to try this. Very cool script.

Quote:
only verified to work with 1.0.25 and Windows XP

Minor typo; I think you meant 1.0.15

Quote:
else
{
}

You might be using the above as just part of your coding style, but in case not: You can omit the final else statement if it's empty.

With your permission, I'll post this to the script showcase at http://www.autohotkey.com/docs/scripts/ , perhaps with a few minor style changes since many users study these scripts to learn the commands and syntax.

Great work and thanks for sharing it. I'm sure many both now and in the future will quietly use and benefit from this script.

edit: fixed typo


Last edited by Chris on July 27th, 2004, 11:46 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2004, 9:10 am 
Offline

Joined: July 25th, 2004, 8:00 pm
Posts: 8
Chris wrote:
I finally got a chance to try this. Very cool script.
[...] Great work and thanks for sharing it. I'm sure many both now and in the future will quietly use and benefit this script.


Glad you like it. :-)
But don't forget that without your efforts in creating and documenting AutoHotKey, I wouldn't have been able to write this. Thanks again!

Quote:
Quote:
only verified to work with 1.0.25 and Windows XP

Minor typo; I think you meant 1.0.15


Oops. Yes, of course. I have the same typo in my GermanUmlaute.ahk.

Quote:
Quote:
else
{
}

You might be using the above as just part of your coding style, but in case not: You can omit the final else statement if it's empty.


Yes, I know. In this case I decided consciously to use it for better readability.

Quote:
With your permission, I'll post this to the script showcase at http://www.autohotkey.com/docs/scripts/ , perhaps with a few minor style changes since many users study these scripts to learn the commands and syntax.


Sure, I'd be honoured. Go ahead. :) These showcase scripts helped kick-start me, too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 31st, 2005, 2:23 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Partially inspired by this topic, Jonny has posted the first version of his ultimate KDE-style window dragging/resizing script. If you have an interest, please give it a try and post feedback. http://www.autohotkey.com/forum/viewtopic.php?t=2062


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2009, 10:17 pm 
works awesome in windows 7 too.

the mouse button needs a click then move with alt pressed, not drag to work. not sure if it's a bug or feature, but works nifty!


Report this post
Top
  
Reply with quote  
 Post subject: true
PostPosted: January 22nd, 2010, 2:30 pm 
ture works very nice with win 7 :)


Report this post
Top
  
Reply with quote  
 Post subject: question
PostPosted: January 22nd, 2010, 2:48 pm 
how do i have to change the code, so LButton has to be pressed and alt can be released, so i can move the window around with only the mouse button pressed and not the alt button pressed, i hope you understand, what i mean ^^


Report this post
Top
  
Reply with quote  
 Post subject: Modified
PostPosted: March 14th, 2011, 2:43 pm 
Offline

Joined: February 24th, 2010, 10:17 am
Posts: 42
Thanks ck for your original script.

I've modified it somewhat to release the grab on either releaseing alt or the mouse-button - so releasing either Alt or LButton will stop the window from moving - as well a toltip to display the top/left.

I've also added in the resize functionality that linux provides in the same style - this with Alt+RButton, and the tooltip with width/height displayed. Releasing either the Alt or RButton also stops resizing the window.

I've stored the modified script on my own site at : http://development.twdev.net/index.php/ahk/linux-win-grab/


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: bobbysoon, jrav, Xx7 and 13 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