Jump to content

Need some help for a special Autoclick-script!


Recommended Posts

Hi guys,

I've got a little problem!

Let me first explain what's the present situation: I'm working on a Windows-LiveCD called BartPE (it's a counterpart to Knoppix etc.) - if anyone is interested, there's a really good forum: 911cd-Forums.

When booting up my BartPE-CD, I'm asked if I want to start network-support - and that's the problem: the CD stops booting until I click on "Yes" or "No". But sometimes I just want to start the CD and let it boot up automatically, means I don't want to make any interaction.

That's why I decided to give AutoIt a try!

I want AutoIt to look for this window and after a short pause it shall click on "OK", which brings up the next window. Now AutoIt shall also click on "OK" after a short pause. Then the last window opens and I want AutoIt to do the same thing again.

For this I made the following script:

; start PENetCfg with parameter "/Useprofile"
Run("PENetCfg.exe /Useprofile")

; look for a untitled window containing "&Nein"
WinWaitActive("","&Nein")
; wait five seconds
Sleep(5000)
; focus mouse over "OK"-button (button-ID="TRzBitBtn2")
ControlFocus("","&Nein","TRzBitBtn2")
; click "OK"-button
ControlClick("","&Nein","TRzBitBtn2")

; look for a untitled window containing "Durchsuchen"
WinWaitActive("","Durchsuchen")
; wait five seconds
Sleep(5000)
; focus mouse over "OK"-button (button-ID="TRzBitBtn3")
ControlFocus("","Durchsuchen","TRzBitBtn3")
; click "OK"-button
ControlClick("","Durchsuchen","TRzBitBtn3")

; look for a window named "PE Network Configurator" containing "Netzwerkidentifikation"
WinWaitActive("PE Network Configurator","Netzwerkidentifikation")
; wait five seconds
Sleep(5000)
; focus mouse over "OK"-button (button-ID="TRzBitBtn13")
ControlFocus("PE Network Configurator","Netzwerkidentifikation","TRzBitBtn13")
; click "OK"-button
ControlClick("PE Network Configurator","Netzwerkidentifikation","TRzBitBtn13")

Now my questions:

As you can see, the first two windows have no title. Is it possible to use another parameter to identify the windows? Because in my example the windows are only identified over the containing text - and the window-text is different from user to user, depending on the host-system language on which the BartPE-CD was built :dance:

My other question is, what happens, if I manually click on a button while my script runs? Then the window would not be found and...yes, what's happening then? Will the script continue?

For example if I confirm the first window manually with "OK" and then I do nothing more - will my script continue to autoclick the next two windows?

And do I have to include an EXIT-command at the end, so that my script is not running endlessly?

Many questions from a newbie - any help from you pros would be really much appreciated :dance:

Best regards and thanks in advance

cool400 :whistle:

Edited by cool400
Link to comment
Share on other sites

Hi

I am not an expert, but I think I can answer a few of your questions...

To answer the first question:

Is it possible to use another parameter to identify the windows?

Yes, it is - have a look at the help file 'Window Titles and Text (Advanced)' is a good place to start with regard to this. :dance:

Question two:

For example if I confirm the first window manually with "OK" and then I do nothing more - will my script continue to autoclick the next two windows?

Have you tried using 'If' & 'Then' commands? :dance:

For example:

If WinActive("","Durchsuchen") then
; wait five seconds
Sleep(5000)
; focus mouse over "OK"-button (button-ID="TRzBitBtn3")
ControlFocus("","Durchsuchen","TRzBitBtn3")
; click "OK"-button
ControlClick("","Durchsuchen","TRzBitBtn3")
Else 
Exit

And lastly yes, it is a good idea to include an 'exit' command in your script.

Hope this helps :-)

* Try reading the help file, it is pretty comprehensive and easy to use (even for somone like myself) :whistle:

Link to comment
Share on other sites

@Katy

