Help needed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Help needed

22 Sep 2018, 17:02

I need the following:

1. Script should wait till a program(notepad editor of windows) opening a error log window
2. Script should close error log window or ending the process (whatever is easier)
3. Script should start a program and there it should click "start" I guess it will needing coordinates to click the correct button
4. After the start button got clicked successfully the script should go again in standby till the next error log window comes up and then do the steps from 2-4 again
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

22 Sep 2018, 17:59

I hope this nearly-pseudo-code helps.

Code: Select all

/*
1. Script should wait till a program(notepad editor of windows) opening a error log window
2. Script should close error log window or ending the process (whatever is easier)
3. Script should start a program
   and there it should click "start"
   I guess it will needing coordinates to click the correct button
4. After the start button got clicked successfully the script should
   go again in standby till the next error log window comes up
   and then do the steps from 2-4 again
*/



;-------------------------------------------------------------------------------
Loop { ; forever
;-------------------------------------------------------------------------------
    WinWait, ErrorLog ahk_exe notepad.exe           ; (1)
    WinClose                                        ; (2)
    Run, whatever, get PID                          ; (3a)

    While not Button ; waiting for button to appear
        ControlGet, Button, hwnd,, Start, use PID

    ControlClick, Start                             ; (3b)
    ; do nothing and restart from (1)               ; (4)
}
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

22 Sep 2018, 18:29

A Bit I guess^^ But we need to find the button with coordinates or will start really work if the button is labeled with start? What's about the loop will this version of you stop actions after clicked the button and go back to standby till a new notepad window appears again?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

22 Sep 2018, 18:41

I don't know what Run, whatever will start. Programs that don't work, we will call just weird and stop, or study a lot, and hope for early results.
I think it's worth trying, there some nice programs where it works.
Edit: Yes, the code should stop actions and start a new WinWait.

Condensed and fine tuned:

Code: Select all

/*
1. Script should wait till a program(notepad editor of windows) opening a error log window
2. Script should close error log window or ending the process (whatever is easier)
3. Script should start a program
4. and there ...
5. it should click "start"
*/


;-------------------------------------------------------------------------------
Loop { ; forever
;-------------------------------------------------------------------------------
    WinWait, ErrorLog ahk_exe notepad.exe           ; (1)
    WinClose                                        ; (2)
    Run, whatever, get PID                          ; (3)

    ; where is the button?                          ; (4)
    Button := False     ; reset each time
    While not Button    ; waiting for button to appear
    {
        ControlGet, Button, hwnd,, Start, use %PID%
        Sleep, 15       ; limit to 60x checks per second vs. more
    }

    ControlClick, Start                             ; (5)
}
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

22 Sep 2018, 20:01

Well there are different buttons in the program window which should be reopen, one button will start the main function of the program, the others are for config settings etc...
Image

Marked the button
This button I wanna to be clicked
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

22 Sep 2018, 21:14

Now use WinSpy. If WinSpy can see the button that would mean, we are good to go.
WinSpy is started from RightClick on SysTray icon near the clock.
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 05:42

wolf_II wrote:Now use WinSpy. If WinSpy can see the button that would mean, we are good to go.
WinSpy is started from RightClick on SysTray icon near the clock.
Image

Nice! It can read out the button!
So anything to edit now?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 05:52

Don't edit yet: study first

Notice: control under mouse position field contains Text and ClassNN. There is a little confusion coming up since classNN looks dodgy to me.
The next check I would do: Rum your experiment a few times, write down EXACT classNN each time. same Program, same button, is it still same classNN?
It might be, it might not be, we don't care, we just need to know which it is. We may know already the solution to that particular weirdness.
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 06:02

Yes it's the same classNN

It's always ClassNN: WindowsForms10.BUTTON.app.0.2bf8098_r9_ad18

Window title is generated, but the .exe same is always same

btw, I'm not sure about the errorLog part for Notepad, wouldn't it be saver to just use it like if Notepad window appears in general?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 06:28

Now we get the handle of that button. Precision is king here, use the caption/text of the button.

this line: check all the commas, they control how each piece of info gets passed to AHK.

Code: Select all

ControlGet, Button, hwnd,, Start Botting !, ahk_id %PID%
the first 4 pieces are ControlGet, Button, hwnd, Value. (Value we don't use = empty)

Compare with the help file where it tells the meaning of all these pieces.
So far we have the command, comma, Button comma hwnd two commas. Which are OutputVar and SubCommand

we will use the handle, we got the handle before with hwnd, it is saved in varable Button.
like that:

Code: Select all

    ControlClick, %Button%                           ; (5)

Carl wrote:btw, I'm not sure about the errorLog part for Notepad, wouldn't it be saver to just use it like if Notepad window appears in general?
Let's test that. separately.
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 06:36

Could you post the script in his finished form please? :)
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 06:41

I can and I will.

First things first: I know notepad.exe. I don't know the errorLog part for Notepad. What is this saying, EXACTLY :?:
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 06:53

wolf_II wrote:I can and I will.

First things first: I know notepad.exe. I don't know the errorLog part for Notepad. What is this saying, EXACTLY :?:
Why we cannot use notepad in general? Like as soon as notepad.exe window appears it should start the script trigger

ErrorLog meant, the program opening sometimes a error-message in notepad, because it can't handle a situation
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 07:04

