Jump to content
ingosa

[SOLVED] How to capture If a client window is resized?

Recommended Posts

How to capture If a client window is resized?
I am wondering how you can capture if lets say notepad if being resized?
I want to make a script that adapts the mouse x and y to the new size of the window.
I was thinking of Setting the x and y and the size of the screen in variables and then use a while loop to check if old size is still current size, If not do the math?

I hope some one can help me a bit.
Best Regards

Edited by ingosa

Share this post


Link to post
Share on other sites

Capture what exactly? 

There are quite some build in functions that can get the window information, so what exactly did you try?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Well, lets say you have a square where you want the mouse to click a dot in on one spot.
But when you resize the square you want it to click in the same spot.Like the thing you can do when you make a
GUI and want to make all the buttons to size up to that, But now to get the mouse click in the same spot.

#include <MsgBoxConstants.au3>

$hWnd = "Naamloos - Paint"
WinActivate($hWnd)
WinWaitActive($hWnd)
Global $aClientSizeOLD = WinGetClientSize($hWnd)
Global $x = 340
Global $y = 543
Global $x2
Global $y2
MouseClick("left", $x, $y, 1, 10)

Global $g_bPaused = False

HotKeySet("c", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ; Shift-Alt-d

While 1
    Sleep(100)
WEnd

Func TogglePause()
    ToolTip('Script is "Paused"', 0, 0)
    Example($hWnd, $aClientSizeOLD)
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit
EndFunc   ;==>Terminate

Func Example($hWnd, $aClientSizeOLD)
    WinActivate($hWnd)
    WinWaitActive($hWnd)
    Local $newSize = WinGetClientSize($hWnd)
    
    ; X SECTION
    If ($aClientSizeOLD[0] = $newSize[0]) Then
        ; Deliberd left blank
    Else
        $altery = $newSize[0] - $aClientSizeOLD[0]
        If ($aClientSizeOLD[0] < $newSize[0]) Then
            $x2 = $x - $altery
        Else
            $x2 = $x + $altery
        EndIf
        MouseClick("left", $x, $y2, 1, 10)
        $aClientSizeOLD[1] = $newSize[1]
    EndIf
    
    ; Y Section
    If ($aClientSizeOLD[1] = $newSize[1]) Then
        ; Deliberd left blank
    Else
        $altery = $newSize[1] - $aClientSizeOLD[1]
        If ($aClientSizeOLD[1] < $newSize[1]) Then
            $y2 = $y - $altery
        Else
            $y2 = $y + $altery
        EndIf
        MouseClick("left", $x, $y2, 1, 10)
        $aClientSizeOLD[1] = $newSize[1]
    EndIf
EndFunc   ;==>Example

This is what i have now, I have X section spot on at the moment, But Y section is not working correct. Not getting back to the same spot :S

Share this post


Link to post
Share on other sites

Give me a real case example why you need this and I'll try to assist, but I have grown tired of these BS examples to cover up for possibly something which is against our forumrules.

Jos

(Duidelijker kan ik het niet maken mr. clanfun.nl)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I can understand that, No offense taken.
Well, the thing is i want to use the script as klicking on icons in line so it can click on the icons and send me the text in mail to me.
But i was thinking that i should first have the resize problem solft or i would spend hours on coding and so and than i will resize it, and the script will no longer work :S

Edited by ingosa

Share this post


Link to post
Share on other sites

Help me understand why you choose to answer again with something vague after my pretty direct (Dutch approach) statement?

Listen, I like to help people to get better at AutoIt3, but not when I feel being played with. ;) 

