Jump to content

How to test for one of several windows and execute keys


Docfxit
 Share

Recommended Posts

I have a number of windows that may come up on the screen.

If one of them does come up, I'd like to hit the enter key.

I'd like this to be a never ending program to run all the time.

This is the code I have so far:

Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number
HotKeySet("{F8}", "Terminate")
Dim $t

While 1

    ;If this window comes up do this:
    WinWait("DAZzle Professional", "The file DAZzle Prof")
    If Not WinActive("DAZzle Professional", "The file DAZzle Prof") Then WinActivate("DAZzle Professional", "The file DAZzle Prof")
    WinWaitActive("DAZzle Professional", "The file DAZzle Prof")
    $t = $t + 1
    Send("{ENTER}")
    ;Until here
    ;If this window comes up do this:
    WinWait("Error", "The remote server re")
    If Not WinActive("Error", "The remote server re") Then WinActivate("Error", "The remote server re")
    WinWaitActive("Error", "The remote server re")
    $t = $t + 1
    Send("{ENTER}")
    ;Until here
    ;If this window comes up do this:
    WinWait("DAZzle Professional", "Error from CreateLab")
    If Not WinActive("DAZzle Professional", "Error from CreateLab") Then WinActivate("DAZzle Professional", "Error from CreateLab")
    WinWaitActive("DAZzle Professional", "Error from CreateLab")
    $t = $t + 1
    Send("{ENTER}")
    ;Until here
    ;If this window comes up do this:
    WinWait("DAZzle Professional", "Failed to complete t")
    If Not WinActive("DAZzle Professional", "Failed to complete t") Then WinActivate("DAZzle Professional", "Failed to complete t")
    WinWaitActive("DAZzle Professional", "Failed to complete t")
    $t = $t + 1
    Send("{ENTER}")
    $sText = "Errors Found: " & $t
    $aStringSize = _StringSize($sText, 17, Default, Default, "Verdana")

    SplashTextOn("Splash", $sText, $aStringSize[2] + 15, 50, -1, -1, 1, "Verdana") ; See end of post for explanation of + 15
    Sleep(8000)

WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Could someone please help me make this happen?

Thank you,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

I think I figured it out.  I can't test it right now.

Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)
Opt("TrayAutoPause", 0)
#include "Notify.au3"
#include "StringSize.au3"
#include <MsgBoxConstants.au3>
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number

; Press ESC to exit script
HotKeySet("{ESC}", "_Exit")

Dim $ErrorCount, $textLine
; Register message for click event
_Notify_RegMsg()

; Set notification location
_Notify_Locate(0)
_Notify_Set(Default)

; Show notifications
Global $aNotCID[5]
;$aNotCID[1] = _Notify_Show(0, "", "Message 2" & @CRLF & "more Message 2")
;$aNotCID[4] = _Notify_Show(0, "DAZzle 3", "Auto-retract", 1)

While 1
    WinExists("DAZzle Professional")
    If Not WinActive("DAZzle Professional", "") Then WinActivate("DAZzle Professional", "")
    Local $title = WinGetTitle("DAZzle Professional", "")
    ;MsgBox($MB_SYSTEMMODAL, "", "Full title read is: " & $title)
    Local $text = WinGetText("", "")
    ;MsgBox($MB_SYSTEMMODAL, "", "Full text read is: " & $text)

    If $title = "DAZzle Professional" And $text = "The file DAZzle Prof" Then
        $ErrorCount = $ErrorCount + 1
        $aNotCID[1] = _Notify_Show(0, "DAZzle 2", "The file DAZzle Prof")
        Send("{ENTER}")
    EndIf
    If $title = "Error" And $text = "The remote server re" Then
        $ErrorCount = $ErrorCount + 1
        $aNotCID[2] = _Notify_Show(0, "DAZzle 3", "The remote server" & @CRLF & "more Message 4")
        Send("{ENTER}")
    EndIf
    If $title = "DAZzle Professional" And $text = "Error from CreateLab" Then
        $ErrorCount = $ErrorCount + 1
        $aNotCID[3] = _Notify_Show(0, "DAZzle 4", "Error from CreateLab" & @CRLF & "more Message 4")
        Send("{ENTER}")
    EndIf
    If $title = "DAZzle Professional" And $text = "Failed to complete t" Then
        $ErrorCount = $ErrorCount + 1
        $aNotCID[4] = _Notify_Show(0, "DAZzle 5", "Failed to complete" & @CRLF & "more Message 4")
        Send("{ENTER}")
    EndIf
    $aNotCID[0] = _Notify_Show(0, "DAZzle 1", "Errors Found: " & $ErrorCount, 8)

    Sleep(8000)
    ; For debug purposes only
    For $i = 0 To 4
        $sRet = _CheckRetractionMethod($aNotCID[$i])
        If $sRet Then
            ConsoleWrite("Notification " & $i + 1 & ": " & $sRet & @CRLF)
        EndIf
    Next

WEnd


Func _CheckRetractionMethod($hWnd)
    Local $sRet = ""
    ; Check if notification was the last clicked
    Local $aFuncRet = _Notify_RetractCheck($hWnd)
    ; Determine method of retraction
    Switch $aFuncRet[0]
        Case 0
            ; Do nothing - notification either still visible or already retracted
        Case 1
            $sRet = "Title clicked :: " & $aFuncRet[1]
        Case 2
            $sRet = "Message clicked :: " & $aFuncRet[1]
        Case 9
            $sRet = "Timeout :: " & $aFuncRet[1]
    EndSwitch
    Return $sRet
EndFunc   ;==>_CheckRetractionMethod

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

Edited by Docfxit
With the help of Danp2:
Link to comment
Share on other sites

8 hours ago, Docfxit said:

I think I figured it out.  I can't test it right now.

I can't see how this will work because you never set the value of $title.

8 hours ago, Docfxit said:

Currently it's displaying the "Errors Found:" in the middle of the screen.

@Melba23has a couple of UDFs that you could use instead of SplashTextOn. Check out Notify and Toast.

Link to comment
Share on other sites

Hi Danp2,

All of these windows are from "DAZzle Professional".

I was on the phone with Endicia (the creator of Dazzle) all day yesterday.  I am a user of Dazzle.  The support person I was talking to wanted me to find a way to solve their errors in their program.  They aren't smart enough and they have no want to resolve their own errors.  So I want a script to press the enter key every time an error pops up.  I don't want to sit in front of the screen waiting for their errors to pop up.

 

Thank you very much for the help...

Docfxit

Edited by Docfxit
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...