Help on Script I just can't get to Exit

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
deathw
Posts: 11
Joined: 15 Oct 2014, 01:20

Help on Script I just can't get to Exit

26 Oct 2014, 06:45

I need help on a simple script that I just can't figure out how to Exit properly at the end.

I've read the docs and if I put "!o::ExitApp" it will exit when pressed, but ExitApp doesn't work at the end of my script. If I take it out than ExitApp works fine.

I just don't know what to do, I see the examples but don't get it fully. Could pressing OK on the message box exit the script? or even after its pressed it just ends with no connection to the message box.

Please help me. I've Included the code below that works fine when Alt+p and o are pressed but just wont Exit at all after the message box. I just want it to be simple.

Code: Select all


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.

IfWinExist, BlueStacks App Player	                ; Looking for Bluestacks
WinActivate 			                        ; Bringing Bluestacks to the front of screen


loop, 10

	{

MouseMove, 720, 694       ; Mouse Placement on Retry
 
click                              ; Send, {VK01 down}{VK01 up} Same as Click

Sleep, 4500                    ; 4500 is 4.5 seconds 60000 is 1 minute - milliseconds - 800 loops for one hour at 4.5 seconds

}

MsgBox, 0,, Completed Script.         ; Simple Notification of Completion.


!p::Pause                              ; Alt+p to pause script, press again to resume.

!o::ExitApp                            ; Ends Script on command pressing Alt+o

ExitApp                                 ; Not ending the Script



It's more spaced out than normal but that's just so I can mess around with the code.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Help on Script I just can't get to Exit

26 Oct 2014, 09:47

Its because you are executing a Pause before the ExitApp

Code: Select all

;.............
MsgBox, 0,, Completed Script.         ; Simple Notification of Completion.
; ^^ After this Message Box is closed ... 

!p::Pause                              ; Alt+p to pause script, press again to resume.
; ^^ ... this Pause will execute ...
!o::ExitApp                            ; Ends Script on command pressing Alt+o
; ^^ ... making this ExitApp not execute.
ExitApp  
; ^^ ... This ExitApp will never execute.
try this:

Code: Select all

;.............
MsgBox, 0,, Completed Script.         ; Simple Notification of Completion.

!o::ExitApp                            ; Ends Script on command pressing Alt+o

!p::Pause                              ; Alt+p to pause script, press again to resume.
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

26 Oct 2014, 10:28

TLM wrote:Its because you are executing a Pause before the ExitApp

Code: Select all

;.............
MsgBox, 0,, Completed Script.         ; Simple Notification of Completion.
; ^^ After this Message Box is closed ... 

!p::Pause                              ; Alt+p to pause script, press again to resume.
; ^^ ... this Pause will execute ...
!o::ExitApp                            ; Ends Script on command pressing Alt+o
; ^^ ... making this ExitApp not execute.
ExitApp  
; ^^ ... This ExitApp will never execute.
Sorry, but this is simply not true. Did you try this code?
The last ExitApp simply is not reached because of the hotkeys. And the first ExitApp is (in this case) only executed if Alt+o is pressed. (If !p::Pause was not on one line only then it would also require a return for the next hotkey not to be executed as well.) Pause itself is not executed automatically. Only if Alt+p is pressed. At least that is what my tests showed.

However, the last ExitApp anyway makes no sense in connection with an ExitApp hotkey. Either the script should exit on its own or at the press of a hotkey. Both is not possible.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Help on Script I just can't get to Exit

26 Oct 2014, 10:57

autocart wrote:Sorry, but this is simply not true.
Actually it's absolutely true. If the Message Box is closed, the script will not exit.

Code: Select all

Msgbox Press to OK close
F3::Pause
Esc::ExitApp
As you can see, and as in the OP's script, the Pause command is being executed before the ExitApp.
By simply switching the hotkeys around or adding an additional ExitApp command, it should resolve the OP's issue:

Code: Select all

Msgbox Press to OK close
Esc::ExitApp
F3::Pause

;  OR
Msgbox Press to OK close
ExitApp

F3::Pause
Esc::ExitApp
I suggested to move the hotkeys as not to add repetitive code.
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

26 Oct 2014, 11:05

The point being, TLM, is that Pause in this case is not executed unless the hotkey is pressed, even though it in the code is above ExitApp, which, as we all know, is also not executed.

If you don't believe it, why do you not simply try the code, as indicated already?
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

26 Oct 2014, 11:10

you edited while i was answering, no problem:
your 2nd expamle makes not sense (as does the OP's original example, as alredy mentioned above). Either ExitApp in the "normal" code OR in a hotkey, both together makes no sense. (EDIT: Unless of course the user wants to exit the script with a hotkey while the message box is shown.)

(EDIT2: If you were right then your first example also would not make sense. Because then, according to your Pause-explaination the ExitApp in your 1st examle would be executed automatically, not waiting for the hotkey, making the hotkey obsolete. However, the script does wait after the msgbox is closed. Therefore proving that your 1st example is ok but your explaination is wrong.)

For you to see better what is being executed, you can also exchange "Pause" with e.g. "Run Notepad". Then you see clearly that it is not being exectued.
Last edited by autocart on 26 Oct 2014, 11:29, edited 1 time in total.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Help on Script I just can't get to Exit

26 Oct 2014, 11:21

autocart wrote:...Pause in this case is not executed unless the hotkey is pressed
Not true (based off the OP's code and my example)
exit.gif
exit.gif (79.14 KiB) Viewed 6843 times
as you can clearly see:
a) pause is executed
b) the script is not exited
The reason Pause is executed after the message box is closed ( regardless of being in a hotkey ),
is because there is nothing stopping it from executing.
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

26 Oct 2014, 11:44

