Sign in to follow this  
Followers 0
JJohnson

If ControlGetText LIKE "" Then ?

16 posts in this topic

Hello

I've been using AutoIt3 for a few months now and it is very helpful for doing certain tasks. I've been having some trouble though and wonder if this can be solved easily.

Here is my conditional statement:

If ControlGetText("", "", 10) = "How many letters in the word dog?" Then
    If ControlGetText("", "", 1) = "3" Then
        ControlClick("", "", 1)
    ElseIf ControlGetText("", "", 2) = "3" Then
        ControlClick("", "", 2)
    ElseIf ControlGetText("", "", 3) = "3" Then
        ControlClick("", "", 3)
    ElseIf ControlGetText("", "", 4) = "3" Then
        ControlClick("", "", 4)
    EndIf
    ControlClick("","", 20)

Is there some way to use: If ControlGetText("", "", 1) like "%3%" Then ?? Sorry for my SQL syntax. Is there a way to use an if/then statement in this manner?

Also, I noticed someone posted this in the faq:

Q21. Why my script doesn't work on locked station?

A21. On locked station any window will never be active (active is only dialog with text "Press Ctrl+Alt+Del")

In Windows locked state applications runs hidden (behind that visible dialog) and haven't focus and active status.

So generally don't use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc.

Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc.

This way you may have your script resistive against another active windows.

and it's possibe to run such script from scheduler on locked Windows station.

I'm having this exact problem. When my workstation locks the script no longer finds the window I am looking for. I am using WinActivate to activate the window and continue on with these if/then statements, and WinWait to make sure the window exists before the script runs. What is the alternative for this so the script functions when the workstation is locked?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is there some way to use: If ControlGetText("", "", 1) like "%3%" Then ?? Sorry for my SQL syntax. Is there a way to use an if/then statement in this manner?

Try:
If StringInStr(ControlGetText("Window Title", "", 1), "3") Then

Also, I noticed someone posted this in the faq:

I'm having this exact problem. When my workstation locks the script no longer finds the window I am looking for. I am using WinActivate to activate the window and continue on with these if/then statements, and WinWait to make sure the window exists before the script runs. What is the alternative for this so the script functions when the workstation is locked?

Use WinExists(), because it doesn't depend on the window being active, it will work while the console is locked.

:mellow:

Edit: Added window title specification. Since we are talking about a locked console, ControlGetText("", "", 1) wouldn't work. You need to specify the window as edited above, or by advanced specification:

ControlGetText("[CLASS:YourWinClass; TITLE:Your Window Title]", "", 1)
Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

well, winactivate won't work when windows is locked because that locked screen is the only one active until unlocked.

The rest depends on what you are trying to do.

if you are trying to send mouse clicks and text (controlclick, controlsend) then using the windows title or handle will help.

winexists should work as well to tell is the window you want to interact with is available.

winwait to pause until the window is available.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Just remove the WinActivate().

So generally don't use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc.

Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc.

Share this post


Link to post
Share on other sites

Try:

If StringInStr(ControlGetText("", "", 1), "3") Then

Use WinExists(), because it doesn't depend on the window being active, it will work while the console is locked.

:mellow:

So this

If StringInStr(ControlGetText("", "", 1), "3") Then

will work if the "3" is like "3 " with a space after the 3? What if the "3" looks like "3r"?

Share this post


Link to post
Share on other sites

Just remove the WinActivate().

So if multiple windows are open I don't need WinActivate before I start using ControlGetText and ControlClick?

Share this post


Link to post
Share on other sites

So if multiple windows are open I don't need WinActivate before I start using ControlGetText and ControlClick?

If there is a question of whether the window exists all, yes you need to test that first, but it doesn't have to be active. The Control*() functions, where you specify the window, will usually work on a window that is not active or even minimized and while the console is locked. For example Send() wouldn't work in those conditions, but ControlSend() would.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

So this

If StringInStr(ControlGetText("", "", 1), "3") Then

will work if the "3" is like "3 " with a space after the 3? What if the "3" looks like "3r"?

Hi,

StringInStr checks, if, in your case "3", the given check value exists in given String. The Return is the position of the value to check, if exists.

ControlGetText    StringinStr (default function call) see help for more details
123               3
321               1
131               2
3                 1 there is a blank behind
 3                2 there is a blank before
3r                1

Your if condition is always True, if one or more "3"'s are in your string. So it is also True for "3r".

If you only want values always starting with a 3, you have to check, if Return from StringInStr is 1.

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

Hi,

StringInStr checks, if, in your case "3", the given check value exists in given String. The Return is the position of the value to check, if exists.

ControlGetText    StringinStr (default function call) see help for more details
123               3
321               1
131               2
3                 1 there is a blank behind
 3                2 there is a blank before
3r                1

Your if condition is always True, if one or more "3"'s are in your string. So it is also True for "3r".

