AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The ultimate KDE-style window move/resize/drag script?
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue Jun 20, 2006 5:02 am    Post subject: Reply with quote

Is it just me or does the window jump back and forth between its original position and its new position while you're holding alt and dragging? It's erratic and jarring. I've tried it on three different copies of Windows XP.

-Phil Crosby
Back to top
BoBo
Guest





PostPosted: Tue Jun 20, 2006 7:50 am    Post subject: Reply with quote

@ Phil
please use a nick. You don't have to register for it. Thx for listening. Smile
Back to top
Andrew
Guest





PostPosted: Tue Jul 04, 2006 6:58 am    Post subject: issue with EasyWindowDrag_(KDE).ahk script Reply with quote

hi,

I have placed EasyWindowDrag_(KDE).ahk in my startup folder. I see
that it gets loaded at start up time by the presence of the AHK icon in system tray.

Even though it is loaded, it doesn't function as it should until I manually reload the script. This is the case each & every time my computer boots up.

can someone explain what the problem could be ? I'm running Windows XP (SP 2) and version 1.0.43.06 of AHK.

Thanks
--Andrew
Back to top
evl



Joined: 24 Aug 2005
Posts: 1234

PostPosted: Tue Jul 04, 2006 9:23 am    Post subject: Reply with quote

I'd guess that you have another script which uses the same hotkeys and is loading after this script, hence "grabbing" the hotkeys for itself. Reloading this script would cause it to grab the hotkeys back.
Back to top
View user's profile Send private message
bluedawn
Guest





PostPosted: Mon Nov 06, 2006 6:07 pm    Post subject: Reply with quote

i'm not sure how worth it is, but i noticed that WinMove section of resize can be optimized like this:

from:
Code:

If (KDE_X1 < KDE_WinX1 + KDE_WinW / 2)
   KDE_WinLeft := true
Else
   KDE_WinLeft := false
If (KDE_Y1 < KDE_WinY1 + KDE_WinH / 2)
   KDE_WinUp := true
Else
   KDE_WinUp := false


to:
Code:

If (KDE_X1 < KDE_WinX1 + KDE_WinW / 2)
   KDE_WinLeft := 1
Else
   KDE_WinLeft := -1
If (KDE_Y1 < KDE_WinY1 + KDE_WinH / 2)
   KDE_WinUp := 1
Else
   KDE_WinUp := -1



and from:
Code:

   If KDE_WinLeft
   {
      ; Reverse and apply the offset to the size, and correct for the skewed position.
      KDE_WinX1 += KDE_X2
      KDE_WinW -= KDE_X2
   }
   Else
      KDE_WinW += KDE_X2 ; Apply the offset to the size.
   If KDE_WinUp
   {
      ; Reverse and apply, correct the position.
      KDE_WinY1 += KDE_Y2
      KDE_WinH -= KDE_Y2
   }
   Else
      KDE_WinH += KDE_Y2 ; Apply the offset.
   ; Finally, apply all the changes to the window.
   WinMove,ahk_id %KDE_id%,,%KDE_WinX1%,%KDE_WinY1%,%KDE_WinW%,%KDE_WinH%


to:
Code:

WinMove,ahk_id %KDE_id%,,% KDE_WinX1+(KDE_WinLeft+1)/2*KDE_X2, KDE_WinY1+(KDE_WinUp+1)/2*KDE_Y2, KDE_WinW-KDE_WinLeft*KDE_X2,  KDE_WinH-KDE_WinUp*KDE_Y2


some arithmetic stuff Smile
Back to top
jonny



Joined: 13 Nov 2004
Posts: 2952
Location: Minnesota

PostPosted: Mon Nov 06, 2006 7:10 pm    Post subject: Reply with quote

As a showcase script, the main goal is readability and learnability (word? Very Happy ), so I think the first one should stay as is. However, I like the second one. It seems both faster and more readable. Cool

Have you already tested it?
Back to top
View user's profile Send private message
bluedawn
Guest





PostPosted: Tue Nov 07, 2006 7:42 am    Post subject: Reply with quote

yeah it works fine.
i'm now studying AHK with those nice showcase scripts, and really happy to use them.
by the way, i found more understandable expression. just split Smile

Code:

