Jump to content

[Query] Stop script execution if target not "active"


Tobei
 Share

Recommended Posts

I'm trying to get my script to stop all execution (especially hotkeys) when the script's target window is not active.

I have WinWaitActive("<target window>") just before the first hotkeys are setup and the main loop begins.

This works fine for splash screen and other processes that should be run before the main loop beings,

but this doesn't seem to pause the script when the user leaves the target window once the main loop starts...

---

The only workable solution I can think of would be to call a function at the beginning of the main loop that:

1) check if the window is active

2) if it is not, remove all hotkeys according to current "state" (or menu) the user was in, and set new "state"

3) if it is, and the current "state" is the "window not active" "state" then restore "state" user was in,

including hotkeys, etc.

4) if it is, and the current "state" is not the "window not active" "state" then return.

---

I could probably write that function without any trouble, but then i'd have to rework my entire menu system throughout my script to facilitate the change...

Is there an easier way?

Thanks,

Tobei.

Link to comment
Share on other sites

I'm trying to get my script to stop all execution (especially hotkeys) when the script's target window is not active.

I have WinWaitActive("<target window>") just before the first hotkeys are setup and the main loop begins.

This works fine for splash screen and other processes that should be run before the main loop beings,

but this doesn't seem to pause the script when the user leaves the target window once the main loop starts...

---

The only workable solution I can think of would be to call a function at the beginning of the main loop that:

1) check if the window is active

2) if it is not, remove all hotkeys according to current "state" (or menu) the user was in, and set new "state"

3) if it is, and the current "state" is the "window not active" "state" then restore "state" user was in,

including hotkeys, etc.

4) if it is, and the current "state" is not the "window not active" "state" then return.

---

I could probably write that function without any trouble, but then i'd have to rework my entire menu system throughout my script to facilitate the change...

Is there an easier way?

Thanks,

Tobei.

you basically wrote the function...

maybe more like this

If Not WinActivate("win name") Then
    HotKeySet("{F1}"); nothing
; other keys...etc
    HotKeySet("{F1}", "new_state"); new state
ElseIf WinActive("win name","") Then
;do something
Else
    WinSetState("win name", "", "state")
; do something
EndIf

needs your input to work

8)

NEWHeader1.png

Link to comment
Share on other sites

Thought I'd share the peice of code that accomplished this.

(Extracted from my Dofus Companion Webpage )

;Main loop.
While 1
    While WinActive( "Dofus")
        If getstate () = $state_sleep Then setstate ($state_mainmenu)
        Sleep(1000)
    WEnd
    If getstate () <> $state_sleep Then setstate ($state_sleep)
    If getstate () = $state_sleep Then Sleep(1000)
WEnd

So:

While "Dofus" is running and in the foreground the script functions normally with the state in mainmenu

While "Dofus" is not running or is not in the forground the script functions normally with state in sleep.

sleep mode: only active hotkey is the one to quit.

-----

Thought maybe this would help somebody out.

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...