diff --git a/libcvautomation_funcs b/libcvautomation_funcs index c00277b..ffa72ae 100644 --- a/libcvautomation_funcs +++ b/libcvautomation_funcs @@ -146,45 +146,59 @@ click_i () out "click_i: matching $@" - for x in $@ - do - if [ -n "$USE_CENTER" ]; then - center="c" - else - center="" - fi - if [ -n "$USE_SANE_TOLERANCE" ]; then - TOLERANCE_OPTION="-o" - else - TOLERANCE_OPTION="-t" + if [ -n "$USE_CENTER" ]; then + center="c" + else + center="" + fi + + if [ -n "$USE_SANE_TOLERANCE" ]; then + TOLERANCE_OPTION="-o" + else + TOLERANCE_OPTION="-t" + fi + + + if [ -n "$USE_WAIT" ]; then + #Alternate between each image until a match is found, or we loop $TIMEOUT times + #This is a bit weird, since we need to lower the TIMEOUT value for the "waitfor" + #function, and then restore it at the end. + OLD_TIMEOUT=$TIMEOUT + TIMEOUT=1 + + for loop in {1..$OLD_TIMEOUT} + do + for x in $@ + do + + waitfor "$x" + CVA_RETURN=$? + + if [ $CVA_RETURN -lt $RETURN_CODE ]; then + RETURN_CODE=$CVA_RETURN + fi + + if [ $CVA_RETURN -eq 0 ]; then + #We found the image, click it + TIMEOUT=$OLD_TIMEOUT + eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick $x' >> $OUTFILE" + return $? + fi + done + done + + #We'll get here if we don't find a match + OLD_TIMEOUT=$TIMEOUT + TIMEOUT=1 + else + eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick $x' >> $OUTFILE" + CVA_RETURN=$? + + if [ $CVA_RETURN -lt $RETURN_CODE ]; then + RETURN_CODE=$CVA_RETURN fi + fi - if [ -n "$USE_WAIT" ]; then - waitfor "$x" - CVA_RETURN=$? - - if [ $CVA_RETURN -lt $RETURN_CODE ]; then - RETURN_CODE=$CVA_RETURN - fi - - if [ $CVA_RETURN -eq 0 ]; then - #We found the image, click it - eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick $x' >> $OUTFILE" - else - return $RETURN_CODE - fi - else - eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick $x' >> $OUTFILE" - CVA_RETURN=$? - - if [ $CVA_RETURN -lt $RETURN_CODE ]; then - RETURN_CODE=$CVA_RETURN - fi - fi - - done - - return $RETURN_CODE } # ---------- end of function click_i ----------