Merge pull request #28 from SemjonKerner/fix_key_eso_focus

press keyboard keys only when game window is focused
This commit is contained in:
Adam Saudagar 2020-12-27 17:32:33 +05:30 committed by GitHub
commit 020b962fb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ from fishy import web
from fishy.engine.semifisher.fishing_mode import State, FishingMode
from fishy.helper import helper
import keyboard
from win32gui import GetWindowText, GetForegroundWindow
from fishy.helper.config import config
@ -34,6 +35,7 @@ class FishEvent:
uid = None
sound = False
def _fishing_sleep(waittime, lower_limit_ms = 16, upper_limit_ms = 2500):
reaction = 0.0
if FishEvent.jitter and upper_limit_ms > lower_limit_ms:
@ -42,6 +44,13 @@ def _fishing_sleep(waittime, lower_limit_ms = 16, upper_limit_ms = 2500):
time.sleep(max_wait_t)
def _eso_is_focused():
if GetWindowText(GetForegroundWindow()) == "Elder Scrolls Online":
return True
logging.warning("ESO window is not focused")
return False
def init():
subscribe()
FishEvent.jitter = config.get("jitter", False)
@ -77,6 +86,9 @@ def on_hook():
increases the `fishCaught` and `totalFishCaught`, calculates the time it took to catch
presses e to catch the fish
"""
if not _eso_is_focused():
return
FishEvent.fishCaught += 1
FishEvent.totalFishCaught += 1
time_to_hook = time.time() - FishEvent.stickInitTime
@ -97,6 +109,9 @@ def on_look():
"""
presses e to throw the fishing rod
"""
if not _eso_is_focused():
return
keyboard.press_and_release(FishEvent.action_key)