diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index d57cea2..d3d5107 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -22,7 +22,7 @@ from fishy.engine.common.IEngine import IEngine from pynput import keyboard, mouse from fishy.helper import hotkey, helper -from fishy.helper.helper import sign, log_raise +from fishy.helper.helper import sign, log_raise, wait_until, is_eso_active from fishy.helper.config import config mse = mouse.Controller() @@ -74,6 +74,12 @@ class FullAuto(IEngine): elif FullAutoMode(config.get("full_auto_mode", 0)) == FullAutoMode.Recorder: self.mode = Recorder(self) + if not is_eso_active(): + logging.info("Waiting for eso window to be active...") + wait_until(is_eso_active) + logging.info("starting in 2 secs...") + time.sleep(2) + # noinspection PyBroadException try: if self.window.get_capture() is None: @@ -90,6 +96,7 @@ class FullAuto(IEngine): fishing_event.unsubscribe() if self.show_crop: self.start_show() + self.stop_on_inactive() self.mode.run() @@ -109,6 +116,12 @@ class FullAuto(IEngine): self.window.show(self.show_crop, func=image_pre_process) Thread(target=func).start() + def stop_on_inactive(self): + def func(): + wait_until(lambda: not is_eso_active()) + self.start = False + Thread(target=func).start() + def get_coods(self): img = self.window.processed_image(func=image_pre_process) return get_values_from_image(img) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index 895d566..2158d90 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -19,6 +19,8 @@ from fishy.helper.config import config import random +from fishy.helper.helper import is_eso_active + class FishEvent: fishCaught = 0 @@ -46,7 +48,7 @@ def _fishing_sleep(waittime, lower_limit_ms = 16, upper_limit_ms = 2500): def if_eso_is_focused(func): def wrapper(): - if GetWindowText(GetForegroundWindow()) != "Elder Scrolls Online": + if not is_eso_active(): logging.warning("ESO window is not focused") return func() diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index 55af70a..697c9c5 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -17,6 +17,7 @@ from hashlib import md5 from win32com.client import Dispatch from win32comext.shell import shell, shellcon +from win32gui import GetForegroundWindow, GetWindowText import fishy import winshell @@ -215,6 +216,10 @@ def update(): restart() +def is_eso_active(): + return GetWindowText(GetForegroundWindow()) == "Elder Scrolls Online" + + # noinspection PyProtectedMember,PyUnresolvedReferences def _get_id(thread): # returns id of the respective thread