Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop slowtypemethod #596

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/autokey/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def __sendString(self, string, type_delay=0):
logger.warning("Unable to send character %r", char)
logger.info("Type delay of "+str(type_delay))
if type_delay >= 0:
self.localDisplay.flush()
self.flush()
time.sleep(type_delay)
except Exception as e:
logger.exception("Error sending char %r: %s", char, str(e))
Expand Down
2 changes: 1 addition & 1 deletion lib/autokey/model/phrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_serializable(self):
"hotkey": AbstractHotkey.get_serializable(self),
"filter": AbstractWindowFilter.get_serializable(self),
"sendMode": self.sendMode.value,
"type_delay": self.type_delay
"type_delay": self.type_delay,
}
return d

Expand Down
6 changes: 5 additions & 1 deletion lib/autokey/scripting/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def create_phrase(self, folder, name: str, contents: str,
hotkey: Tuple[List[Union[Key, str]], Union[Key, str]]=None,
send_mode: autokey.model.phrase.SendMode = autokey.model.phrase.SendMode.CB_CTRL_V, window_filter: str=None,
show_in_system_tray: bool=False, always_prompt: bool=False,
temporary=False, replace_existing_hotkey=False):
temporary=False, replace_existing_hotkey=False,
type_delay=0):
"""
Create a new text phrase inside the given folder. Use C{engine.get_folder(folder_name)} to retrieve the folder
you wish to create the Phrase in. If the folder is a temporary
Expand Down Expand Up @@ -217,6 +218,7 @@ def create_phrase(self, folder, name: str, contents: str,
@param replace_existing_hotkey: If true, instead of warning if the hotkey
is already in use by another phrase or folder, it removes the hotkey
from those clashes and keeps this phrase's hotkey.
@param type_delay:
@raise ValueError: If a given abbreviation or hotkey is already in use or parameters are otherwise invalid
@return The created Phrase object. This object is NOT considered part of the public API and exposes the raw
internals of AutoKey. Ignore it, if you don’t need it or don’t know what to do with it.
Expand Down Expand Up @@ -262,6 +264,8 @@ def create_phrase(self, folder, name: str, contents: str,
# reloads.
if not temporary:
p.persist()

p.type_delay = type_delay
return p
finally:
self.monitor.unsuspend()
Expand Down
17 changes: 16 additions & 1 deletion lib/autokey/scripting/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def __init__(self, mediator):
self.mediator = mediator # type: iomediator.IoMediator
"""See C{IoMediator} documentation"""

def slow_type(self, key_string, type_delay):
"""
Sends a sequence of keys via keyboard events with a delay between each key.

@param key_string: string of keys to send.
@param type_delay: Delay between each key event being sent (uses python's time.sleep)
"""
if not isinstance(key_string, str):
raise TypeError("Only strings can be sent using this function")
self.mediator.interface.begin_send()
try:
self.mediator.send_string(key_string, type_delay)
finally:
self.mediator.interface.finish_send()

def send_keys(self, key_string, send_mode: typing.Union[
autokey.model.phrase.SendMode, int] = autokey.model.phrase.SendMode.KEYBOARD):
"""
Expand All @@ -45,7 +60,7 @@ def send_keys(self, key_string, send_mode: typing.Union[

Usage: C{keyboard.send_keys(keyString)}

@param key_string: string of keys to send. Special keys are only possible in keyboard mode.
@param key_string:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What reasoning for removing this docstring?

@param send_mode: Determines how the string is sent.
"""

Expand Down