Jos 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I am not Kidding, My phone is broken and sent back to the factory, and i cant use my work phone for it so i use a emulator to run line on it.
But i cant install it on my work phone, and can than still read the contend sent to my by mail from my running laptop / emulator :(

shot1.PNG

shot2.PNG

Share this post


Link to post
Share on other sites

So you want to automate "Line" on this Android emulator to do what exactly? 
Line is an Call/Text app, so which part do you want to automate? 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Well, as i show with the two screenshots when i resize the emu, all get smaller, and move (according to the spot the script is thinking that the icons are at)
What i want is the script to open the emu, That is no problem i can use the run command fore that, But when the emu is started, and the bot starts clicking line, and the buttons are not there becoss of the resize the bot will bot be able to start it at the first place. But after that, when it did start it, it will go to the main chat of line, and grab the text send there and send it to me by mail.
But when i am not at home, i am not the only one using the laptop so my wife or kids can start dragging the emu ore resizing it.

I have no code yet fore that all, becoss i will not start on it if i cant get that resize problem fixt :S

Edited by ingosa

Share this post


Link to post
Share on other sites

Instead of clicking and using send commands, I would suggest that you use Control* functions or UIAutomation.  That way they can be anywhere on the screen and your script will continue to work flawlessly...

Share this post


Link to post
Share on other sites
 ControlClick("[CLASS:subWin]", "", "[CLASS:Button; INSTANCE:1]", "left", 1, 538, 289) 

My guess is that it is not working because its a emu i am running on?

Class:    subWin
Instance:    1
ClassnameNN:    subWin1
Name:    
Advanced (Class):    [CLASS:subWin; INSTANCE:1]
ID:    
Text:    sub
Position:    1, 32
Size:    1080, 608
ControlClick Coords:    538, 289
Style:    0x58000000
ExStyle:    0x00000004
Handle:    0x00291EEA 

Share this post


Link to post
Share on other sites

If control* do not work, then use UIAutomation.  It will most certainly work.  Try using UISpy to check if it can read the controls.

Share this post


Link to post
Share on other sites

Hey ingosa,

Unless @Nine's advice works, maybe you just need to alter the logic of your initial code.

Instead of using display coords (top-left of display 0,0) to find the mouseclick location, try using Window Position.

Something like : (not anyway tested, may need some adjusting but you would get the idea).

Note: Having the window on a 2nd display changes some computations with respect to res/scaling involved.

Note2: You can instead put MouseClick inside the if statement if you want to click only if a resize/re-position of the window occurs. This is how I would try if what you have been advised fails somehow.

Global $hWnd = "title/class"
Global $aWinPosOld = WinGetPos($hWnd)
Global $bWinPosChanged = False

; Initial position of the mouseclick you want
Global $i_x_Click = somenumber
Global $i_y_Click = somenumber

; When you wish to click
if something_happens then click_x_y()



func click_x_y()

    Local $aWinPosNew = WinGetPos($hWnd)

    for $i = 0 to 3
        if $aWinPosOld[$i] <> $aWinPosNew[$i] then $bWinPosChanged = True
    next

    if $bWinPosChanged then
        ; Calculate the new pos
        Local $i_x_WindowNew = $aWinPosNew[0]
        Local $i_y_WindowNew = $aWinPosNew[1]

        Local $i_x_ClickRelative = $i_x_Click - $aWinPosOld[0]
        Local $i_y_ClickRelatve = $i_y_Click - $aWinPosOld[1]
        
        ; Adjust " * ($aWinPosNew[2]/$aWinPosOld[2])" part depending on how the resizing affects
        ; the area you want to click, example is if everything gets scaled up/down
        $i_x_Click = $aWinPosNew[0] + $i_x_ClickRelative * ($aWinPosNew[2]/$aWinPosOld[2]) 
        $i_y_Click = $aWinPosNew[1] + $i_y_ClickRelative * ($aWinPosNew[3]/$aWinPosOld[3])
        
        $aWinPosOld = WinGetPos($hWnd)
        $bWinPosChanged = False
    endif

    ; click same place if pos/size remained same, or new pos if any has changed
    MouseClick("left",$i_x_Click,$i_y_Click,1,10)

endfunc

 

Edited by GokAy
Corrected format for MouseClick in code

Share this post


Link to post
Share on other sites
1 hour ago, Nine said:

If control* do not work, then use UIAutomation. 

We are talking about an Android Emulator program that the OP wishes to automate, so windows controls will not work.


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
1 hour ago, GokAy said:

Hey ingosa,

Unless @Nine's advice works, maybe you just need to alter the logic of your initial code.

Instead of using display coords (top-left of display 0,0) to find the mouseclick location, try using Window Position.

Something like : (not anyway tested, may need some adjusting but you would get the idea).

Note: Having the window on a 2nd display changes some computations with respect to res/scaling involved.

Note2: You can instead put MouseClick inside the if statement if you want to click only if a resize/re-position of the window occurs. This is how I would try if what you have been advised fails somehow.

$hWnd = "(MEmu1)"

Global $aWinPosOld = WinGetPos($hWnd)
Global $bWinPosChanged = False

WinActivate($hWnd)
WinWaitActive($hWnd)

; Initial position of the mouseclick you want
Global $i_x_Click = 539
Global $i_y_Click = 323

Global $x2
Global $y2

Global $g_bPaused = False

HotKeySet("c", "click_x_y")
HotKeySet("{ESC}", "Terminate")

While 1
    Sleep(100)
WEnd

Func Terminate()
    Exit
EndFunc   ;==>Terminate

Func click_x_y()
    Local $aWinPosNew = WinGetPos($hWnd)
    For $i = 0 To 3
        If $aWinPosOld[$i] <> $aWinPosNew[$i] Then $bWinPosChanged = True
    Next
    If $bWinPosChanged Then
        ; Calculate the new pos
        Local $i_x_WindowNew = $aWinPosNew[0]
        Local $i_y_WindowNew = $aWinPosNew[1]
        Local $i_x_ClickRelative = $i_x_Click - $aWinPosOld[0]
        Local $i_y_ClickRelative = $i_y_Click - $aWinPosOld[1]
        ; Adjust " * ($aWinPosNew[2]/$aWinPosOld[2])" part depending on how the resizing affects
        ; the area you want to click, example is if everything gets scaled up/down
        $i_x_Click = $aWinPosNew[0] + $i_x_ClickRelative * ($aWinPosNew[2] / $aWinPosOld[2])
        $i_y_Click = $aWinPosNew[1] + $i_y_ClickRelative * ($aWinPosNew[3] / $aWinPosOld[3])

        $aWinPosOld = WinGetPos($hWnd)
        $bWinPosChanged = False
    EndIf
    ; click same place if pos/size remained same, or new pos if any has changed
    MouseClick("primary", $i_x_Click, $i_y_Click, 10)
EndFunc   ;==>click_x_y

 

Thanks, That solved the problem :) 
I have adapted it to a working script.
Now i will start with the rest of it.

Tanks a lot fore the help you all :) 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...