Sign in to follow this  
Followers 0
singbass

Prevent Window from being moved

4 posts in this topic

I have a script that opens a proprietary application and pulls up a patient monitor. This monitor has a refresh button that needs to be pushed every 2 minutes. Unfortunately there is no keyboard command to get to the button and no controls are exposed when using the Window Info tool. It has to be a mouseclick. What I have done so far is just move to a position and click and it works great. However, if the window gets moved, the click is now in the wrong place.

Q1. I can determine the position and size of the window, then determine the location within that window based on where it is, but will the mouseclick work if the refresh button has been moved off the screen (i.e. can you click beyond your screen resolution)?

Q2. Right now I am going to code it to move the window back to the original location and resize it to the original size before I do the mouse click and that should take care of my problem. I just wondered if there was a way to freeze a window so it couldn't be moved? The nurses still need to interact with other things on the window, I just don't want them to be able to move it or resize it.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

win moves, clicks relative to client, win activate to remove minimize:

; change these to be the x/y relative to your window's client
$x = 24
$y = 50
AutoItSetOption("MouseCoordMode",2)
While True
    $hwnd = WinGetHandle("Your Window Title")
    $iTimer = TimerInit()
    While WinExists($hwnd)
        If TimerDiff($iTimer)>110000 Then
            WinActivate($hwnd)
            WinMove($hwnd, "", 0,0)
            MouseClick("primary",$x,$y)
            $iTimer = TimerInit()
        EndIf
        Sleep (1000)
    WEnd
WEnd

but there are much better ways, using the control* functions

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Rather than hook the windows move and size events I think it would be easier and safer to use a timer.  Periodically check the window's size and position/state and fix it if required.  Then send the mouse click.  I've found generally that a timer function with a trigger of 1/4 second(250 ms) is snappy enough to catch changes while not bogging even fairly slow machines.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I am planning on moving and resizing before clicking.  I just thought if I could "hook the windows move and size events" it might be easier (and less intrusive).  If they couldn't move the window then I wouldn't have a problem.  I just couldn't find anything in the forums that showed me how to do it although I didn't search for 'hook' or 'event'.

I still didn't get Q1 answered so I am playing now to see if mouseclick can take place off the screen.  I am going to guess no, but then I have been wrong in the past (just ask my wife) :argue: .

 

Edit:....Confirmed

Edited by singbass

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