WinMove,ahk_id %KDE_id%,,% KDE_WinX1 + (KDE_WinLeft+1)/2*KDE_X2  ; X of resized window
                         , KDE_WinY1 +   (KDE_WinUp+1)/2*KDE_Y2  ; Y of resized window
                         , KDE_WinW  -     KDE_WinLeft  *KDE_X2  ; W of resized window
                         , KDE_WinH  -       KDE_WinUp  *KDE_Y2  ; H of resized window
Back to top
jonny



Joined: 13 Nov 2004
Posts: 2952
Location: Minnesota

PostPosted: Wed Nov 08, 2006 5:37 am    Post subject: Reply with quote

I fiddled around with this in my spare time for two days before finally realizing I needed that first optimization of yours to make the second one work. I was trying to find a way to do that arithmetic with the '0' and '1' values, and eventually decided to just change those to '-1' and '1'... and my mind snapped back to your suggestions. I probably should've questioned why you changed the false's to -1's.... Rolling Eyes

Anyway, I included both optimizations and voila, works like a charm. Much thanks for the improvement, I'll see that it's added to the showcase version.

This is some great expression practice, too. Cool
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 2952
Location: Minnesota

PostPosted: Thu Nov 09, 2006 2:45 am    Post subject: Reply with quote

Both the showcase version and the [synchronous] version in the first post of this topic have been updated. Enjoy!
Back to top
View user's profile Send private message
rdk
Guest





PostPosted: Tue Jan 16, 2007 6:29 pm    Post subject: Reply with quote

Anonymous wrote:
Is it just me or does the window jump back and forth between its original position and its new position while you're holding alt and dragging? It's erratic and jarring. I've tried it on three different copies of Windows XP.

-Phil Crosby


Yes, it does the same on my comp. (WIN2000)

AFAIK Windows can be switched into dragmove mode, which could be more "natural" to the system.
Back to top
owl
Guest





PostPosted: Fri Apr 06, 2007 7:48 pm    Post subject: With double clicks instead of double Alts Reply with quote

I hacked this script to use double-clicks instead of doubleAlts:
Code:

KDE_Alt_Left_Tick = 0
.
.
.
!LButton::
; Get the initial mouse position and window id, and
; abort if the window is maximized.
MouseGetPos,KDE_X1,KDE_Y1,KDE_id
WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
If (KDE_Win) {
    if ( (A_TickCount - KDE_Alt_Left_Tick) <300) {
        WinRestore,ahk_id %KDE_id%
        return
    } else {
        KDE_Alt_Left_Tick = %A_TickCount%
        return
    }
   
} else {
    if ( (A_TickCount - KDE_Alt_Left_Tick) <300) {
        WinMaximize,ahk_id %KDE_id%
        return
    } else {
        KDE_Alt_Left_Tick = %A_TickCount%
        ; don't return!
    }
}


And similar code to minimize on Alt right double click.

This is a lot more intuitive for me, probably because I've never used KDE.
That's the cool thing about scripts; in a certain sense it's all configuration, nothing's really hard-coded.

I think you've made a great script here; I use it as example when preaching the wonders of AutoHotKey to coworkers. Very Happy
Back to top
khalid
Guest





PostPosted: Thu May 03, 2007 5:03 am    Post subject: jumping windows??? Reply with quote

Anonymous wrote:
Is it just me or does the window jump back and forth between its original position and its new position while you're holding alt and dragging? It's erratic and jarring. I've tried it on three different copies of Windows XP.

-Phil Crosby


I noticed the same problem after modifying the script. Although the modification does not have any thing to do with the hot key. to illustrate, I am using WIN+LButton to drag and WIN+RButton to move and the script worked just fine.

However, after adding the following lines, the behaviour of dragging and resizing became wiered:
Code:
SystemDoubleClickTime := DllCall("GetDoubleClickTime")
Ctrl::
   If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < SystemDoubleClickTime) {
         send ^!r
   }
return

this simply hook a double-press of the Ctrl key
although it has nothing to do with the WIN key,, it is still giving this wiered behaviour!!!

any suggestions??
-khalid
Back to top
canadaman123
Guest





PostPosted: Thu Sep 20, 2007 4:27 pm    Post subject: Re: lbutton for Alt-Tab Replacement Reply with quote

