You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
The Controller().type() function is very useful to easily type out long strings.
However, some web interfaces are too slow to capture the key presses because the key is released directly after being pressed [1]. I will be using duration to refer to the time a key is pressed and delay to refer to the time between two consecutive keys being pressed.
There is already a pull request to add a delay between key presses in #579 , but it does not include duration. As mentioned in [2], the xdotool utility provides the --delay option to set how long the key press should last [3][4], but the time is apparently split 50-50 between duration and delay.
I would propose to add both parameters to Controller().type() as described in [2], but keep the current default of no duration or delay by default.
deftype(self, string, duration=0.0, delay=0.0):
"""Types a string. This method will send all key presses and releases necessary to type all characters in the string. :param str string: The string to type. :param duration float: Key press duration in seconds. :param delay float: Time between two key presses in seconds. :raises InvalidCharacterException: if an untypable character is encountered """from . import_CONTROL_CODESfromtimeimportsleepfori, characterinenumerate(string):
key=_CONTROL_CODES.get(character, character)
try:
self.press(key)
ifduration>0.0: # prevent context switch if duration is 0sleep(duration)
self.release(key)
ifdelay>0.0:
sleep(delay)
except (ValueError, self.InvalidKeyException):
raiseself.InvalidCharacterException(i, character)
Description
The
Controller().type()
function is very useful to easily type out long strings.However, some web interfaces are too slow to capture the key presses because the key is released directly after being pressed [1]. I will be using
duration
to refer to the time a key is pressed anddelay
to refer to the time between two consecutive keys being pressed.There is already a pull request to add a
delay
between key presses in #579 , but it does not includeduration
. As mentioned in [2], thexdotool
utility provides the--delay
option to set how long the key press should last [3][4], but the time is apparently split 50-50 betweenduration
anddelay
.I would propose to add both parameters to
Controller().type()
as described in [2], but keep the current default of noduration
ordelay
by default.[1] https://github.com/moses-palmer/pynput/blob/6d01a92d2e4ef10be57af6ef7ce720f04f8b5652/lib/pynput/keyboard/_base.py#L488C1-L492C34
[2] Evidlo/passhole#64
[3] https://askubuntu.com/questions/1098762/does-xdotool-key-delay-pause-for-specified-delay-between-typing-every-two-co
[4] jordansissel/xdotool#423
The text was updated successfully, but these errors were encountered: