Jump to content

Run script when app starts and run it multiple times


Go to solution Solved by Leendert-Jan,

Recommended Posts

I am totaly new to autoit (discover it today). I mange to program script to do what I want but at the moment it do it only once and immediatly after I run the script manualy. But I need this:

Start script when specific application starts. Then run in background and do nothing untill specific button is pressed by user. It is ok even to start script when button is pressed as I would not need it before. But I think that it is not possible to binde script like that. Then it should run and do its job and then wait again for user to press same button. So basicly while application is open script should wait for in app button click and then execute code. Than wait again.... It could be repeated 1x per minute but also 20x...

Basicly my script wait for user to print something (by pressing specific button inside app), than read log file that is automaticly generated and then write some info from that file in specific textbox inside application. I managed that part and it is working ok. Just have troubles with making it running while app is open and to close when app is closed.

I feel that this is simple task to do but I just can't figure it out how.  I would probably comple my script to run as standalone application if it is important for my solution, as script will run on PC without installed autoscript on it.

Link to comment
Share on other sites

Perhaps ProcessExists() can help you?

https://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm

You can use a while loop like this to check if the program started:

While True
    If ProcessExists("program.exe") Then 
        MsgBox(64, "", "Program started")
        ExitLoop
    EndIf
WEnd

 

Edited by Leendert-Jan
Changed msgbox type to information (64)
Link to comment
Share on other sites

20 minutes ago, Leendert-Jan said:

Perhaps ProcessExists() can help you?

https://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm

You can use a while loop like this to check if the program started:

While True
    If ProcessExists("program.exe") Then 
        MsgBox(64, "", "Program started")
        ExitLoop
    EndIf
WEnd

 

Hey man tnx, I think that this is good direction to go. Just to add to my question, how to chceck if button is pressed in "program.exe". I mean I know how to identify button with Window info, but what is correct way to detect button is pressed?

Link to comment
Share on other sites

For setting value in field that has this properties

This is not working:

ControlSend("BF BROJ","","[CLASS:Edit; INSTANCE:1]", $finalBF)

 

but I wonder should I use "ControlSetText" (can't test now as I need BF BROJ windows to be opened and can't open it at the moment, but just trying to figure it out why ControlSend is not working.

So will this work:

ControlSetText("BF BROJ", "", "[CLASS:Edit; INSTANCE:1]", "99")

 

neradi.png

Link to comment
Share on other sites

5 minutes ago, Didinjo said:

but I wonder should I use "ControlSetText"

ControlSend works the same as Send, but instead of just sending the keystrokes, it sends them to a specific control (in most cases a textbox). It will add the text to the control.

ControlSetText on the other hand overwrites the text that is already in the textbox.

 

5 minutes ago, Didinjo said:

can't test now as I need BF BROJ windows to be opened and can't open it at the moment

You can always test using notepad :)

Edited by Leendert-Jan
Link to comment
Share on other sites

Tnx, but I have strange problem with textbox that I need to populate with those command. I added screen shot of Windows info for that textbox which I can't rach (or be able to change with ControlSend command. Don't know why. Tried all kind of variants for third parrameter (CLASSNN, CLASS, ID; CLASS + INSTANCE) but never be able to change content of that textbox. I use additional popup dialog to test if value that need to be inserted is set and it is. Everything works fine except I am unable to add text to that textbox.

Unfortunetly it is onyl text box in that window. In rest of application I don't have problem to access textboxes. I know that I address correctly first parameter (Window name) as I successifuly pass "If WinExists("BF BROJ") Then...."

 

 

Link to comment
Share on other sites

  • Solution
5 minutes ago, Didinjo said:

So you suggest to try this:

ControlSend("[ACTIVE]","","[CLASS:Edit; INSTANCE:1]", $finalBF)

Yes, in some cases, even when the title is correct, AutoIt might not be able to access specific controls (e.g. no break spaces, multiple windows with the same name).

This is especially true if you run the window you are trying to access as administrator and your script as a normal user, or vice versa.

Edited by Leendert-Jan
Link to comment
Share on other sites

15 hours ago, Leendert-Jan said:

Yes, in some cases, even when the title is correct, AutoIt might not be able to access specific controls (e.g. no break spaces, multiple windows with the same name).

This is especially true if you run the window you are trying to access as administrator and your script as a normal user, or vice versa.

 Unfortunetly  "[ACTIVE]" didn't help. Still not able to edit text box. I just hate when hit problems like this as it looks that everything is fine but it is not working.

Link to comment
Share on other sites

As a workaround you can use MouseClick() to click (and focus) on the textbox, and use regular Send() to send the text you want. Something like this:

MouseClick("left", x, y)
Send("test")

Replace the x and y with the coordinates of the textbox. You can find the coordinates on the Mouse tab of the AutoIt Window Info.

More info:

https://www.autoitscript.com/autoit3/docs/functions/MouseClick.htm

Link to comment
Share on other sites

Well I just have one more question.

If I have function like this

 

F

Global $Form1 = GUICreate("AutoBF", 353, 209, 192, 114)
Global $UPALI = GUICtrlCreateButton("UPALI AutoBF", 32, 40, 137, 65)
Global $exit = GUICtrlCreateButton("ZATVORI", 105, 118, 137, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Global $UGASI = GUICtrlCreateButton("UGASI AutoBF", 184, 41, 137, 65)
GLOBAL $Label1 = GUICtrlCreateLabel("STATUS: !!! AUTO BF UGAŠEN !!!", 100, 11, 350, 25) ; first cell 70 width
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $UPALI
         GUICtrlSetData($Label1, "STATUS: *** AUTO BF AKTIVAN ***")
         GUISetState()
         GUICtrlSetState($UPALI, $GUI_DISABLE)
         GUICtrlSetState($UGASI, $GUI_ENABLE)
         test()

        Case $UGASI
          GUICtrlSetData($Label1, "STATUS: !!! AUTO BF UGAŠEN !!!")
          GUISetState()
          GUICtrlSetState($UGASI, $GUI_DISABLE)
          GUICtrlSetState($UPALI, $GUI_ENABLE)


        Case $exit
            Exit


    EndSwitch
 WEnd





Func test()

  While true 
    .....

    If something then
        exitloop
    EndIf
  WEnd

EndFunc

 

As you can see I have two buttons one for starting (UPALI) and other for stoping (UGASI).  Starting is not problem but how to stop while loop that is started in Func test().  I guess that everyitime I call function new instance is created. 

 

Link to comment
Share on other sites

  • Developers
2 hours ago, Didinjo said:

Starting is not problem but how to stop while loop that is started in Func test()

Ensure you return from test() to keep on reading the messages from the GUI!

Show us a piece of runnable code that shows the issue so we can help you modify it.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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