Jump to content
manit

what happens if window not found

Recommended Posts

hi ,

I have written a script to simulate keypresses and click on some windows 

The work is repetitive.

Here I activate 'foobar' and click on a place in it then press few down arrow keys . Then some keypresses in 'reboot' window ...

(1)It sometimes happen that am external window pops up taking focus away from action being performed by script . As a result ,say, 'reboot' window does not appear . How should I bring scipt to run from beginning (of while loop) again ?

(2)I used window info tool to find coordinates of place to click . Is it possible that window info tool keeps updating mouse coordinate even when I do not drag its finder ?

(3)I would also like to add functionality to do an action on window 'new IP' , if found , in the infinite while loop .

Please give directions.

Thanks.

#include <AutoItConstants.au3>
HotKeySet("{ESC}", "dummy")
AutoItSetOption("WinTitleMatchMode",2);
Local $hWnd, $x, $y, $pos, $reponse
While 1
$hWnd = WinGetHandle("foobar")
$pos = WinGetPos($hWnd)
$x = 360 ; 
$y = 77  ; 
WinActivate($hWnd)
MouseClick("left", $pos[0] + $x, $pos[1] + $y)
Send("{DOWN}")
WinWaitActive($hWnd)
Send("{DOWN}")
WinWaitActive($hWnd)
Send("{DOWN}")
WinWaitActive($hWnd)
Send("{DOWN}")
WinWaitActive($hWnd)
Send("{DOWN}")
Send("{DOWN}")
WinWaitActive($hWnd)
WinWaitActive($hWnd)
Send("{ENTER}")
$reboot_window = WinWait("Reboot")
WinWaitActive($reboot_window)
Send("{TAB}")
WinWaitActive($reboot_window)
Send("{SPACE}")
WinWaitActive($reboot_window)
Send("{TAB}")
WinWaitActive($reboot_window)
Send("{DOWN}")
Send("{DOWN}")
WinWaitActive($reboot_window)
Send("{TAB}")
WinWaitActive($reboot_window)
Send("{DOWN}")
WinWaitActive($reboot_window)
Send("{TAB}")
WinWaitActive($reboot_window)
Send("{SPACE}")
Sleep(1000)
$response = WinGetHandle("Reboot")
$pos = WinGetPos($response)
$x = 168 ; 530-362
$y = 258  ; 376-118
WinActivate($response)
MouseClick("left", $pos[0] + $x, $pos[1] + $y)
Sleep(50000)
WEnd
Func dummy()
EndFunc   ;==>dummy

Edited by manit
wasn't displayed properly before

Share this post


Link to post
Share on other sites

I suggest - if possible - to not use Send but ControlSend. So windows popping up do not influence your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-03-26 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-03-21 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

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

  • Similar Content

    • By bylly
      Hello this is the code maybe you can figure it out I placed some comments to try and explain what I want
      #include <Array.au3> AnyDeskOpen() Func AnyDeskOpen() Global $aWinList = WinList("[REGEXPTITLE:(?i)(.*Anydesks*)]") ;get window name and handle from windows and store into an array $asd = $aWinList $aExtract = _ArrayExtract($asd) ; beginner babble clean this Sh** up Global $default = _ArrayToString($aExtract, "", 0, 0) EndFunc StartWait() ; check in the array to see how many windows are opened Func StartWait() While 1 AnyDeskOpen() If $Default = 1 Then Sleep (3500) Else Exitloop EndIf WEnd EndFunc If $default = "2" Then ; If two windows are opened than someone is trying to connect to that computer and needs a click to accept connection try and click accept Button in the first window and the second one by activating diffrent window handle $extra = _ArrayToString($aWinList, "", 1, 1) $sString = StringReplace($extra, "AnyDesk", "") $hGUI = $sString WinActivate(HWnd($hGUI)) winmove (HWnd($hGUI), "", 50, 50) Mouseclick ("left", 100, 500) Sleep (1500) $extra = _ArrayToString($aWinList, "", 2, 2) $sString = StringReplace($extra, "AnyDesk", "") $hGUI = $sString WinActivate(HWnd($hGUI)) winmove (HWnd($hGUI), "", 50, 50) Mouseclick ("left", 100, 500) EndIf While 1 ;up to here everything seems to work AnyDeskOpen() ; while there is a connection there are two AnyDesk windows, if we close the connection than only one window remains opened and we check the array to see how many values it has If $Default = 2 Then Sleep (3500) Else ; At this point the program exits code 0 instead of resseting to function above StartWait() Exitloop EndIf WEnd ; thank you  the intent is to keep the program going so it clicks accept again when reconnecting
    • By nacerbaaziz
      hello sirs, please i created a tool witch get the focused control in a window and play a audio file linked with this controls
      e.g buttons, checkBoxes, radios, comboboxes, and others
      i know that their is a function that give us the control focus but it return the classNN
      i want to get the class name to use it with a switch and
      because their are more than class e.g button tbutton timagebutton tnewButton...
      please can any one help me to get the class name not the classnn
      thanks in advance
    • By ThePoro
      Hi everyone.
      I want to ask about this : 
      I want it runs from 1 to 100 and It opens 10 firefox profiles then access youtube. After I close a firefox window, the loop runs and wait for another window close until loop ends
      I have a loop like this.
      Func launch() Local $from = Int(GUICtrlRead($input1)) Local $to = Int(GUICtrlRead($input2)) If $to <> "" Then While $from <= $to Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") $to=$to+1 WEnd Else Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") EndIf EndFunc Is there any solution?
      Thank you!
    • By Rhidlor
      I was wondering if there was a library or something which provides the capability to Send() to inactive windows, and I know what you're thinking, I could just use ControlSend(); the reason I can't use that in this situation is because I need to hold down keys for specific prolonged periods of time. Also activating the window, Send()ing then de-activating the window isn't really an option here, I need the target window to always be in the background. I've looked around the forums for an adequate amount of time and didn't find anything useful, perhaps because the threads were all 10 years old, nevertheless, if anyone has any suggestions they would be greatly appreciated.
      Thanks!
    • By bbProg
      Hi,
       
      how can I wait activate for windows with information as in the photos attached?
      Class is not being recognized by the script.
       
      thanks in advanced.



×
×
  • Create New...