Merge branch 'fix_key_eso_focus'

This commit is contained in:
Adam Saudagar 2020-12-27 19:45:14 +05:30
commit 3a6f29b642

View File

@ -19,6 +19,7 @@ from fishy.helper.config import config
import random import random
class FishEvent: class FishEvent:
fishCaught = 0 fishCaught = 0
totalFishCaught = 0 totalFishCaught = 0
@ -44,11 +45,13 @@ def _fishing_sleep(waittime, lower_limit_ms = 16, upper_limit_ms = 2500):
time.sleep(max_wait_t) time.sleep(max_wait_t)
def _eso_is_focused(): def if_eso_is_focused(func):
if GetWindowText(GetForegroundWindow()) == "Elder Scrolls Online": def wrapper():
return True if GetWindowText(GetForegroundWindow()) != "Elder Scrolls Online":
logging.warning("ESO window is not focused") logging.warning("ESO window is not focused")
return False return
func()
return wrapper
def init(): def init():
@ -80,14 +83,13 @@ def fisher_callback(event: State):
FishEvent.previousState = event FishEvent.previousState = event
@if_eso_is_focused
def on_hook(): def on_hook():
""" """
called when the fish hook is detected called when the fish hook is detected
increases the `fishCaught` and `totalFishCaught`, calculates the time it took to catch increases the `fishCaught` and `totalFishCaught`, calculates the time it took to catch
presses e to catch the fish presses e to catch the fish
""" """
if not _eso_is_focused():
return
FishEvent.fishCaught += 1 FishEvent.fishCaught += 1
FishEvent.totalFishCaught += 1 FishEvent.totalFishCaught += 1
@ -105,13 +107,11 @@ def on_hook():
_fishing_sleep(0.0) _fishing_sleep(0.0)
@if_eso_is_focused
def on_look(): def on_look():
""" """
presses e to throw the fishing rod presses e to throw the fishing rod
""" """
if not _eso_is_focused():
return
keyboard.press_and_release(FishEvent.action_key) keyboard.press_and_release(FishEvent.action_key)