Help needed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 08:57

one more change to where ListVars is done, else we might miss info.
Idea: get info then print-to-screen, not the other way round, silly! :D

Code: Select all

    {
        ControlGet, hButton, hwnd,, %BtnName%, ahk_pid %progPID%
        ListVars
        Sleep, 15       ; limit to ~60 checks per second
    }
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 09:06

Ok made your last change, started the script under test conditions (notepad is open)
Getting the following windows after that:

Image

Current script:

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 := "RoS-BoT-714"
program  := "C:\Users\D3\Desktop\okok\" 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
    {
        ControlGet, hButton, hwnd,, %BtnName%, ahk_pid %progPID%
        ListVars
        Sleep, 15       ; limit to ~60 checks per second
    }

    ControlClick, %hButton%                         ; (6)
}



;-------------------------------------------------------------------------------
F5:: ExitApp ; emergency hotkey {F5}
;-------------------------------------------------------------------------------
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 09:58

I suspect a typo (of mine): "Start botting !" is not the same as "Start botting!"

Use what WinSpy can read. check again and again, this gets tedious easily. :thumbup:
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 10:04

The program window says "Start botting !" and WinSpy can also read "Start botting !" :?:

Image :?:

Edit: Same result no matter if I use

Code: Select all

Start botting!
or

Code: Select all

Start botting !
Getting the same windows from AHK like I posted before

Possible because the program window where the button is having no focus? :?:
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 10:21

ouch! hmm, lets start examining if we can get the handle of a button elsewhere, C:\Windows\System32\charmap.exe for example
look for button "&Select"
this works for me:

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
;-------------------------------------------------------------------------------
program      := "charmap.exe"
pathToProgram := "C:\Windows\System32\"
BtnName       := "&Select"



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

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

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

    ; where is the button                           ; (5)
    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
        ListVars
    }

    ControlClick, %hButton%                         ; (6)
}



;-------------------------------------------------------------------------------
F5:: ExitApp ; emergency hotkey {F5}
;-------------------------------------------------------------------------------
Edit: changed where ".exe" should go and added pathToProgram
Maybe we should look at ClassNN after ...
Last edited by wolf_II on 23 Sep 2018, 10:35, edited 1 time in total.
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 10:35

This happening for me:
Image
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 10:37

Perfect, same here, make sure you got the last change also. ...
be back with ideas when they come ... classNN ... hmm
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 10:39

wolf_II wrote:Perfect, same here, make sure you got the last change also. ...
be back with ideas when they come ... classNN ... hmm
Well I get the same window with the last changes :(
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 11:19

Carl wrote:Well I get the same window with the last changes :(
:D that was meant to still work the same.

ListVars shows we have a hButtton, we don't click it correctly.
What I noticed is a mistake in (6).
The problem is counting the commas correctly in (6). myBAD :oops:

here is now better version which SUCCESSFULLY clicks the button

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      ; decimal/hex value ( use/meaning )
;-------------------------------------------------------------------------------
progPID := 0    ; will hold PID of the program with the wanted button | decimal
hButton := 0    ; will toggle between 0 and the handle of the button  | hex



;-------------------------------------------------------------------------------
; configure
;-------------------------------------------------------------------------------
Program       := "charmap.exe"
PathToProgram := "C:\Windows\System32\"
BtnName       := "&Select"



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

    ; make sure program has stopped                 ; (3)
    Process, Exist, %Program%
    if ErrorLevel ; there is a problem
    {
        MsgBox,, Alert!, %ErrorLevel% is the PID of %Program%, 1
        WinClose, ahk_pid %ErrorLevel%
        Sleep, 1000 ; add a li'l time to look
    }

    Run, %Program%, %PathToProgram%,, progPID       ; (4)

    ; where is the button                           ; (5)
    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
    }

    Sleep, 1000 ; add a li'l time to look
    ControlClick,, ahk_id %hButton%                 ; (6)
}



;-------------------------------------------------------------------------------
F5:: ExitApp ; emergency hotkey {F5}
;-------------------------------------------------------------------------------
I hope you will succeed with whatever.exe and "Start botting !"
Good Luck. :D
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

23 Sep 2018, 12:05

Hmm, may not work yet, but the clicking is fixed, Let me know if not.

