Help - Search - Members - Calendar
Full Version: AutoIt Unfocused Windows?
MSFN Forums > Unattended Windows Discussion & Support > Application Installs

   


Google Internet Forums Unattended CD/DVD Guide
RandomClown
Hello, I have been over the internet for a while now, & I didnt see how to focus on a window.
Is there no way to do it? Or are my eyes bad from hours of reading? wacko.gif



Since I didnt see it, I might have to do this instead; I wanted to write a little script that will:
* Perform a "IF WinActive()" check 10 times, once per second.

- If the window was active during the check, do a Goto to get out of the messy script & goto the main script.

- If the window did not focus during the check, do that code then goto the script:
MouseMove(@DesktopWidth/2, @DesktopHeight/2-30, 0)
MouseClick("primary")



ima go to sleep now.
ive been reading & typing all day..
thanks for reading.
radix
QUOTE (RandomClown @ Oct 28 2008, 08:46 AM) *
I didnt see how to focus on a window.

If I understand right, you need to use WinActivate function.
RandomClown
oooohhh that could stand alone?

I thought it was a checking thingy for If() funcs.
AutoIT is more powerful then I thought.

Thanks a lot!



EDIT [not to double post]

How would I set 2 conditions in a While statement?
- There is the i++ thing
[something like that] I saw in the very useful help file
- Where is the &&?

I want to set a While() with these conditions:
- Run at most 10 times
- Check if "Some Window" is up

...hmm I just saw this right now: "ExitLoop".
I could do an If("Some Window" is up){ExitLoop}
[of course in AutoIT language], but I want to cut off 3 lines from the tiny check script if possible.

Nick_White
CODE
$i=1
While ($i<=10)
    If (WinActive("Window title")) Then
        ExitLoop
    EndIf
    $i = $i + 1
    Sleep(1000)
WEnd
MHz
Welcome to the forum RandomClown, smile.gif

QUOTE (RandomClown @ Oct 29 2008, 09:07 AM) *
How would I set 2 conditions in a While statement?
- There is the i++ thing something like that I saw in the very useful help file
- Where is the &&?

AutoIt supports only the operators under "Language Reference" catagory in the help file supplied within the installation of AutoIt3.

QUOTE
I want to set a While() with these conditions:
- Run at most 10 times
- Check if "Some Window" is up

You may use as Nick White displays or you could use a For...Next loop that is suitable for limited looping by using a counter variable. Using AdlibEnable() function may also be suitable for detection in your script. The choice is for you to make. I made example code below.

CODE

; title of test window
$title = 'Target Window'

; create a window to test with
GUICreate($title)
GUISetState()

; run the _Adlib() function every 2 seconds to check for the test window
AdlibEnable('_Adlib', 2000)

Sleep(2000)

; activate the test window if needed
If Not WinActive($title) Then
WinActivate($title)
EndIf

; loop 10 times
For $i = 1 To 10
; check if test window is active
If WinActive($title) Then
; disable the _Adlib() function check
AdlibDisable()
; show the result
SplashTextOn('For...Next Loop', 'Window is active', 200, 50)
Sleep(2000)
SplashOff()
; enable the _Adlib() function check
AdlibEnable('_Adlib', 2000)
; exit the For...Next Loop
ExitLoop
EndIf
Sleep(500)
Next

Sleep(5000)

Exit

Func _Adlib()
; Adlib function to show result while the main code is executing
SplashTextOn('_Adlib() function', 'Window is active', 200, 50)
Sleep(1000)
SplashOff()
Sleep(250)
EndFunc


QUOTE
...hmm I just saw this right now: "ExitLoop".
I could do an If("Some Window" is up){ExitLoop} [of course in AutoIT language], but I want to cut off 3 lines from the tiny check script if possible.

Single line If...Then... are allowed though your mention of removing 3 lines is beyond my understanding to answer with the information supplied.
RandomClown
Thanks for the welcome!

Hey thanks for the info guys, I just learned a few things from your responses.


MHz:
Single line If...Then... are allowed though your mention of removing 3 lines is beyond my understanding to answer with the information supplied.

Oops! Did I write 3? I meant a lot.
This is what I wrote before revisiting this thread:

$i = 0
While $i <= 60
$i = $i + 1
Sleep(1000)
If WinActive("setup") Then
ExitLoop
EndIf
WinActivate("setup")
WEnd
WinWaitActive("setup")
ControlClick("setup", "", "[CLASS:Button; INSTANCE:##]")
WinWaitClose("setup")
Exit

This is way more than 3 lines..I meant a lot

The code you wrote is beyond my understanding. biggrin.gif

I made the code on 1 line before & I got error messages.
Is there a way to make it all on 1 line?

For now, I will replace my script with Do Untils
MHz
QUOTE (RandomClown @ Nov 1 2008, 08:07 AM) *
I made the code on 1 line before & I got error messages.
Is there a way to make it all on 1 line?

Controlclick() normally works with an inactive window so this may do the task as being 1 line.
CODE
If WinWait("setup") And ControlClick("setup", "", "[CLASS:Button; INSTANCE:##]") Then WinWaitClose("setup")
RandomClown
thanks

I am also trying this for buttons disabled while installing:

Do Sleep(200)
Until ControlCommand($title, , 'Button2', 'IsEnabled', '')
ControlClick($title, "", "[CLASS:Button; INSTANCE:2]")


It keeps crashing at the until.
I want to make it wait until it is enabled.
Did I use the wrong code?

- The window is called setup; I used $title you guys showed me.
- The button is named Button2,
MHz
QUOTE (RandomClown @ Nov 3 2008, 04:15 PM) *
Do Sleep(200)
Until ControlCommand($title, , 'Button2', 'IsEnabled', '')
ControlClick($title, "", "[CLASS:Button; INSTANCE:2]")

Put the Do keyword on a line of it's own to avoid the error condition.
CODE
Do
    Sleep(200)
Until ControlCommand($title, , 'Button2', 'IsEnabled', '')
ControlClick($title, "", "[CLASS:Button; INSTANCE:2]")

You can use [ CODE ] ... [/ CODE ] tags (without spaces in the tags) to post code segments in this forum.
RandomClown
thanks for the reminder. I forgot I was on a coding forum.
biggrin.gif

hmm.

Still not working.
I am getting a Line -1: error.

**EDIT** I read it wrong. It said Line -1:, not Line: -1

It crashes after 2 seconds...
I wonder where that is. newwink.gif
ControlCommand is a command right?
can commands be used as umm...
..forgot the term.. as a comparison? [whiles, ifs, do untils, !='s, other stoofs]

CODE
$title = 'setup'
Do
    Sleep(1000)
    WinActivate($title)
Until WinActive($title)
sleep(2000)
Do
    Sleep(200)
Until ControlCommand($title, , 'Button2', 'IsEnabled', '')
ControlClick($title, "", "[CLASS:Button; INSTANCE:2]")
RandomClown
OMG I found the problem!!

command($title, , 'Button2', 'IsEnabled', '')
**TO**
command($title, '', 'Button2', 'IsEnabled', '')


got to have the ''

If you didnt know, use that to help other users in the future.

W00T!




Google Internet Forums Unattended CD/DVD Guide

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.