Thanks for your reply - I found the part "Window Titles and Text (Advanced)" in the helpfile. It seems that identifying the window over its classname would be a good idea, using WinTitleMatchMode 4. But I don't know how to use it with the commands WinWaitActive or WinActive :dance:

Could you post an example of the correct syntax, e.g. if the classname of the window is "PENetWindow1"?

Is it better to use the If/Then-function with WinActive instead of WinWaitActive?

Thanks again and best regards

cool400 :whistle:

Link to comment
Share on other sites

Yes, it is better to use the If, then tags. WinWaitActive basically waits for a window and then continues through the script. if you don't include a time out here, your script will stop here indefinately. But if for example the user clicks on eg. cancel instead of proceeding through the windows, you can accomodate him thus:

Sleep(5000)

If WinActive("Name") then

; Continue the script

Else

; Do something else

EndIf

Exit

Does that make more sense?

Link to comment
Share on other sites

Hi cool400,

Based on your concern regarding user intervention while the script is controlled, I took the liberty of rewriting your script. It 'watches' for user input to the specified boxes based on whether they remain on-screen for 5 seconds.

Please let me know what you think and if anything isn't clear.

run("PENetCfg.exe /Useprofile")

; ---------------------------------------------------------------------

; wait until a window containing '&Nein' exists
winWait("", "&Nein")

; wait up to five seconds for this window to disappear
$userAction = winWaitClose("", "&Nein", 5)

; at this point $userAction = 0 if five seconds elapsed
; or $userAction = 1 if the window disappeared before that time

; if the user did not dismiss the box then click control 'TRzBitBtn2'
if ($userAction = 0) then controlClick("", "&Nein", "TRzBitBtn2")

; ---------------------------------------------------------------------

; wait until a window containing 'Durchsuchen' exists
winWait("", "Durchsuchen")

; wait up to five seconds for this window to disappear
$userAction = winWaitClose("", "Durchsuchen", 5)

; if the user did not dismiss the box then click control 'TRzBitBtn3'
if ($userAction = 0) then controlClick("", "Durchsuchen", "TRzBitBtn3")

; ---------------------------------------------------------------------

; wait until a 'PE Network Configurator' window exists
winWait("PE Network Configurator", "Netzwerkidentifikation")

; wait up to five seconds for this window to disappear
$userAction = winWaitClose("PE Network Configurator", _
    "Netzwerkidentifikation", 5)

; if the user did not dismiss the box then click control 'TRzBitBtn13'
if ($userAction = 0) then controlClick("PE Network Configurator", _
    "Netzwerkidentifikation", "TRzBitBtn13")

Could you post an example of the correct syntax, e.g. if the classname of the window is "PENetWindow1"?

opt("winTitleMatchMode", 4)
winWait("classname=PENetWindow1")
Link to comment
Share on other sites

@Katy

Thanks again!

@LxP

This looks very good!

I've got two questions: what happens when one of the windows don't appear? E.g. if I click "No" in the first window, PENetCfg stops and won't open any other window...

Second question: could it be usefull to use the If/Then-function with your script?

Perhaps I should post screenshot of the three windows, so that you could see what I'm talking about...

BTW: when using classnames, do I have to insert the "Opt("winTitleMatchMode", 4)" before every WinWait-command?

Thanks again for your support - I'm really glad to learn something from a pro :dance:

Best regards

cool400 :whistle:

Edited by cool400
Link to comment
Share on other sites

@LxP

Your script is nearly perfect - I tested it without any manual interaction and with manual interaction in one or two of the three windows!

The only issue is, that when I manually click on "Nein" (="No") in the first window, PENetCfg exits and your script runs endlessly, preventing my BartPE from continuing booting up...my PC hangs :dance:

Do you have an idea how to solve this?

Best regards

cool400 :whistle:

Link to comment
Share on other sites

  • Moderators