Then look at using ClassNN (maybe with charmap first, to get the syntax right).
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

23 Sep 2018, 12:51

It seems to work so far^^

Will do a test till tomorrow and will see if it work like it should

Thank you again so much for your help!!! :bravo:
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

30 Sep 2018, 11:19

Ok the current script is working fine.
I wanna add a condition for restarting the one application, if another application is "not responding" so the script should force close the "not responding" one and then cycle like the normal script
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

30 Sep 2018, 11:51

You can try to replace WinClose with WinKill here:

Code: Select all

WinKill, ahk_pid %ErrorLevel%
Read the Remarks section on the respective commands in the help to see how they differ.

I can't tell what whatever.exe will do and how fast that will happen, so you may have to tweak the sleep or put that whole section (3) of the script in the body of a loop.
Guest

Re: Help needed

30 Sep 2018, 13:56

I will not close the "whatever.exe" that we talked about the whole time, I wanna "add" a trigger condition for restarting the "whatever.exe" if another window get the"not responding"-status
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

02 Oct 2018, 10:45

wolf_II wrote:You can try to replace WinClose with WinKill here:

Code: Select all

WinKill, ahk_pid %ErrorLevel%
Read the Remarks section on the respective commands in the help to see how they differ.

I can't tell what whatever.exe will do and how fast that will happen, so you may have to tweak the sleep or put that whole section (3) of the script in the body of a loop.

I will not close the "whatever.exe" that we talked about the whole time, I wanna "add" a trigger condition for restarting the "whatever.exe" if another window get the"not responding"-status
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

02 Oct 2018, 15:23

Maybe, you could add in the config block a line like PROG2 = "wheatever-else.exe"?
Then, add all your conditions for when to respond, and how to respond in the Loop.
In case you get stuck, post your script.

I have no idea how to tell if "wheatever-else.exe" gets the "not responding"-status.
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

15 Oct 2018, 08:58

The original script is broken, it only starts the whatever.exe but not clicking the button anymore. I double checked if the button-name is still the same (it is)! Not sure what's going on
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

15 Oct 2018, 10:43

Carl wrote:
15 Oct 2018, 08:58
The original script is broken
Do I get this right? The "original" script is the one where I claim that it works for me ?
I tried again, it works OK for me, and I can not reproduce the error.

After-thought: Did anything change between your initial tests and now?
Maybe you use a different "whatever.exe"? (update)
On a different PC with a different Windows version?
Carl
Posts: 20
Joined: 22 Sep 2018, 16:56

Re: Help needed

15 Oct 2018, 12:43

The .exe name changed, yes...but I renamed it also in the script and the program path is the same...
Only the name of the exe changed

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      ; decimal/hex value ( use/meaning )
;-------------------------------------------------------------------------------
progPID := 0    ; will hold PID of the program with the wanted button | decimal
hButton := 0    ; will toggle between 0 and the handle of the button  | hex



;-------------------------------------------------------------------------------
; configure
;-------------------------------------------------------------------------------
Program       := "RoS-BoT.exe"
PathToProgram := "C:\Users\D3\Desktop\okok"
BtnName       := "Start botting !"



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

    ; make sure program has stopped                 ; (3)
    Process, Exist, %Program%
    if ErrorLevel ; there is a problem
    {
        MsgBox,, Alert!, %ErrorLevel% is the PID of %Program%, 1
        WinClose, ahk_pid %ErrorLevel%
        Sleep, 1000 ; add a li'l time to look
    }

    Run, %Program%, %PathToProgram%,, progPID       ; (4)

    ; where is the button                           ; (5)
    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
    }

    Sleep, 1000 ; add a li'l time to look
    ControlClick,, ahk_id %hButton%                 ; (6)
}



;-------------------------------------------------------------------------------
F5:: ExitApp ; emergency hotkey {F5}
;-------------------------------------------------------------------------------
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help needed

15 Oct 2018, 13:27

The name of the exe changed. Do you still get info about the target button with WinSpy?
If that changed too, the script can't work. You would have to fall back onto more sophisticated scripts.
If that did not change, try to copy the name of the button from WinSpy and paste it in the script or in a empty file to double check spelling (unicode chars), punctuation and underlined letters, which may be different, yet unnoticed.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 118 guests