Sign in to follow this  
Followers 0
st4vr0s

If window moves move it back

6 posts in this topic

Hi,

I have a dual monitor setup.

Left screen is main window, right screen has a stats window of my pc.

Whenever I play a game at the monitors non-native resolution the stats box on the right screen moves over to the right and I cant read half the info.

I want to write a script that runs at start up that will check to see if my stats window is in a certain position in relation to the screen. If it moves it moves it back straight away then when I quit gaming and return to the desktop back at native res it moves it back.

In other words I need a script that always checks to see if a window is always at a certain position.

I'm running into a brick wall here, can anyone help?

Thanks

Share this post


Link to post
Share on other sites



WinGetPos() and WinMove()


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

I'll be brutally honest. I'm still quite new to autoit and have only written a few scripts that do work :D

Could anyone write be a brief script to say for example move ("Untitled - Notepad") then check to see if its moved and move back, needs to be in a loop forever checking to see if windows moved.

I'm sure I can modify it to suit.

Thanks again

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$XValue = 50 ;this is the x value that the window should be located at
$YValue = 100 ;this is the y value that the window should be located at 

;Loop
While 1

;Make sure the window exists
If WinExists("Untitled - Notepad") Then

;Find the position of the window
$Position = WinGetPos("Untitled - Notepad")

;Find out if window is in that position
If $Position[0] <> $XValue Then WinMove("Untitled - Notepad", "", $XValue, Default)
If $Position[1] <> $YValue Then WinMove("Untitled - Notepad", "", Default, $YValue)

EndIf

Sleep(250) ;save the cpu a few cycles

WEnd

This code is untested, but should work.

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Because I was bored.

Global $title = "Untitled - Notepad"
While 1
    If WinExists($title) Then
        $whnd = WinGetHandle($title)
        $pos = WinGetPos($whnd)
        While WinExists($title)
            $currpos = WinGetPos($whnd)
            For $a = 0 To 3
                If $pos[$a] <> $currpos[$a] Then
                    WinMove( $whnd, '', $pos[0], $pos[1], $pos[2], $pos[3])
                EndIf
            Next
            Sleep(10)
        WEnd
    EndIf
    Sleep(10)
WEnd

EDIT: Ooops, sorry dantay9, didn't see your post while I was replying.

Edited by danwilli

Share this post


Link to post
Share on other sites

Cheers guys thats much appreciated.

Tried Dantay9's script first and worked a treat, just needed to add a WEnd.

Will give danwilli's a go next.

Many thanks again.

Seeing real world examples like this helps me understand how it works :D

Share this post


Link to post
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
Sign in to follow this  
Followers 0