Jump to content

AutoIt Unfocused Windows?


RandomClown

Recommended Posts

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:

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.

Link to comment
Share on other sites


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.

Edited by RandomClown
Link to comment
Share on other sites

Welcome to the forum RandomClown, :)

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.

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.


; 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

...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.

Link to comment
Share on other sites

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. :D

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

Edited by RandomClown
Link to comment
Share on other sites

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.

If WinWait("setup") And ControlClick("setup", "", "[CLASS:Button; INSTANCE:##]") Then WinWaitClose("setup")

Link to comment
Share on other sites

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,

Edited by RandomClown
Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

thanks for the reminder. I forgot I was on a coding forum.

:D

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. ;)

ControlCommand is a command right?

can commands be used as umm...

..forgot the term.. as a comparison? [whiles, ifs, do untils, !='s, other stoofs]

$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]")

Edited by RandomClown
Link to comment
Share on other sites

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!

Edited by RandomClown
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...