| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
from __future__ import annotations |
| 18 |
|
| 19 |
from ..utils import keys_to_typing |
| 20 |
from .interaction import KEY |
| 21 |
from .interaction import Interaction |
| 22 |
from .key_input import KeyInput |
| 23 |
from .pointer_input import PointerInput |
| 24 |
from .wheel_input import WheelInput |
| 25 |
|
| 26 |
|
| 27 |
class KeyActions(Interaction): |
| 28 |
def __init__(self, source: KeyInput | PointerInput | WheelInput | None = None) -> None: |
| 29 |
if not source: |
| 30 |
source = KeyInput(KEY) |
| 31 |
self.source = source |
| 32 |
super().__init__(source) |
| 33 |
|
| 34 |
def key_down(self, letter: str) -> KeyActions: |
| 35 |
return self._key_action("create_key_down", letter) |
| 36 |
|
| 37 |
def key_up(self, letter: str) -> KeyActions: |
| 38 |
return self._key_action("create_key_up", letter) |
| 39 |
|
| 40 |
def pause(self, duration: int = 0) -> KeyActions: |
| 41 |
return self._key_action("create_pause", duration) |
| 42 |
|
| 43 |
def send_keys(self, text: str | list) -> KeyActions: |
| 44 |
if not isinstance(text, list): |
| 45 |
text = keys_to_typing(text) |
| 46 |
for letter in text: |
| 47 |
self.key_down(letter) |
| 48 |
self.key_up(letter) |
| 49 |
return self |
| 50 |
|
| 51 |
def _key_action(self, action: str, letter) -> KeyActions: |
| 52 |
meth = getattr(self.source, action) |
| 53 |
meth(letter) |
| 54 |
return self |