From d04a0b172c6d6785c5e239d6d107358afa0eb4e0 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Sun, 19 Dec 2021 21:33:57 +0200 Subject: [PATCH] Add key_up and key_down methods in GameIO Add key_up() and key_down() methods in GameIO. key_press() does the aforementioned two functions one after the other. --- gameio.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/gameio.py b/gameio.py index 7368aab..0ac2584 100644 --- a/gameio.py +++ b/gameio.py @@ -25,10 +25,22 @@ class AbstractGameIO(ABC): """Creates a screenshot, and returns it in Pillow format.""" pass + # TODO: Implement the following two functions in descendants. + @abstractmethod + def key_up(self, key: str): + """Holds a key on a virtual keyboard.""" + pass + + @abstractmethod + def key_up(self, key: str): + """Lets go of a key on a virtual keyboard.""" + pass + def send_key(self, key: str): """Presses a key on a virtual keyboard.""" - pass + self.key_up(key) + self.key_down(key) class WindowsGameIO(AbstractGameIO): @@ -39,8 +51,11 @@ class WindowsGameIO(AbstractGameIO): def fetch_sshot(self): return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h) - def send_key(self, key: str): - pass # TODO: Add send_key method + def key_up(self, key: str): + pass + + def key_up(self, key: str): + pass class LinuxGameIO(AbstractGameIO): @@ -52,5 +67,8 @@ class LinuxGameIO(AbstractGameIO): def fetch_sshot(self): return pyautogui.screenshot(region=self.loc) - def send_key(self, key: str): - pass # TODO: Add send_key method + def key_up(self, key: str): + pass + + def key_up(self, key: str): + pass