Jump to content

Check to see if a window is moving


Recommended Posts

Hey,

I am doing some window movements.

Basically, I am making some physics to the window. Lets say you want to move a window, normally you would drag it to the desired location. But with this, you click the title, and flick the mouse, let go, and it moves. Then if it hits the desktops sides it will bound back.

#cs
    Name: Window Physics
    Author: James Brooks aka Secure_ICT
    Description: Drag windows and let go to see them move!
#ce

HotKeySet("^!e", "_Exit")

#include <Constants.au3>
#include <Misc.au3>

Local $WinTitle, $WinPos, $WinList, $Window

; Window Boundaries
Global $Desktop[2]
$Desktop[0] = @DesktopWidth      ; The desktop width
$Desktop[1] = @DesktopHeight     ; The desktop height

While WinActive($WinTitle)
    _WindowName()
Wend

While 1
    _WinMoveCheck()
Wend

Func _WindowName()
    $WinTitle = WinGetTitle("")
    ConsoleWrite($WinTitle & @CRLF)
EndFunc

Func _WinMoveCheck()
    $Window = WinGetPos("")
    For $i = 1 to 40
        WinMove($WinTitle, "", $Window[0] - 1, $Window[1]) 
    Next
EndFunc

Func _BouncBack()
    If $WinTitle = $Desktop[0] or $Desktop[1] Then
        Do 
            For $b = 1 to 5
                WinMove($WinTitle, "", $Window[0] + 1, $Window[1])
            Next
        Until WinGetPos($Window, "") = $Desktop[0] + 10
    EndIf
EndFunc

Func _Exit()
    Exit
EndFunc

I'm not sure on how to,

  • Get the window to bounce back if it hits the sides
  • How to know if a window is moving
Any help is much appreciated.

Thanks,

James

Link to comment
Share on other sites

Basically, I am making some physics to the window. Lets say you want to move a window, normally you would drag it to the desired location. But with this, you click the title, and flick the mouse, let go, and it moves. Then if it hits the desktops sides it will bound back.

I'm not sure on how to,

  • Get the window to bounce back if it hits the sides
  • How to know if a window is moving

WinGetPos() returns X, Y, width, height of the window:

- If X <= 0 then you hit the left side

- If X + width >= @DesktopWidth then you hit the right side

- If Y <=0 then you hit the top

- If Y + height >= @DesktopHeight then you hit the bottom

If X or Y change from loop to loop then it's moving.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hmm, I tried to check if it hit left or right sides, but it doesnt work.

#cs
    Name: Window Flicker
    Author: James Brooks aka Secure_ICT
    Description: Drag windows and let go to see them move!
#ce

HotKeySet("^!e", "_Exit")
Opt("WinTitleMatchMode", 2)

#include <Misc.au3>

If _Singleton("W1NFL1CK3R", 1) = 0 Then
    MsgBox(0x10, "Error", "An occurence of Window Flicker is already running.")
EndIf

Local $ProgramName, $Window, $WindowList

Global $DesktopBound[2]
$DesktopBound[0] = @DesktopHeight / @DesktopHeight + @DesktopHeight - 1
$DesktopBound[1] = @DesktopWidth / @DesktopWidth + @DesktopWidth - 1

$Window = WinGetTitle($Window)  
$Program = WinGetPos("")
$x = $Program[0]
$y = $Program[1]
$Width = $Program[2]
$Height = $Program[3]

; Sleep(1000)
; _ErrorBound()

While 1
    $ProgramName = WinGetTitle("", "")
    ;_DesktopBorder()
WEnd

#cs
    Func _Bounce()
    If $ProgramBound[0] or $ProgramBound[1] = 0 Then
    Do
    For $a = 1 To 10
    WinMove($ProgramName, "", @DesktopWidth / 2, @DesktopHeight / 2)
    Next
    Until $Program = @DesktopWidth / 2 & @DesktopHeight / 2
    EndIf
    EndFunc
#ce

Func _DesktopBorder()
    ; For $b = 1 To @DesktopHeight
    ;   _BounceWindow()
    ; Next
    If $Program <= 0 Then MsgBox(0, "You hit:", "The left side!")
    If $WindowList + $Width >= @DesktopWidth Then MsgBox(0, "You hit:", "The right side!")
EndFunc   ;==>_DesktopBorder

Func _WinList()
    $WindowList = WinList()
    For $c = 1 To $WindowList[0][0]
        ;
    Next
EndFunc   ;==>_WinList

Func _ErrorBound()
    #cs
        Used for Checking errors
    #ce
    ; MsgBox(0, "Desktop Info", "Your Desktop Boundary is: Height: " & $DesktopBound[0] & " Width: " & $DesktopBound[1])
    ; MsgBox(0, "Program Info", "Your Program Boundary is: Height: " & $ProgramBound[0] & " Width: " & $ProgramBound[1])
EndFunc   ;==>_ErrorBound

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Ok, I tried doing it all. But the window just keeps moving continuosly. I only want to make it move if it hits the border.

#cs
    Name: Window Flicker
    Author: James Brooks aka Secure_ICT
    Description: Drag windows and let go to see them move!
#ce

HotKeySet("^!e", "_Exit")
Opt("WinTitleMatchMode", 2)

#include <Misc.au3>

If _Singleton("W1NFL1CK3R", 1) = 0 Then
    MsgBox(0x10, "Error", "An occurence of Window Flicker is already running.")
    Exit
EndIf

Local $ProgramName, $Window, $WindowList

Global $DesktopBound[2]
$DesktopBound[0] = @DesktopHeight / @DesktopHeight + @DesktopHeight - 1
$DesktopBound[1] = @DesktopWidth / @DesktopWidth + @DesktopWidth - 1

$Window = WinGetTitle($Window)  
$Program = WinGetPos("")
$x = $Program[0]
$y = $Program[1]
$Width = $Program[2]
$Height = $Program[3]

While 1
    $ProgramName = WinGetTitle("", "")
    _DesktopBorder()
WEnd

Func _DesktopBorder()
    If $x <= 0 Then WinMove($Program, "", Random(100, 200, 1), $y)
    If $x + $Width >= @DesktopWidth Then WinMove($Program, "", Random(100, 200, 1), $y)
    If $y <= 0 Then WinMove($Program, "", Random(100, 200, 1), $y)
    If $y + $Height >= @DesktopHeight Then WinMove($Program, "", Random(1, $Width, 1), $y)
EndFunc   ;==>_DesktopBorder

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

What is the point of this math gyration?

Global $DesktopBound[2]
$DesktopBound[0] = @DesktopHeight / @DesktopHeight + @DesktopHeight - 1
$DesktopBound[1] = @DesktopWidth / @DesktopWidth + @DesktopWidth - 1oÝ÷ Ø8¯È¨©¥éìmçè­æwû.nÚÚrÛ(¶­Æ¥Á¬¬jëh×6Global $DesktopBound[2]
$DesktopBound[0] = 1 + @DesktopHeight - 1
$DesktopBound[1] = 1 + @DesktopWidth - 1

Why bother with the array, though? Just use the macros @DesktopHeight and @DesktopWidth directly.

And you don't call the array again in the rest of the script fragment you posted.

:)

P.S. You've got the cart before the horse. Nothing here detects a mouse "flick". Nothing here implements any "physics" (like a balistic arc for the window path, maybe). The window movement is random. Etc. Etc.

What in this code has anything to do with your stated script's purpose?

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...