add counter function

This commit is contained in:
2026-04-21 19:39:22 +02:00
parent 6f44817a1f
commit d7d32744e9
+14 -3
View File
@@ -21,7 +21,7 @@ from .command import Command
class Window: class Window:
__AUTHOR__ = 'anima' __AUTHOR__ = 'anima'
__VERSION__ = '1.1.6' __VERSION__ = '1.2.0'
key_press_duration = 0.1 key_press_duration = 0.1
supported_keys = ['return', 'Up', 'Down', 'Right', 'Left'] supported_keys = ['return', 'Up', 'Down', 'Right', 'Left']
@@ -45,14 +45,18 @@ class Window:
self.dry_run = False self.dry_run = False
def run(self): def run(self) -> bool:
"""main loop to screenshot given monitor and match with screens
Returns:
bool: True if a clean fin
"""
if not len(self.commands) > 0: if not len(self.commands) > 0:
logging.error(f'no commands to run found') logging.error(f'no commands to run found')
sys.exit(1) sys.exit(1)
with mss.mss() as self.sct: with mss.mss() as self.sct:
while True: while True:
command = self.match_screen() command = self.match_screen()
# print(self.match_screen())
if command: if command:
self.activate_window() self.activate_window()
for key in command.commands: for key in command.commands:
@@ -60,7 +64,14 @@ class Window:
self.send_key(key) self.send_key(key)
elif isinstance(key, int) or isinstance(key, float): elif isinstance(key, int) or isinstance(key, float):
time.sleep(key) time.sleep(key)
command.count += 1
if isinstance(command.counter, int):
logging.info(f'{command.name} counter: {command.count} / {command.counter}')
if command.count >= command.counter:
logging.info(f'{command.name} hast reach counter limit. stop script')
return True
time.sleep(self.poll_intervall) time.sleep(self.poll_intervall)
return False
## Screen Managament ## Screen Managament
def grab_screen(self) -> numpy.ndarray: def grab_screen(self) -> numpy.ndarray: