Unable to stop the process in the script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bapiman
Posts: 9
Joined: 20 Jan 2017, 08:10

Unable to stop the process in the script

20 Jan 2017, 08:29

Dear Team

Would appreciate if you can give me some help with this one. I have a simple script that clicks the down arrow when on an email program so we can navigate through a whole long bunch of emails very quickly (rather than keep pressing the arrow key again and again). Created two speeds for the key press.
Once it starts...I just cannot stop it. I have checked the forums and tried sticking in the Hotkey for Pause and ExitScript...even added these commands to the buttons...it refuses to do the pause or ExitScript...until the number of arrow presses program have completed.
Is there a way to keep the presses going and then just stop them when required? The script is below Thankyou for any help you can give.

Code: Select all

Gui, Add, Button, x12 y30 w100 h30 , Down slow
Gui, Add, Button, x12 y60 w100 h30 , Down fast
Gui, Add, Button, x12 y90 w100 h30 , Up
Gui, Add, Button, x12 y120 w100 h30 , Pause
Gui, Add, Button, x12 y150 w100 h30 , Quit
Gui, Font, S8 cFFFFFF, Arial Bold
Gui, Add, Text, x12 y0 w100 h20 , quick mail check

Gui, Show, w128 h195, mail - check
F9::ExitApp
return

buttondownslow:
Gui, Submit, Nohide

IfWinExist, mailcheck - 3.5.1
    WinActivate mailcheck - 3.5.1
else goto, message

SetKeyDelay, 1000
Send {Down 10}
	
return

buttondownfast:
Gui, Submit, Nohide
IfWinExist, mailcheck - 3.5.1
    WinActivate mailcheck - 3.5.1
SetKeyDelay, 100
send {Down 10}
return

buttonpause:
Gui, Submit, Nohide
pause
return


message:
msgbox no gui
return


buttonquit:
Gui, Submit, Nohide
ExitApp
return


GuiClose:
ExitApp
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Unable to stop the process in the script

20 Jan 2017, 09:12

I have not tested this, but I think this can not be interrupted:

Code: Select all

SetKeyDelay, 1000
Send, {Down 10}
This can be interrupted:

Code: Select all

Loop, 10 {
    Send, {Down}
    Sleep, 1000
}
I hope that helps.
bapiman
Posts: 9
Joined: 20 Jan 2017, 08:10

Re: Unable to stop the process in the script

20 Jan 2017, 09:41

Great - you sort of got me on the right track - very much appreciate that. Only one slight issue if you dont mind helping me a bit further.
I am using Notepad.exe as the test application in which the up and down arrow keys will work.

The up and down etc all works fine and can be paused using the F9 key. However, say I have clicked "down fast" on the Gui control - this then correctly activates notepad window and starts to hit the "down" arrow key...if I then click the "pause" on the Gui...and then click the "down fast" again on the Gui - it becomes very sporadic - it either does nothing or instead of selecting the Notepad application...it instead starts doing the "down" arrow key Gui itself. Its as if once a button is pressed and the script paused...clicking the same button again does not seem to correctly run the full button command again.

Below is the full code. Appreciate any pointers on this. Thanks

Code: Select all

Gui, Color, 004C99
Gui, Font, S8 cFFFFFF, Arial
Gui, Add, Button, x12 y30 w100 h30 , Down slow
Gui, Add, Button, x12 y60 w100 h30 , Down fast
Gui, Add, Button, x12 y90 w100 h30 , Up
Gui, Add, Button, x12 y120 w100 h30 , Pause
Gui, Add, Button, x12 y150 w100 h30 , Quit
Gui, Font, S8 cFFFFFF, Arial Bold
Gui, Add, Text, x12 y0 w100 h20 , ylpheed Checker
; Generated using SmartGUI Creator for SciTE

Gui, Show, w128 h195, Sylpheed Checker
F9::Pause
return


buttondownslow:
Gui, Submit, Nohide

IfWinExist, Untitled - Notepad
    WinActivate Untitled - Notepad
else goto, message

Loop, 50 {
    Send, {Down}
    Sleep, 1000
}
	
return

buttondownfast:
Gui, Submit, Nohide
IfWinExist, Untitled - Notepad
    WinActivate Untitled - Notepad
else goto, message
Loop, 50 {
    Send, {Down}
    Sleep, 100
}
return


buttonup:
Gui, Submit, Nohide
IfWinExist, Untitled - Notepad
    WinActivate Untitled - Notepad
else goto, message
Loop, 50 {
    Send, {Up}
    Sleep, 100
}
return


buttonpause:
Gui, Submit, Nohide
pause
return



message:
msgbox no gui
return



buttonquit:
Gui, Submit, Nohide
ExitApp
return


GuiClose:
ExitApp
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Unable to stop the process in the script

20 Jan 2017, 10:33

I'm not so sure, if I miss the point here, but I think there is a problem with using "Pause" when you want a loop to interrupt.
The Pause will not interrupt the Loop, it just pauses the execution while "Pause is in effect". I see the icon in the taskbar change, when it does that.
All "outside" user interaction such as activate the GUI again, then unpausing, is not dealt with in your code presently.
I strongly suggest to react to F9 by completely breaking out of the Loop:

Code: Select all

F9:: bInterrupt := ! bInterrupt
...
Loop, 50 {
    If (bInterrupt = True)
        Break ; no more iterations after this
    Send, {Down}
    Sleep, 1000
}
bInterrupt := False
I see some problems can still be caused by the user, If he chooses to repeatedly press F9, but one thing at a time. The script won't actually break immediately the Loop, only when it checks to see if the Interrupt flag has been set, which is 1000 ms delayed at most. Maybe the typical user of this script is prone to impatience, maybe not.
I hope that helps you a bit further.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Unable to stop the process in the script

20 Jan 2017, 10:51

Better yet is this:

Code: Select all

F9:: bInterrupt := True
bapiman
Posts: 9
Joined: 20 Jan 2017, 08:10

Re: Unable to stop the process in the script

20 Jan 2017, 11:25

The F9:: pause works fine.
However - running the pause command from the Gui button causes issues. It pauses fine when pressing the Gui Button - but when clicking another button to continue with the script - strange things happen. Like the script refuses to focus on the specified app and the commands run on its own gui - or it stops functioning altogether. Thanks for all your inputs
bapiman
Posts: 9
Joined: 20 Jan 2017, 08:10

Re: Unable to stop the process in the script

30 Jan 2017, 07:35

Just an update on this...if anyone is still able to help...please do since I am still perplexed with this issue.
What I have done now is to recreate the above GUI and have a single button which presses the DOWN arrow key an X number of times. Pressing F9 pauses this...and pressing F9 again continues the process.

The problem is...if was to create another GUI button which upon clicking hits the UP arrow key...and then pause the DOWN Arrow key script and then click the gui button to run the UP arrow key script, this would work fine...BUT I cannot the script to get the DOWN arrow to work again unless I closed the whole GUI and re-launch. Going back to DOWN arrow key button in the GUI does not seem to be an option since nothing then happens.

Appreciate any advice on this.
Many thanks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, Google [Bot] and 133 guests