30 lines
978 B
Python
30 lines
978 B
Python
import pyautogui
|
|
from objects.inputs import MouseInput, KeyboardInput, ButtonType
|
|
|
|
def press_mouse(mouse_input: MouseInput) -> None:
|
|
"""Presses mouse buttons at the given position."""
|
|
x, y = mouse_input.x, mouse_input.y
|
|
button = mouse_input.click_type
|
|
if button == "left":
|
|
pyautogui.click(x, y, button='left')
|
|
elif button == "double_left":
|
|
pyautogui.doubleClick(x, y)
|
|
elif button == "right":
|
|
pyautogui.click(x, y, button='right')
|
|
elif button == "middle":
|
|
pyautogui.click(x, y, button='middle')
|
|
|
|
def press_keyboard(keyboard_input: KeyboardInput) -> None:
|
|
"""Types the given sequence of keys."""
|
|
text = keyboard_input.text
|
|
if text:
|
|
pyautogui.typewrite(text)
|
|
if keyboard_input.press_enter:
|
|
pyautogui.press('enter')
|
|
|
|
def _execute(name, args):
|
|
if name == "click_button":
|
|
press_mouse(MouseInput(**args))
|
|
elif name == "type_text":
|
|
press_keyboard(KeyboardInput(**args))
|