Iulian wrote:
I would like to use your script, but I also like Alt-Tab Replacement
( http://file.autohotkey.net/evl/AltTab/AltTab.ahk ).
Running both scripts, makes imposible the selection in the task list
(alt+left click) because the kde window moving is triggered.
Is there an work around for this ?

Iulian T.


I customized this window dragging/resizing script to use Ctrl instead of Alt. The only modification other than changing all "!" to "^" and "Alt" to "Ctrl" was to add a ~ in front of ^LButton. This allows you to still use the Ctrl + click to select different files that aren't next to each other. Here's the script with Ctrl:

Code:
/*
AHK Version: 1.0.47.03
Language:    English
Platform:    Win9x/NT
Author:     
*/

#SingleInstance force

; This script was inspired by and built on many like it
; in the forum. Thanks go out to ck, thinkstorm, Chris,
; and aurelian for a job well done.

; Change history:
; November 07, 2006: Optimized resizing code in ^RButton, courtesy of bluedawn.
; February 05, 2006: Fixed double-Ctrl (the ~Ctrl hotkey) to work with latest versions of AHK.

; The Double-Ctrl modifier is activated by pressing
; Ctrl twice, much like a double-click. Hold the second
; press down until you click.
;
; The shortcuts:
;  Ctrl + Left Button  : Drag to move a window.
;  Ctrl + Right Button : Drag to resize a window.
;  Double-Ctrl + Left Button   : Minimize a window.
;  Double-Ctrl + Right Button  : Maximize/Restore a window.
;  Double-Ctrl + Middle Button : Close a window.
;
; You can optionally release Ctrl after the first
; click rather than holding it down the whole time.

If (A_AhkVersion < "1.0.39.00")
{
    MsgBox,20,,This script may not work properly with your version of AutoHotkey. Continue?
    IfMsgBox,No
    ExitApp
}


; This is the setting that runs smoothest on my
; system. Depending on your video card and cpu
; power, you may want to raise or lower this value.
SetWinDelay,2

CoordMode,Mouse
return

~^LButton::
If DoubleCtrl
{
    MouseGetPos,,,KDE_id
    ; This message is mostly equivalent to WinMinimize,
    ; but it avoids a bug with PSPad.
    PostMessage,0x112,0xf020,,,ahk_id %KDE_id%
    DoubleCtrl := false
    return
}
; Get the initial mouse position and window id, and
; abort if the window is maximized.
MouseGetPos,KDE_X1,KDE_Y1,KDE_id
WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
If KDE_Win
    return
; Get the initial window position.
WinGetPos,KDE_WinX1,KDE_WinY1,,,ahk_id %KDE_id%
Loop
{
    GetKeyState,KDE_Button,LButton,P ; Break if button has been released.
    If KDE_Button = U
        break
    MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
    KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
    KDE_Y2 -= KDE_Y1
    KDE_WinX2 := (KDE_WinX1 + KDE_X2) ; Apply this offset to the window position.
    KDE_WinY2 := (KDE_WinY1 + KDE_Y2)
    WinMove,ahk_id %KDE_id%,,%KDE_WinX2%,%KDE_WinY2% ; Move the window to the new position.
}
return

^RButton::
If DoubleCtrl
{
    MouseGetPos,,,KDE_id
    ; Toggle between maximized and restored state.
    WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
    If KDE_Win
        WinRestore,ahk_id %KDE_id%
    Else
        WinMaximize,ahk_id %KDE_id%
    DoubleCtrl := false
    return
}
; Get the initial mouse position and window id, and
; abort if the window is maximized.
MouseGetPos,KDE_X1,KDE_Y1,KDE_id
WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
If KDE_Win
    return
; Get the initial window position and size.
WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
; Define the window region the mouse is currently in.
; The four regions are Up and Left, Up and Right, Down and Left, Down and Right.
If (KDE_X1 < KDE_WinX1 + KDE_WinW / 2)
   KDE_WinLeft := 1
Else
   KDE_WinLeft := -1
If (KDE_Y1 < KDE_WinY1 + KDE_WinH / 2)
   KDE_WinUp := 1
Else
   KDE_WinUp := -1
Loop
{
    GetKeyState,KDE_Button,RButton,P ; Break if button has been released.
    If KDE_Button = U
        break
    MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
    ; Get the current window position and size.
    WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
    KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
    KDE_Y2 -= KDE_Y1
    ; Then, act according to the defined region.
    WinMove,ahk_id %KDE_id%,, KDE_WinX1 + (KDE_WinLeft+1)/2*KDE_X2  ; X of resized window
                            , KDE_WinY1 +   (KDE_WinUp+1)/2*KDE_Y2  ; Y of resized window
                            , KDE_WinW  -     KDE_WinLeft  *KDE_X2  ; W of resized window
                            , KDE_WinH  -       KDE_WinUp  *KDE_Y2  ; H of resized window
    KDE_X1 := (KDE_X2 + KDE_X1) ; Reset the initial position for the next iteration.
    KDE_Y1 := (KDE_Y2 + KDE_Y1)
}
return

; "Ctrl + MButton" may be simpler, but I
; like an extra measure of security for
; an operation like this.
^MButton::
If DoubleCtrl
{
    MouseGetPos,,,KDE_id
    WinClose,ahk_id %KDE_id%
    DoubleCtrl := false
    return
}
return

; This detects "double-clicks" of the Ctrl key.
~Ctrl::
DoubleCtrl := A_PriorHotKey = "~Ctrl" AND A_TimeSincePriorHotkey < 400
Sleep 0
KeyWait Ctrl  ; This prevents the keyboard's auto-repeat feature from interfering.
return


That should free up your Alt key for the Alt + Tab script. Later.
Back to top
cor
Guest





PostPosted: Wed Dec 05, 2007 12:03 am    Post subject: Reply with quote

I discovered this yesterday in the showcase (via google for KDE resizing in Windows XP) and it's almost exactly what I was looking for. Good work! I wish I'd searched for this a year ago!

I notice that the windows don't snap to the edge, like KDE does, so I added that..

Code:
; Easy Window Dragging -- KDE style (requires XP/2k/NT) -- by Jonny
; http://www.autohotkey.com
; This script makes it much easier to move or resize a window: 1) Hold down
; the ALT key and LEFT-click anywhere inside a window to drag it to a new
; location; 2) Hold down ALT and RIGHT-click-drag anywhere inside a window
; to easily resize it; 3) Press ALT twice, but before releasing it the second
; time, left-click to minimize the window under the mouse cursor, right-click
; to maximize it, or middle-click to close it.