If you only want values always starting with a 3, you have to check, if Return from StringInStr is 1.

;-))

Stefan

Thanks, this seems to work just fine.

Share this post


Link to post
Share on other sites

Shouldn't I also be able to do:

If ControlGetText("", "", 10) = "How many letters in the word dog?" Then
    If ControlGetText("", "", 1) = "3" OR ControlGetText("", "", 1) = "3 " Then
        ControlClick("", "", 1)
    ElseIf ControlGetText("", "", 2) = "3" OR ControlGetText("", "", 2) = "3 " Then
        ControlClick("", "", 2)
    ElseIf ControlGetText("", "", 3) = "3" OR ControlGetText("", "", 3) = "3 " Then
        ControlClick("", "", 3)
    ElseIf ControlGetText("", "", 4) = "3" OR ControlGetText("", "", 4) = "3 " Then
        ControlClick("", "", 4)
    EndIf
    ControlClick("","", 20)

??

For some reason I don't think it likes the empty space after 3 very much...

Share this post


Link to post
Share on other sites

Hi,

if you are afraid of spaces, get rid of them with StringReplace ($string, " ", "") or have a look at StringStripWs ()

or

;if your control id's are correct this should work
If ControlGetText("", "", 10) = "How many letters in the word dog?" Then
    For $i = 1 To 4
        ;any occurences of "3" in ControlGetText..
        If StringInStr (ControlGetText("", "", $i), "3") Then
            ControlClick("", "", $i)
            ExitLoop
        EndIf
    Next
    ControlClick("","", 20)
EndIf

;-))

Stefan

Share this post


Link to post
Share on other sites

If there is a question of whether the window exists all, yes you need to test that first, but it doesn't have to be active. The Control*() functions, where you specify the window, will usually work on a window that is not active or even minimized and while the console is locked. For example Send() wouldn't work in those conditions, but ControlSend() would.

:mellow:

Thanks for this. I thought I had to activate the window first but using the Control*() commands with window names works great.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

If there is a question of whether the window exists all, yes you need to test that first, but it doesn't have to be active. The Control*() functions, where you specify the window, will usually work on a window that is not active or even minimized and while the console is locked. For example Send() wouldn't work in those conditions, but ControlSend() would.

:mellow:

One more question for clarification. What if I have the same title'd window open two or three times? Does it know which window to send to when I use ControlGetText and ControlClick?

A sample of my current code:

Dim $loop
Do 
If WinExists("My Window") Then
If ControlGetText("My Window", "", 10) = "How many letters in the word dog?" Then
    If ControlGetText("My Window", "", 1) = "3" Then
        ControlClick("My Window", "", 1)
    ElseIf ControlGetText("My Window", "", 2) = "3" Then
        ControlClick("My Window", "", 2)
    ElseIf ControlGetText("My Window", "", 3) = "3" Then
        ControlClick("My Window", "", 3)
    ElseIf ControlGetText("My Window", "", 4) = "3" Then
        ControlClick("My Window", "", 4)
    EndIf
    ControlClick("My Window","", 20)
ElseIf ControlGetText("My Window", "", 10) = "How many hours in a day?" Then
    If ControlGetText("My Window", "", 1) = "24" Then
        ControlClick("My Window", "", 1)
    ElseIf ControlGetText("My Window", "", 2) = "24" Then
        ControlClick("My Window", "", 2)
    ElseIf ControlGetText("My Window", "", 3) = "24" Then
        ControlClick("My Window", "", 3)
    ElseIf ControlGetText("My Window", "", 4) = "24" Then
        ControlClick("My Window", "", 4)
    EndIf
    ControlClick("My Window","", 20)
EndIf
Else
    WinWait("My Window")
EndIf
$loop = 0
Until $loop = 1
Edited by JJohnson

Share this post


Link to post
Share on other sites

Review your help file under "Window Titles and Text (Advanced)" for some of the ways to specify the window. For example: "[TITLE:My Window; INSTANCE:2]".

Ideally, you would have been collecting the HWND handles as those windows were created, and then just use the handle from then on.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Review your help file under "Window Titles and Text (Advanced)" for some of the ways to specify the window. For example: "[TITLE:My Window; INSTANCE:2]".

Ideally, you would have been collecting the HWND handles as those windows were created, and then just use the handle from then on.

:mellow:

How would I use the HWND once I have it? It seems to change for every window, which is normal I guess.

Do I just replace title with the handle? Like so:

$handle = WinGethandle("My Window","")

If ControlGetText($handle, "", 10) = "How many letters in the word dog?" Then

If ControlGetText($handle, "", 1) = "3" Then

ControlClick($handle, "", 1)

etc.

Share this post


Link to post
Share on other sites

Ok I actually read the help topic like you suggested and see that you do just replace the title with the $handle. So I tested it and it seems to work. I'm about to run 20 windows and see if it works with so many at once. :mellow:

Thanks for all the help!

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