35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from abc import ABC, abstractmethod
|
|
from fabric import Connection
|
|
|
|
from .xdotool import XDoToolController
|
|
from .python import PythonController
|
|
|
|
class AbstractKeyboardController(ABC):
|
|
@abstractmethod
|
|
def type(self, text: str):
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
def key(self, key: str):
|
|
raise NotImplementedError
|
|
|
|
class XDoToolKeyboardController(AbstractKeyboardController, XDoToolController):
|
|
def __init__(self, ssh_connection: Connection):
|
|
super().__init__(ssh_connection=ssh_connection)
|
|
|
|
def type(self, text: str):
|
|
self._execute_xdotool_command(f"type {text}")
|
|
|
|
def key(self, key: str):
|
|
self._execute_xdotool_command(f"key {key}")
|
|
|
|
class PythonKeyboardController(AbstractKeyboardController, PythonController):
|
|
def __init__(self, http_server: str):
|
|
super().__init__(http_server=http_server)
|
|
self.command = "python -c \"import keyboard; {command}\""
|
|
|
|
def type(self, text: str):
|
|
self._execute_python_command(self.command.format(command=f"keyboard.write('{text}')"))
|
|
|
|
def key(self, key: str):
|
|
self._execute_python_command(self.command.format(command=f"keyboard.press_and_release('{key}')")) |