Inheriting cross-platform keyboard methods (non-abstract)
This commit is contained in:
parent
05c29e7e72
commit
7d07718326
11
gameio.py
11
gameio.py
|
@ -27,20 +27,17 @@ class AbstractGameIO(ABC):
|
||||||
|
|
||||||
# feel free to change these two functions in the descendants
|
# feel free to change these two functions in the descendants
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def key_up(self, key: str):
|
def key_up(self, key: str):
|
||||||
"""Holds a key on a virtual keyboard."""
|
"""Holds a key on a virtual keyboard."""
|
||||||
pyautogui.keyUp(key)
|
pyautogui.keyUp(key)
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def key_down(self, key: str):
|
def key_down(self, key: str):
|
||||||
"""Lets go of a key on a virtual keyboard."""
|
"""Lets go of a key on a virtual keyboard."""
|
||||||
pyautogui.keyDown(key)
|
pyautogui.keyDown(key)
|
||||||
|
|
||||||
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."""
|
||||||
self.key_up(key)
|
pyautogui.press(key)
|
||||||
self.key_down(key)
|
|
||||||
|
|
||||||
|
|
||||||
class WindowsGameIO(AbstractGameIO):
|
class WindowsGameIO(AbstractGameIO):
|
||||||
|
@ -51,12 +48,6 @@ 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 key_up(self, key: str):
|
|
||||||
pyautogui.keyUp(key)
|
|
||||||
|
|
||||||
def key_down(self, key: str):
|
|
||||||
pyautogui.keyDown(key)
|
|
||||||
|
|
||||||
|
|
||||||
class LinuxGameIO(AbstractGameIO):
|
class LinuxGameIO(AbstractGameIO):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Reference in New Issue