; This script was inspired by and built on many like it
; in the forum. Thanks go out to ck, thinkstorm, Chris,
; and aurelian for a job well done.

; Change history:
; December 04, 2007: Window snap-to-edge - just like KDE, but with extra fun! (or @ corz.org ;o)
; November 07, 2006: Optimized resizing code in !RButton, courtesy of bluedawn.
; February 05, 2006: Fixed double-alt (the ~Alt hotkey) to work with latest versions of AHK.

; The Double-Alt modifier is activated by pressing
; Alt twice, much like a double-click. Hold the second
; press down until you click.
;
; The shortcuts:
;  Alt + Left Button  : Drag to move a window.
;  Alt + Right Button : Drag to resize a window.
;  Double-Alt + Left Button   : Minimize a window.
;  Double-Alt + Right Button  : Maximize/Restore a window.
;  Double-Alt + Middle Button : Close a window.
;
; You can optionally release Alt after the first
; click rather than holding it down the whole time.
;
;  Snap-To Edges. by (or .. Tuesday Dec 04, 2007
;
;  I added snap-to for the windows. If their edge comes within ten pixels
;  of your desktop edge, the window snaps to it. Very neat; it's what KDE
;  does. But there's more..
;
;  If you keep mousing after the window snaps, you get a beautiful
;  resizing control which keeps on going. Also you can Alt-right-click
;  any oversized windows and pop them straight back into the desktop.
;  Note: If you are quick enough, you can break the snap when needed.
;  Have fun!
;  ;o)
;


If (A_AhkVersion < "1.0.39.00")
{
    MsgBox,20,,This script may not work properly with your version of AutoHotkey. Continue?
    IfMsgBox,No
    ExitApp
}


; This is the setting that runs smoothest on my
; system. Depending on your video card and cpu
; power, you may want to raise or lower this value.
SetWinDelay,2

CoordMode,Mouse
return

!LButton::
If DoubleAlt
{
    MouseGetPos,,,KDE_id
    ; This message is mostly equivalent to WinMinimize,
    ; but it avoids a bug with PSPad.
    PostMessage,0x112,0xf020,,,ahk_id %KDE_id%
    DoubleAlt := false
    return
}
; Get the initial mouse position and window id, and
; abort if the window is maximized.
MouseGetPos,KDE_X1,KDE_Y1,KDE_id
WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
If KDE_Win
    return
