-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from quillcraftsman/replayer
Replayer
- Loading branch information
Showing
20 changed files
with
327 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
replay\_wizard.capturing package | ||
================================ | ||
|
||
Submodules | ||
---------- | ||
|
||
replay\_wizard.capturing.capture module | ||
--------------------------------------- | ||
|
||
.. automodule:: replay_wizard.capturing.capture | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
replay\_wizard.capturing.errors module | ||
-------------------------------------- | ||
|
||
.. automodule:: replay_wizard.capturing.errors | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
replay\_wizard.capturing.keyboard module | ||
---------------------------------------- | ||
|
||
.. automodule:: replay_wizard.capturing.keyboard | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: replay_wizard.capturing | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
replay\_wizard.models package | ||
============================= | ||
|
||
Submodules | ||
---------- | ||
|
||
replay\_wizard.models.action module | ||
----------------------------------- | ||
|
||
.. automodule:: replay_wizard.models.action | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
replay\_wizard.models.sequence module | ||
------------------------------------- | ||
|
||
.. automodule:: replay_wizard.models.sequence | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: replay_wizard.models | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
Quickstart | ||
---------- | ||
|
||
.. literalinclude:: ../quickstart/main.py | ||
:pyobject: main | ||
To capture actions | ||
================== | ||
|
||
.. literalinclude:: ../quickstart/capturing.py | ||
:pyobject: capture_actions | ||
|
||
To replay actions | ||
================= | ||
|
||
.. literalinclude:: ../quickstart/replay.py | ||
:pyobject: replay_actions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
""" | ||
Manual run module | ||
""" | ||
from quickstart.main import main | ||
import time | ||
from quickstart.capturing import capture_actions | ||
from quickstart.replay import replay_actions | ||
|
||
if __name__ == '__main__': | ||
main() | ||
capture_actions() | ||
time.sleep(5) | ||
replay_actions() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
""" | ||
|
||
|
||
def main(): | ||
def capture_actions(): | ||
""" | ||
ReplayWizard simple usage | ||
:return: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
Quickstart examples | ||
""" | ||
|
||
|
||
def replay_actions(): | ||
""" | ||
ReplayWizard simple usage | ||
:return: | ||
""" | ||
from replay_wizard.replay import replay # pylint: disable=import-outside-toplevel | ||
|
||
replay('one') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
Replay package | ||
""" | ||
from .core import replay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Replay core module | ||
""" | ||
import json | ||
from replay_wizard.models import Sequence, Action | ||
from .keyboard import push_button | ||
|
||
|
||
def replay(name, extension='sequence'): | ||
""" | ||
Replay sequence from file | ||
:param name: sequence name, without extension | ||
:param extension: sequence file extension | ||
""" | ||
filename = f'{name}.{extension}' | ||
with open(filename, 'r', encoding='utf-8') as f: | ||
sequence_dict = json.load(f) | ||
sequence = Sequence.model_validate(sequence_dict) | ||
replay_sequence(sequence) | ||
|
||
|
||
def replay_action(action: Action): | ||
""" | ||
Replay one Action | ||
""" | ||
push_button(action) | ||
|
||
|
||
def replay_sequence(sequence: Sequence): | ||
""" | ||
Replay sequence | ||
:param sequence: sequence to replay | ||
""" | ||
for action in sequence: | ||
replay_action(action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Keyboard replay functions | ||
""" | ||
import pynput | ||
from pynput.keyboard import Key | ||
from replay_wizard.models import Action | ||
|
||
|
||
def push_button(action: Action): | ||
""" | ||
Push keyboard button | ||
""" | ||
value = action.value | ||
action_type = action.action | ||
try: | ||
value = Key[value] | ||
except KeyError: | ||
pass | ||
keyboard = pynput.keyboard.Controller() | ||
push_function = getattr(keyboard, action_type) | ||
push_function(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "one", "actions": [{"subtype": "keyboard", "value": "m", "action": "press"}, {"subtype": "keyboard", "value": "m", "action": "release"}, {"subtype": "keyboard", "value": "o", "action": "press"}, {"subtype": "keyboard", "value": "o", "action": "release"}, {"subtype": "keyboard", "value": "u", "action": "press"}, {"subtype": "keyboard", "value": "u", "action": "release"}, {"subtype": "keyboard", "value": "r", "action": "press"}, {"subtype": "keyboard", "value": "r", "action": "release"}, {"subtype": "keyboard", "value": "backspace", "action": "press"}, {"subtype": "keyboard", "value": "backspace", "action": "release"}, {"subtype": "keyboard", "value": "s", "action": "press"}, {"subtype": "keyboard", "value": "s", "action": "release"}, {"subtype": "keyboard", "value": "t", "action": "press"}, {"subtype": "keyboard", "value": "h", "action": "press"}, {"subtype": "keyboard", "value": "t", "action": "release"}, {"subtype": "keyboard", "value": "h", "action": "release"}, {"subtype": "keyboard", "value": "i", "action": "press"}, {"subtype": "keyboard", "value": "i", "action": "release"}, {"subtype": "keyboard", "value": "s", "action": "press"}, {"subtype": "keyboard", "value": "space", "action": "press"}, {"subtype": "keyboard", "value": "s", "action": "release"}, {"subtype": "keyboard", "value": "space", "action": "release"}, {"subtype": "keyboard", "value": "i", "action": "press"}, {"subtype": "keyboard", "value": "i", "action": "release"}, {"subtype": "keyboard", "value": "s", "action": "press"}, {"subtype": "keyboard", "value": "space", "action": "press"}, {"subtype": "keyboard", "value": "s", "action": "release"}, {"subtype": "keyboard", "value": "space", "action": "release"}, {"subtype": "keyboard", "value": "t", "action": "press"}, {"subtype": "keyboard", "value": "t", "action": "release"}, {"subtype": "keyboard", "value": "backspace", "action": "press"}, {"subtype": "keyboard", "value": "backspace", "action": "release"}, {"subtype": "keyboard", "value": "r", "action": "press"}, {"subtype": "keyboard", "value": "r", "action": "release"}, {"subtype": "keyboard", "value": "e", "action": "press"}, {"subtype": "keyboard", "value": "e", "action": "release"}, {"subtype": "keyboard", "value": "p", "action": "press"}, {"subtype": "keyboard", "value": "p", "action": "release"}, {"subtype": "keyboard", "value": "l", "action": "press"}, {"subtype": "keyboard", "value": "l", "action": "release"}, {"subtype": "keyboard", "value": "a", "action": "press"}, {"subtype": "keyboard", "value": "a", "action": "release"}, {"subtype": "keyboard", "value": "y", "action": "press"}, {"subtype": "keyboard", "value": "y", "action": "release"}, {"subtype": "keyboard", "value": "enter", "action": "press"}, {"subtype": "keyboard", "value": "enter", "action": "release"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Pytest fixtures | ||
""" | ||
from pytest import fixture | ||
|
||
|
||
class MockKeyboardController: | ||
""" | ||
Mock class for pynput Controller | ||
""" | ||
|
||
action_list = [] | ||
|
||
def press(self, key): | ||
""" | ||
Mocked press method | ||
""" | ||
self.action_list.append(('PRESS', key)) | ||
|
||
def release(self, key): | ||
""" | ||
Mocked release method | ||
""" | ||
self.action_list.append(('RELEASE', key)) | ||
|
||
@classmethod | ||
def clear(cls): | ||
""" | ||
Clear action lint after testing | ||
Because it's class property | ||
""" | ||
cls.action_list.clear() | ||
|
||
|
||
@fixture | ||
def mocked_keyboard_controller(): | ||
""" | ||
Mock keyboard kontroller from pynput | ||
""" | ||
return MockKeyboardController |
Oops, something went wrong.