The only issue is, that when I manually click on "Nein" (="No") in the first window, PENetCfg exits and your script runs endlessly

Have you tried While WinExists() or If WinExists() ?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

BTW: when using classnames, do I have to insert the "Opt("winTitleMatchMode", 4)" before every WinWait-command?

<{POST_SNAPBACK}>

Nope. The Opt() function is for setting options that stay at the values you set them to until you change them yourself. You can put that line at the very top of your script and then it's out of the way and done with.
Link to comment
Share on other sites

@c0deworm

Thanks, but I just want a kind of countdown - the profiles have to be hardcoded when building my BartPE-CD and I can't change anything afterwards, e.g. if network-support is started automatically using profile XY...

@ronsrules

No, haven't tried it yet - but I'm learning everyday more about AutoIt :dance: Thanks!

Do you mean instead of WinWait, which will cause the endless-loop?

@Saunders

Thanks for this explanation - but I found out that the first two untitled windows have also no classname :dance: They are really totally untitled in any way...

@LxP

Let me explain what I thought my script should do:

if the first window appears (which is the only one at this moment, so it doesn't matter if it has no title or classname), the script should wait five seconds.

If the "&Nein" (="No") button is pressed while this five seconds, the script shall exit - otherwise it's running endlessly!

If the "&Ja" (="Yes") button is pressed, the script should continue with the next two windows the same way, also with five seconds pause.

If nothing is pressed - what could mean that no user is present or is not willing to interact - the script shall also continue after the five seconds, but without any pause between the next two windows! Maybe I could use a variable like this:

If ... Then $pepause=5 Else $pepause=0

Do you have an idea how to realize this?

Best regards and thanks again to all of you for your help!

cool400 :whistle:

Edited by cool400
Link to comment
Share on other sites

Hmmm...I'm stuck with this problem :dance:

I don't know how to make a loop, which lasts five seconds, and while this loop is running how I'm getting the information if a button is clicked :dance:

I thought the there was a function which delivers the button-ID back, if a button is clicked, but I can't find anything in the help-file. Or can I use GUIGetMsg()? But I don't know if this only works with self-made GUIs or also with my PENetCfg...

Any help is very much appreaciated!

Best regards

cool400 :whistle:

Link to comment
Share on other sites

Oh dear -- this thread has been quite active but the View New Posts feature managed not to pick it up until now! :"> I am so sorry!

From what I've read, it appears that your desired script would have this logic:

  • run the EXE;
  • wait for the first Ja/Nein window;
  • wait 5 seconds for it to disappear -- if it still remains then immediately automate all remaining boxes;
  • otherwise wait for the next window;
  • wait 5 seconds to disappear -- automate remaining boxes if not;
  • etc.
Does this sound right?

Edit: I re-read your posts and I have a question: will all three windows appear regardless of which items are selected? In which cases may certain windows not appear?

Edited by LxP
Link to comment
Share on other sites

Here's a script that will do what I've defined above. I may post an edited version soon -- I'm not too happy with its structure.

Edit: This script assumes that all three windows will always be shown in order, regardless of which buttons are clicked in each window. Please let me know if this is wrong.

run("PENetCfg.exe /Useprofile")

; ---------------------------------------------------------------------

; wait until a window containing '&Nein' exists
winWait("", "&Nein")

; wait up to five seconds for this window to disappear
$userAction = winWaitClose("", "&Nein", 5)

; at this point $userAction = 0 if five seconds elapsed
; or $userAction = 1 if the window disappeared before that time

; if the user did not dismiss the box then automate all following
; responses
if ($userAction = 0) then
    controlClick("", "&Nein", "TRzBitBtn2")
    winWait("", "Durchsuchen")
    controlClick("", "Durchsuchen", "TRzBitBtn3")
    winWait("PE Network Configurator", "Netzwerkidentifikation")
    controlClick("PE Network Configurator", "Netzwerkidentifikation", _
        "TRzBitBtn13")
else

; ---------------------------------------------------------------------

; wait until a window containing 'Durchsuchen' exists
    winWait("", "Durchsuchen")
; wait up to five seconds for this window to disappear
    $userAction = winWaitClose("", "Durchsuchen", 5)
; if the user did not dismiss the box then automate all following
; responses
    if ($userAction = 0) then
        controlClick("", "Durchsuchen", "TRzBitBtn3")
        winWait("PE Network Configurator", "Netzwerkidentifikation")
        controlClick("PE Network Configurator", _
            "Netzwerkidentifikation", "TRzBitBtn13")
    else

; ---------------------------------------------------------------------

; wait until a 'PE Network Configurator' window exists
        winWait("PE Network Configurator", "Netzwerkidentifikation")

; wait up to five seconds for this window to disappear
        $userAction = winWaitClose("PE Network Configurator", _
            "Netzwerkidentifikation", 5)

; if the user did not dismiss the box then click control 'TRzBitBtn13'
        if ($userAction = 0) then _
            controlClick("PE Network Configurator", _
            "Netzwerkidentifikation", "TRzBitBtn13")

    endIf
endIf
Edited by LxP
Link to comment
Share on other sites

Here's an idea that you may not have considered: c0deWorm mentions the ability to use profiles. Might it be easier to construct a set of profiles and then use AutoIt's MsgBox() function to determine which profile to use at runtime?

For instance --

local $choice1, $choice2
local const $YES = 6
local const $NO = 7

$choice1 = msgBox(0x24, "Boot", "Do you want THIS functionality?")
if $choice1 = $YES then
    $choice2 = msgBox(0x24, "Boot", "You want THIS. Do you want THAT?")
    if $choice2 = $YES then
      ; $choice1 = YES and $choice2 = YES
      ; run the appropriate profile
        run("PENetCfg.exe /Useprofile Profile1.profile")
    else
      ; $choice1 = YES and $choice2 = NO
      ; run the appropriate profile
        run("PENetCfg.exe /Useprofile Profile2.profile")
    endIf
else
    $choice2 = msgBox(0x24, "Boot", "You don't want THIS. Do you want THAT?")
    if $choice2 = $YES then
      ; $choice1 = NO and $choice2 = YES
      ; run the appropriate profile
        run("PENetCfg.exe /Useprofile Profile3.profile")
    else
      ; $choice1 = NO and $choice2 = NO
      ; run the appropriate profile
        run("PENetCfg.exe /Useprofile Profile4.profile")
    endIf
endIf
Edited by LxP
Link to comment
Share on other sites

Oh dear -- this thread has been quite active but the View New Posts feature managed not to pick it up until now! :"> I am so sorry!

From what I've read, it appears that your desired script would have this logic:

  • run the EXE;

  • wait for the first Ja/Nein window;

  • wait 5 seconds for it to disappear -- if it still remains then immediately automate all remaining boxes;

  • otherwise wait for the next window;

  • wait 5 seconds to disappear -- automate remaining boxes if not;

  • etc.
Does this sound right?

Edit: I re-read your posts and I have a question: will all three windows appear regardless of which items are selected? In which cases may certain windows not appear?

<{POST_SNAPBACK}>

LxP, thank you very much for your precious help!!!

There is one case, when the last two windows won't appear: if I click "Nein" in the first window! That's the cause why the script runs endlessly and BartPE won't continue booting, because it waits for the 2nd window, which will never appear...

BTW, these are the three windows (all in german):

1st window

Posted Image

2nd window

Posted Image

3rd window

Posted Image

If I click "Abbrechen" (="Cancel") in the 2nd window, the scipt continues as normal and the 3rd window appears also (like if I clicked "OK")!

And this is, what I want to do:

|- start PENetCfg - at this point the 1st window is always shown (and it's always the same)

|- wait 5 seconds for any user-interaction - if mouse is moved, stop time-loop

|--- if the user has clicked "Nein", stop the script (or jump to the end, where it exits)

|--- if the user has clicked "Ja", continue the script without waiting until the end of the 5 seconds

|----- 2nd window appears, wait 5 seconds for any user-interaction - if mouse is moved, stop time-loop

|------- if the user has clicked "OK" or "Abbrechen", continue immediately without waiting until the end of the 5 seconds

|------- if nothing happens within the 5 seconds, click "OK"

|--------- 3rd window appears, wait 5 seconds for any user-interaction - if mouse is moved, stop time-loop

|----------- if user has clicked any of the three buttons, stop the script (or jump to the end, where it exits)

|----------- if nothing happens within the 5 seconds, click "OK" and stop the script (or jump to the end, where it exits)

|--- if nothing happens within the first 5 seconds (when the 1st window is shown), click "Ja" in the first window, and

|--- continue without any pause clicking "OK" in the 2nd and "OK" in the 3rd window, immediately when they appear

|- exit the script

Puh, sounds difficult, or not? Maybe you can help me to find a way doing this...

The idea of using profiles is not, what I want - it would be so great if you can tell me how to do the above things!

Best regards and thanks a lot again

cool400 :whistle:

Edited by cool400
Link to comment
Share on other sites

Okay, give this a go and let me know how it works for you.

Edit: good gravy, get it right the first time Alex...

; declare variables to be used
local $process, $winOpen, $winClosed, $mouse1, $mouse2
local $automating = 0

; start PENetCfg
$process = run("PENetCfg.exe /Useprofile")

; -----------------------------------------------------------------------------

; wait until first window appears or process exits
do
    $winOpen = winWait("", "&Nein", 1)
    if not($winOpen) and not(processExists($process)) then exit
until ($winOpen)

; immediately take note of mouse coordinates
$mouse1 = mouseGetPos()

; wait five seconds for window to close (i.e. user interaction)
$winClosed = winWaitClose("", "&Nein", 5)

if not($winClosed) then
  ; window did not close after 5 seconds
    $mouse2 = mouseGetPos()
    if ($mouse1[0] = $mouse2[0] and $mouse1[1] = $mouse2[1]) then
      ; mouse has not moved either -- no user present
        $automating = 1
        controlClick("", "&Nein", "TRzBitBtn2")
    endIf
endIf

; -----------------------------------------------------------------------------

; wait until next window appears or process exits
do
    $winOpen = winWait("", "Durchsuchen", 1)
    if not($winOpen) and not(processExists($process)) then exit
until ($winOpen)

if ($automating) then
  ; we are automatically handling this window
    controlClick("", "Durchsuchen", "TRzBitBtn3")
else
  ; we are waiting for the user
    $mouse1 = mouseGetPos()
    $winClosed = winWaitClose("", "Durchsuchen", 5)
    if not($winClosed) then
      ; window did not close after 5 seconds
        $mouse2 = mouseGetPos()
        if ($mouse1[0] = $mouse2[0] and $mouse1[1] = $mouse2[1]) then
          ; mouse has not moved either -- no user present
            $automating = 1
            controlClick("", "Durchsuchen", "TRzBitBtn3")
        endIf
    endIf
endIf

; -----------------------------------------------------------------------------

; wait until next window appears or process exits
do
    $winOpen = winWait("PE Network Configurator", "Netzwerkidentifikation", 1)
    if not($winOpen) and not(processExists($process)) then exit
until ($winOpen)

if ($automating) then
  ; we are automatically handling this window
    controlClick("PE Network Configurator", "Netzwerkidentifikation", _
            "TRzBitBtn13")
else
  ; we are waiting for the user
    $mouse1 = mouseGetPos()
    $winClosed = winWaitClose("PE Network Configurator", _
        "Netzwerkidentifikation", 5)
    if not($winClosed) then
      ; window did not close after 5 seconds
        $mouse2 = mouseGetPos()
        if ($mouse1[0] = $mouse2[0] and $mouse1[1] = $mouse2[1]) then _
            controlClick("PE Network Configurator", "Netzwerkidentifikation", _
            "TRzBitBtn13")
    endIf
endIf
Edited by LxP
Link to comment
Share on other sites

WOW - thank you very much, Alex!!! :dance::dance::(

This script is exactly the thing that I searched for for months...

I tried it out and it works like a charm - I just posted it (and credits to you and your work) in the 911cd-forum.

You're the best, it's so nice to have people like you helping someone!

Best regards and thanks a lot again

cool400 :whistle:

Link to comment
Share on other sites

No problem cool400 -- it was a pleasure helping you because you are polite and from your very first post you have demonstrated effort in your code, and effort in reading the help file. You're a model new forum member! :dance:

If only we could have them all like this. Unfortunately I don't think we'll see anyone script a solution for that. :whistle:

Link to comment
Share on other sites

  • 4 months later...

Just posting the English version if anyone is interested. I was able to pull the windows titles too.

Thank you LxP and Cool400 for all the work done on this. Works like a charm!!!!

Trekn820

; declare variables to be used

local $process, $winOpen, $winClosed, $mouse1, $mouse2

local $automating = 0

; start PENetCfg

$process = run("PENetCfg.exe /UseProfile")

; -----------------------------------------------------------------------------

; wait until first window appears or process exits

do

$winOpen = winWait("Confirm", "&No", 1)

if not($winOpen) and not(processExists($process)) then exit

until ($winOpen)

; immediately take note of mouse coordinates

$mouse1 = mouseGetPos()

; wait five seconds for window to close (i.e. user interaction)

$winClosed = winWaitClose("Confirm", "&No", 5)

if not($winClosed) then

; window did not close after 5 seconds

$mouse2 = mouseGetPos()

if ($mouse1[0] = $mouse2[0] and $mouse1[1] = $mouse2[1]) then

; mouse has not moved either -- no user present

$automating = 1

controlClick("Confirm", "&No", "TButton2")

endIf

endIf

; -----------------------------------------------------------------------------

; wait until second window appears or process exits

do

$winOpen = winWait("PE Network Configurator - Network Profiles", "Browse...", 1)

if not($winOpen) and not(processExists($process)) then exit

until ($winOpen)

if ($automating) then

; we are automatically handling this window

controlClick("PE Network Configurator - Network Profiles", "Browse...", "TRzBitBtn2")

else

; we are waiting for the user

$mouse1 = mouseGetPos()

$winClosed = winWaitClose("PE Network Configurator - Network Profiles", "Browse...", 5)

if not($winClosed) then

; window did not close after 5 seconds

$mouse2 = mouseGetPos()

if ($mouse1[0] = $mouse2[0] and $mouse1[1] = $mouse2[1]) then

; mouse has not moved either -- no user present

$automating = 1

controlClick("PE Network Configurator - Network Profiles", "Browse...",

"TRzBitBtn2")

endIf

endIf

endIf

; -----------------------------------------------------------------------------

; wait until third window appears or process exits

do

$winOpen = winWait("PE Network Configurator", "Network Identification", 1)

if not($winOpen) and not(processExists($process)) then exit

until ($winOpen)

if ($automating) then

; we are automatically handling this window

controlClick("PE Network Configurator", "Network Identification", "TRzBitBtn11")

else

; we are waiting for the user

$mouse1 = mouseGetPos()

$winClosed = winWaitClose("PE Network Configurator","Network Identification", 5)

if not($winClosed) then

; window did not close after 5 seconds

$mouse2 = mouseGetPos()

if ($mouse1[0] = $mouse2[0] and $mouse1[1] = $mouse2[1]) then _

controlClick("PE Network Configurator", "Network Identification",

"TRzBitBtn11")

endIf

endIf

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