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.
This commit is contained in:
Martysh12 2021-12-19 21:33:57 +02:00
parent 1a1e8efef8
commit d04a0b172c
1 changed files with 23 additions and 5 deletions

View File

@ -25,10 +25,22 @@ class AbstractGameIO(ABC):
"""Creates a screenshot, and returns it in Pillow format.""" """Creates a screenshot, and returns it in Pillow format."""
pass pass
# TODO: Implement the following two functions in descendants.
@abstractmethod @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): def send_key(self, key: str):
"""Presses a key on a virtual keyboard.""" """Presses a key on a virtual keyboard."""
pass self.key_up(key)
self.key_down(key)
class WindowsGameIO(AbstractGameIO): class WindowsGameIO(AbstractGameIO):
@ -39,8 +51,11 @@ class WindowsGameIO(AbstractGameIO):
def fetch_sshot(self): def fetch_sshot(self):
return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h) return self.d.screenshot() # TODO: Cut this to self.loc(x, y, w, h)
def send_key(self, key: str): def key_up(self, key: str):
pass # TODO: Add send_key method pass
def key_up(self, key: str):
pass
class LinuxGameIO(AbstractGameIO): class LinuxGameIO(AbstractGameIO):
@ -52,5 +67,8 @@ class LinuxGameIO(AbstractGameIO):
def fetch_sshot(self): def fetch_sshot(self):
return pyautogui.screenshot(region=self.loc) return pyautogui.screenshot(region=self.loc)
def send_key(self, key: str): def key_up(self, key: str):
pass # TODO: Add send_key method pass
def key_up(self, key: str):
pass