; Get the initial window position.
WinGetPos,KDE_WinX1,KDE_WinY1,,,ahk_id %KDE_id%
Loop
{
    GetKeyState,KDE_Button,LButton,P ; Break if button has been released.
    If KDE_Button = U
        break
    MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
    KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
    KDE_Y2 -= KDE_Y1
    KDE_WinX2 := (KDE_WinX1 + KDE_X2) ; Apply this offset to the window position.
    KDE_WinY2 := (KDE_WinY1 + KDE_Y2)
    WinMove,ahk_id %KDE_id%,,%KDE_WinX2%,%KDE_WinY2% ; Move the window to the new position.
}
return

!RButton::
If DoubleAlt
{
    MouseGetPos,,,KDE_id
    ; Toggle between maximized and restored state.
    WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
    If KDE_Win
        WinRestore,ahk_id %KDE_id%
    Else
        WinMaximize,ahk_id %KDE_id%
    DoubleAlt := false
    return
}
; Get the initial mouse position and window id, and
; abort if the window is maximized.
MouseGetPos,KDE_X1,KDE_Y1,KDE_id
WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
If KDE_Win
    return
; Get the initial window position and size.
WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
; Define the window region the mouse is currently in.
; The four regions are Up and Left, Up and Right, Down and Left, Down and Right.
If (KDE_X1 < KDE_WinX1 + KDE_WinW / 2)
   KDE_WinLeft := 1
Else
   KDE_WinLeft := -1
If (KDE_Y1 < KDE_WinY1 + KDE_WinH / 2)
   KDE_WinUp := 1
Else
   KDE_WinUp := -1
Loop
{
    GetKeyState,KDE_Button,RButton,P ; Break if button has been released.
    If KDE_Button = U
        break
    MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
    ; Get the current window position and size.
    WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
    KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
    KDE_Y2 -= KDE_Y1

   ; snap the window to the edge of the screen if closer than 10 pixels..

   if KDE_WinX1 < 10
      KDE_WinX1 := 0

   if KDE_WinY1 < 10
      KDE_WinY1 := 0

   if KDE_WinX1 + KDE_WinW > A_ScreenWidth - 10
      KDE_WinX1 := A_ScreenWidth - KDE_WinW

   if KDE_WinY1 + KDE_WinH > A_ScreenHeight - 10
      KDE_WinY1 := A_ScreenHeight - KDE_WinH

    ; Then, act according to the defined region.
    WinMove,ahk_id %KDE_id%,, KDE_WinX1 + (KDE_WinLeft+1)/2*KDE_X2  ; X of resized window
                            , KDE_WinY1 +   (KDE_WinUp+1)/2*KDE_Y2  ; Y of resized window
                            , KDE_WinW  -     KDE_WinLeft  *KDE_X2  ; W of resized window
                            , KDE_WinH  -       KDE_WinUp  *KDE_Y2  ; H of resized window
    KDE_X1 := (KDE_X2 + KDE_X1) ; Reset the initial position for the next iteration.
    KDE_Y1 := (KDE_Y2 + KDE_Y1)
}
return

; "Alt + MButton" may be simpler, but I
; like an extra measure of security for
; an operation like this.
!MButton::
If DoubleAlt
{
    MouseGetPos,,,KDE_id
    WinClose,ahk_id %KDE_id%
    DoubleAlt := false
    return
}
return

; This detects "double-clicks" of the alt key.
~Alt::
DoubleAlt := A_PriorHotKey = "~Alt" AND A_TimeSincePriorHotkey < 400
Sleep 0
KeyWait Alt  ; This prevents the keyboard's auto-repeat feature from interfering.
return


My first AutoHotKey coding. Fun. Now I just need to figure out how to get it to replace Windows' poor implementation of X-Window raising, and I'm done!

;o)
(or

ps. you other guys.. KDE uses Alt-Click, okay!
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Wed Dec 05, 2007 12:10 am    Post subject: Reply with quote

cor wrote:
Now I just need to figure out how to get it to replace Windows' poor implementation of X-Window raising, and I'm done!


Do you mean: http://www.autohotkey.com/forum/viewtopic.php?t=22763
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group