Jump to content

Emergency Halt Button


nago
 Share

Recommended Posts

Hi, I'm having some problems with the GUI modes conceptually. My goal is to have a small Gui frontend for a script which:

A) Has a start button,

B) Has a stop button,

C) Has an exit button.

D) Has a few settings fields, Apply/Save button (ETC).

The "Start" button will start a long macro: A long series of keypresses, sleeps, WinWaitActive() functions, etcetera.

The "Stop" button should stop the aforementioned function at any time.

The "Exit" button -- the default window's "X", should close the gui and halt the script instantly at any time.

The problem is, once the macro function has been started, the gui is no longer responsive... In either GUI mode. In the event mode, once one event has been triggered, none of the other buttons respond. Or, in the default mode, (with the case $button layout) the function with the macro sequence in it still prevents it from paying any attention from the gui, so.

I'm at a loss for how to design something like this.

I was considering actually putting this macro into its own .exe and calling it with Run(), but then there are issues of how to update the settings fields and variables and whatnot between the spawned script and the main settings window, etc.

Any tips?

Edited by nago
Link to comment
Share on other sites

What is happening is that your "macro" is a event so when it's executed any other events are queued. To solve that easily move your "macro" to the mainloop.

See this (rather messy) example for OnEventMode:

(run from SciTe and watch the console when you press the buttons)

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

Global $xyz = False

GUICreate("Test")
$start = GUICtrlCreateButton("start", 10, 10)
GUICtrlSetOnEvent(-1, "_start")
$stop = GUICtrlCreateButton("stop", 10, 50)
GUICtrlSetOnEvent(-1, "_stop")

GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")

While 1
    If $xyz = True Then _SomeFunc()
    Sleep(10)
WEnd

Func _SomeFunc()
    While 1
        If $xyz = False Then Return
        ConsoleWrite(Random() & @CRLF)
        Sleep(10)
    WEnd
EndFunc

Func _start()
    $xyz = True
EndFunc

Func _stop()
    $xyz = False
EndFunc

Func _quit()
    Exit
EndFunc
Edited by AdmiralAlkex
Link to comment
Share on other sites

The HotKeySet() Is a good suggestion, though I am dead-set on using a stop button instead of a hotkey, if only for ease of use. I have always considered hotkeys, with regards to user interfaces, as secondary interfaces.

As for the third reply, I will investigate this more deeply: I am not sure I understand what you mean just yet, so let me look into your example and digest it.

Edit: OK, I see. I will still have to work the "Stop" functionality into my "Macro Function", however: the Exit button should at least now work with no further modifications. This is a good vector in which to solve this problem, I'll work on a version using your method. Very clever.

In the meantime, any other suggestions are still welcome.

For an example of my "Macro Function", it's something akin to the following:

Func Macro
  WaitWinActive("Game Window")
  Sleep(200)
  Send('{ENTER}')
  sleep(20)
  Send('{ENTER}')
  sleep(20)
  Send('{DOWN}')
  sleep(30)
  ...
EndFunc

Etcetera. There are a lot of loops and various WinWaitActive()s in there, but the "main loop" of the macro function takes about two and a half minutes to complete.

Second Edit: Since I'm only using Send() and Sleep() and WinWaitActive() in the 'Macro Function', I think what I can do to achieve an "instantaneous stop", is write a custom wrapper for each function, like _MacroSend(), _MacroSleep() and _MacroWinWaitActive(), and in those wrappers, just have a simple if/then, such as:

If Not $STOP Then
  (Pass Arguments on to Proper Function)

And so if "STOP" is pressed, all functions cease doing any actual work, achieving an emergency halt.

Sound logic?

Edited by nago
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...