-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgameio.py
More file actions
53 lines (36 loc) · 1.26 KB
/
gameio.py
File metadata and controls
53 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
"""Module to interact with the game."""
import platform
from abc import ABC, abstractmethod
import pyautogui
PLATFORM_SYS = platform.system()
class AbstractGameIO(ABC):
"""Base class for each platform."""
@abstractmethod
def __init__(self):
"""Initializes components needed for the I/O to operate."""
self.loc = pyautogui.locateOnScreen("images/app.png")
@abstractmethod
def fetch_sshot(self):
"""Creates a screenshot, and returns it in Pillow format."""
pass
# feel free to change these two functions in the descendants
def key_up(self, key: str):
"""Holds a key on a virtual keyboard."""
pyautogui.keyUp(key)
def key_down(self, key: str):
"""Lets go of a key on a virtual keyboard."""
pyautogui.keyDown(key)
def send_key(self, key: str):
"""Presses a key on a virtual keyboard."""
pyautogui.press(key)
class WindowsGameIO(AbstractGameIO):
def __init__(self):
super().__init__()
def fetch_sshot(self):
return pyautogui.screenshot(region=self.loc)
class LinuxGameIO(AbstractGameIO):
def __init__(self):
super().__init__()
def fetch_sshot(self):
return pyautogui.screenshot(region=self.loc)