(EDIT: @TLM: the picture is not being displayed; now it is, thx; as Nextron below pointed out, though, something is wrong there; would you mind posting the exact code that you used for the example in the pic, please)

for anybody else reading along here:
you can either try it out yourself or look up the help file:
FAQ:

Why do some lines in my script never execute?

Any lines you want to execute immediately when the script starts should appear at the top of the script, prior to the first hotkey, hotstring, or Return. For details, see auto-execute section.
Basic Usage and Syntax / Scripts:

The Top of the Script (the Auto-execute Section)

After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
Last edited by autocart on 26 Oct 2014, 13:51, edited 1 time in total.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Help on Script I just can't get to Exit

26 Oct 2014, 13:30

I'm with autocart on this. Whatever is happening in TLM's picture, shouldn't: Hotkeys don't run as part of the autoexecute section (imagine the chaos :crazy: ) and it doesn't with me (1.1.14 32bit). Either something else is triggering the pause, or you're not using the same script as I am or you've found a bug.

@deathw: put ExitApp directly below your MsgBox and only below that, define your hotkeys... fixed.
deathw
Posts: 11
Joined: 15 Oct 2014, 01:20

Re: Help on Script I just can't get to Exit

26 Oct 2014, 14:59

idk wtf I'm doing but I guess thanks....I just wanted to simply pause and manual exit and end the script at the end. I guess thats not possible.
deathw
Posts: 11
Joined: 15 Oct 2014, 01:20

Re: Help on Script I just can't get to Exit

26 Oct 2014, 15:03

I'm not turning this into a exe it's running simply from the ahk file, for certain reasons.
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

26 Oct 2014, 15:09

deathw wrote:idk wtf I'm doing but I guess thanks....I just wanted to simply pause and manual exit and end the script at the end. I guess thats not possible.
Of course it is possible. You just need to be clear enough what you actually want. If you only want the manual hotkey-exit, then you don't need no other ExitApp in the code at all. Else explain in more detail under what conditions you want the script to exit "on its own".
deathw wrote:I'm not turning this into a exe it's running simply from the ahk file, for certain reasons.
were do you come up with this one from? this makes no difference here, it doen not matter
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

26 Oct 2014, 15:37

I just read your whole original code. Before, I concentrated on the hotkeys and how to exit the script.
I made some comments in the code.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.

IfWinExist, BlueStacks App Player
{ ;[You would want braces here or else the loop will be executed also when the window does not exist.]

WinActivate

loop, 10
{
MouseMove, 720, 694  ; Mouse Placement on Retry 
;[What does "on Retry" mean?]
click
Sleep, 4500   ; 4500 is 4.5 seconds 60000 is 1 minute - milliseconds - 800 loops for one hour at 4.5 seconds 
;[What does 800 loops mean? Were from do you come up with this?
; Overall there are better ways for this but never mind for right now.]
}

}

MsgBox, 0,, Completed Script.

ExitApp   ; Not ending the Script 
;[What does "Not ending the Script" mean? Was that a hint to the problem?
; Anyway, as pointed out by the other 2 posters, ExitApp without hotkey needs to go here if it is to take effect after the the loop and the MsgBox is finished. The hotkeys will work anyway.]

!p::Pause

!o::ExitApp
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Help on Script I just can't get to Exit

26 Oct 2014, 15:42

so if you run this

Code: Select all

msgbox press ok to exit
esc::exitapp
the script does not exit after you close the message box ?
because it should exit after the message box is closed.
ahk has always worked this way ever since 1.0.x

the only things that would stop if from exiting ( from the following exitapp from executing ),
is a return after the message box or if the message box was in a loop or if there was a goto/sub label pointing to another part of the script etc.

Code: Select all

msgbox press ok to close message box
return ; << -- this is what stops ahk from continuing through to the next command
esc::exitapp
it doesn't matter that exitapp is part of the escape hotkey
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

26 Oct 2014, 15:57

I am running the latest version of ahk: v1.1.16.05
TLM wrote:so if you run this

Code: Select all

msgbox press ok to exit
esc::exitapp
the script does not exit after you close the message box ?
No, it does not exit. Must have been changed in some version between 1.0.x and now.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Help on Script I just can't get to Exit

26 Oct 2014, 16:00

@ TLM

With your 3 line example in a cleen script the pause hotkey is the first autoexecute ending condition and there by does not get executed.

In any other case, even a one line hotkey like that is ofc just executed in the flow of the script, atleast if no exit or idling condition is encountered.

two examples

Code: Select all

#SingleInstance force
return

f8::
Msgbox Press to OK close
F3::Pause
Esc::ExitApp
pause is executed after F8 is pressed

Code: Select all

Msgbox Press to OK close
F3::Pause
Esc::ExitApp
This script does not pause for me.

Hope it helps
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: Help on Script I just can't get to Exit

26 Oct 2014, 16:11

ahh I see whats happening I use a script template with F1:: at the top of the script

Code: Select all

F1::

msgbox press ok to exit
esc::exitapp
mb
deathw
Posts: 11
Joined: 15 Oct 2014, 01:20

Re: Help on Script I just can't get to Exit

26 Oct 2014, 16:44

800 loops at 4.5 seconds was just a reminder to me that it equals a hour of the scripts running time, I'm seriously getting confused here with two total differences. Also I'm running 1.1.15.00 64bit.
deathw
Posts: 11
Joined: 15 Oct 2014, 01:20

Re: Help on Script I just can't get to Exit

26 Oct 2014, 17:04

all the ; were just reminders and stuff for me. I shouldn't of included them.
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Help on Script I just can't get to Exit

27 Oct 2014, 08:03

no problem,
So, does your code work for you now?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jameswrightesq and 412 guests