Carl wrote:Why we cannot use notepad in general? Like as soon as notepad.exe window appears it should start the script trigger
ErrorLog meant, the program opening sometimes a error-message in notepad, because it can't handle a situation
We can, as long as you realize that this means every time notepad.exe starts, this script will close it and run whatever instead. AND try to click a button there.
You can consider putting in an emergency break, in case unexpected things happen, you can always exit the script from SysTray, so you can get away without.
Just consider it, and consider again later, when unexpected things start happening. Keep in mind: emergency breaks are a thing.

Next, what does your Run, whatever, get PID say, EXACTLY :?:

Just replace whatever in the script in line marked ; (3) <<<:

Code: Select all

/*
1. Script should wait till a program(notepad editor of windows) opens
2. Script should close notepad window or ending the process (whatever is easier)
3. Script should start a program
4. and there ...
5. it should click "start"
*/



; configure
program := "C:\path\to\whatever.exe"    
BtnName := "Start botting!"

; variable      ; hex value ( use/meaning )
progPID := 0    ; will hold PID of the program with the wanted button
hButton := 0    ; will toggle between 0 and the handle of the button



;-------------------------------------------------------------------------------
Loop { ; forever
;-------------------------------------------------------------------------------
    WinWait, ahk_exe notepad.exe                    ; (1)
    WinClose                                        ; (2)
    Run, %program%,,, progPID                       ; (3) 

    ; where is the button                           ; (4)
    hButton := False    ; reset each time
    While not hButton   ; waiting for button to appear
    {
        ControlGet, hButton, hwnd,, %BtnName%, ahk_pid %progPID%
        Sleep, 15       ; limit to ~60 checks per second
    }

    ControlClick, %hButton%                         ; (5)
}



;-------------------------------------------------------------------------------
F5:: ExitApp ; emergency hotkey {F5}
;-------------------------------------------------------------------------------
Last edited by wolf_II on 23 Sep 2018, 07:51, edited 1 time in total.
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 07:38

Run, whatever,,, PID

I just need to change whatever to the .exe I wanna start right? Is the PID needed too? Not 100% sure if the PID is also every time the same
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 07:52

just updated script again, sorry. Yes, but now it's:
Fill in ; configure


Pid will be diferent each time, that's right. We get it fresh for every program we run.
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 08:07

wolf_II wrote:just updated script again, sorry. Yes, but now it's:
Fill in ; configure


Pid will be diferent each time, that's right. We get it fresh for every program we run.
Ok great! tested the script a bit

1) Script closing Notepad like it should
2) Starting the program like it should
3) Not clicking the Start button after the program started <<<More work needed^^


What I thought about, can we add a kill process to be sure that the program which should start after notepad is closed is not running anymore? (I guess it should not run after the error appeared, but just to be sure it really not running)
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 08:16

OK, more work is done with help of debugging tools. I'd start with buildt-in ListVars command.

I can not test and see on screen, so you have to do that. I might get this wrong, lets see ...

patch this block of code with ListVars

Code: Select all

    While not hButton   ; waiting for button to appear
    {
        ControlGet, hButton, hwnd,, %BtnName%, ahk_pid %progPID%
        Sleep, 15       ; limit to ~60 checks per second
        ListVars
    }
Run and see what all the variables contain while the script runs. after that, I don't know yet, I might need a screenshot.

What I thought about, can we add a kill process to be sure that the program which should start after notepad is closed is not running anymore? (I guess it should not run after the error appeared, but just to be sure it really not running)
We can do that also, ...
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 08:35

(3) make sure program has stopped before starting it, renumber old steps 3..5

Code: Select all

/*
1. Script should wait till a program(notepad editor of windows) opens
2. Script should close notepad window or ending the process (whatever is easier)
3. make sure program has stopped before starting it
4. Script should start a program
5. and there ...
6. it should click "start"
*/



;-------------------------------------------------------------------------------
; variable      ; hex value ( use/meaning )
;-------------------------------------------------------------------------------
progPID := 0    ; will hold PID of the program with the wanted button
hButton := 0    ; will toggle between 0 and the handle of the button



;-------------------------------------------------------------------------------
; configure
;-------------------------------------------------------------------------------
progName := "whatever"
program  := "C:\path\to\" progName ".exe"
BtnName  := "Start botting!"



;-------------------------------------------------------------------------------
Loop { ; forever
;-------------------------------------------------------------------------------
    WinWait, ahk_exe notepad.exe                    ; (1)
    WinClose                                        ; (2)

    ; make sure program has stopped                 ; (3)
    Process, Exist, %progName%
    if ErrorLevel ; there is a problem
    {
        MsgBox,, Alert!, %ErrorLevel% is the handle of %progName%.exe
        ExitApp
    }

    Run, %program%,,, progPID                       ; (4)

    ; where is the button                           ; (5)
    hButton := False    ; reset each time
    While not hButton   ; waiting for button to appear
    {
        ListVars
        ControlGet, hButton, hwnd,, %BtnName%, ahk_pid %progPID%
        Sleep, 15       ; limit to ~60 checks per second
    }

    ControlClick, %hButton%                         ; (6)
}



;-------------------------------------------------------------------------------
F5:: ExitApp ; emergency hotkey {F5}
;-------------------------------------------------------------------------------
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 08:44

Great work

I will doing some tests now and reporting problems(if they're happening) later :)

At this point I wanna say thanks for your work!
I really appreciated

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], mikeyww and 165 guests