diff --git a/emunium/base.py b/emunium/base.py index f7c8f2f..e3fd6b6 100644 --- a/emunium/base.py +++ b/emunium/base.py @@ -6,7 +6,11 @@ import time import struct -import keyboard +try: + import keyboard +except ImportError: + keyboard = None + import pyautogui import pyclick @@ -118,22 +122,17 @@ def silent_type(self, text, characters_per_minute=280, offset=20): randomized_offset = random.uniform(-offset, offset) / 1000 delay = time_per_char + randomized_offset - keyboard.write(char) - time.sleep(delay) - - # Update by Pranav (https://github.com/ps428) - # keyboard.write used in silent_type needs sudo mode on Linux machines - # This uses pyautogui.press instead of keyboard.write - def silent_type_pyautogui(self, text, characters_per_minute=280, offset=20): - time_per_char = 60 / characters_per_minute - - for i, char in enumerate(text): - randomized_offset = random.uniform(-offset, offset) / 1000 - delay = time_per_char + randomized_offset + # Update by Pranav (https://github.com/ps428) + # keyboard.write used in silent_type needs sudo mode on Linux machines + # This uses pyautogui.press instead of keyboard.write + if keyboard is None: + pyautogui.press(char) + else: + keyboard.write(char) - pyautogui.press(char) time.sleep(delay) + def _scroll_smoothly_to_element(self, element_rect): window_width = self.browser_inner_window[0] window_height = self.browser_inner_window[1] diff --git a/setup.py b/setup.py index c48a19f..7969450 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='emunium', - version='2.0.0', + version='2.0.1', author='Maehdakvan', author_email='visitanimation@google.com', description='A Python module for automating interactions to mimic human behavior in standalone apps or browsers when using Selenium, Pyppeteer, or Playwright.',