Skip to content

Commit

Permalink
remove verbose; add noise
Browse files Browse the repository at this point in the history
  • Loading branch information
ebonnal committed Nov 30, 2024
1 parent 2fb37f2 commit 25c186e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 6 additions & 1 deletion botable/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@
default=0,
help="in 'play' mode: how many events the first loop will skip, default is 0 event skipped",
)
arg_parser.add_argument("--playback-verbose", required=False, type=bool)
arg_parser.add_argument(
"--playback-noise",
required=False,
type=bool,
help="in 'play' mode: to add noise to the time intervals between events",
)
args = arg_parser.parse_args()

mode = args.mode
Expand Down
13 changes: 7 additions & 6 deletions botable/botable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import deque
from contextlib import suppress
import random
import time
from typing import Deque, Iterable, Iterator, List, Optional, Union, NamedTuple, Tuple
from pynput import keyboard, mouse # type: ignore
Expand Down Expand Up @@ -109,13 +110,13 @@ def play(
rate: float = 1.0,
delay: float = 1.0,
offset: int = 0,
verbose: bool = False,
noise: bool = False,
) -> Iterator[ButtonEvent]:
"""
Waits `delay` and then iterates on `events` to play them,
optionally playing them at a modified speed `rate`,
optionally skipping the first `offset` events,
optionally logging the played events if `verbose`.
optionally adding noise to the time intervals between events (the original interval remains the minimum).
Once `button_events` is exhausted the entire collected set of event will optionally be replayed additional times if `loops` > 1.
Pressing the `exit_key` will terminate the recording.
Pressing the `pause_key` will pause/resume the recording.
Expand Down Expand Up @@ -157,9 +158,6 @@ def on_press(key: keyboard.Key):
while continue_ and paused_at:
time.sleep(0.5)

if verbose:
print(button_event)

if loop_index == 0 and offset > event_index:
continue

Expand All @@ -176,7 +174,10 @@ def on_press(key: keyboard.Key):
else:
evaluated_button = eval(button_event.button)

time.sleep(button_event.seconds_since_last_event / rate)
sleep_duration = button_event.seconds_since_last_event / rate
if noise:
sleep_duration *= (1 + random.betavariate(2, 5) / 2)
time.sleep(sleep_duration)

if button_event.pressed:
ctrl.press(evaluated_button)
Expand Down

0 comments on commit 25c186e

Please sign in to comment.