From 05c29e7e7243d49f37cc916c8384d63d0f9666c6 Mon Sep 17 00:00:00 2001 From: Martysh12 <49569238+Martysh12@users.noreply.github.com> Date: Mon, 20 Dec 2021 16:12:34 +0200 Subject: [PATCH] Implemented key_up and key_down methods Implemented key_up and key_down methods in GameIO --- gameio.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/gameio.py b/gameio.py index b1fad9e..c18a035 100644 --- a/gameio.py +++ b/gameio.py @@ -25,17 +25,17 @@ class AbstractGameIO(ABC): """Creates a screenshot, and returns it in Pillow format.""" pass - # TODO: Implement the following two functions in descendants. + # feel free to change these two functions in the descendants @abstractmethod def key_up(self, key: str): """Holds a key on a virtual keyboard.""" - pass + pyautogui.keyUp(key) @abstractmethod def key_down(self, key: str): """Lets go of a key on a virtual keyboard.""" - pass + pyautogui.keyDown(key) def send_key(self, key: str): """Presses a key on a virtual keyboard.""" @@ -52,10 +52,10 @@ class WindowsGameIO(AbstractGameIO): return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h) def key_up(self, key: str): - pass + pyautogui.keyUp(key) def key_down(self, key: str): - pass + pyautogui.keyDown(key) class LinuxGameIO(AbstractGameIO): @@ -64,9 +64,3 @@ class LinuxGameIO(AbstractGameIO): def fetch_sshot(self): return pyautogui.screenshot(region=self.loc) - - def key_up(self, key: str): - pass - - def key_down(self, key: str): - pass