| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
from . import interaction |
| 18 |
from .input_device import InputDevice |
| 19 |
from .interaction import Interaction |
| 20 |
from .interaction import Pause |
| 21 |
|
| 22 |
|
| 23 |
class KeyInput(InputDevice): |
| 24 |
def __init__(self, name: str) -> None: |
| 25 |
super().__init__() |
| 26 |
self.name = name |
| 27 |
self.type = interaction.KEY |
| 28 |
|
| 29 |
def encode(self) -> dict: |
| 30 |
return {"type": self.type, "id": self.name, "actions": [acts.encode() for acts in self.actions]} |
| 31 |
|
| 32 |
def create_key_down(self, key) -> None: |
| 33 |
self.add_action(TypingInteraction(self, "keyDown", key)) |
| 34 |
|
| 35 |
def create_key_up(self, key) -> None: |
| 36 |
self.add_action(TypingInteraction(self, "keyUp", key)) |
| 37 |
|
| 38 |
def create_pause(self, pause_duration: float = 0) -> None: |
| 39 |
self.add_action(Pause(self, pause_duration)) |
| 40 |
|
| 41 |
|
| 42 |
class TypingInteraction(Interaction): |
| 43 |
def __init__(self, source, type_, key) -> None: |
| 44 |
super().__init__(source) |
| 45 |
self.type = type_ |
| 46 |
self.key = key |
| 47 |
|
| 48 |
def encode(self) -> dict: |
| 49 |
return {"type": self.type, "value": self.key} |