Skip to content

Commit 717e05c

Browse files
committed
Added delay parameter to write method
1 parent 9ec404f commit 717e05c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

adafruit_hid/keyboard_layout_base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
except ImportError:
1717
pass
1818

19+
from time import sleep
1920

2021
__version__ = "0.0.0+auto.0"
2122
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HID.git"
@@ -88,10 +89,11 @@ def _write(self, keycode: int, altgr: bool = False) -> None:
8889
self.keyboard.press(keycode)
8990
self.keyboard.release_all()
9091

91-
def write(self, string: str) -> None:
92+
def write(self, string: str, delay: float = None) -> None:
9293
"""Type the string by pressing and releasing keys on my keyboard.
9394
9495
:param string: A string of UTF-8 characters to convert to key presses and send.
96+
:param float delay: Optional delay in seconds between key presses.
9597
:raises ValueError: if any of the characters has no keycode
9698
(such as some control characters).
9799
@@ -122,6 +124,9 @@ def write(self, string: str) -> None:
122124
)
123125
)
124126

127+
if delay is not None:
128+
sleep(delay)
129+
125130
def keycodes(self, char: str) -> Tuple[int, ...]:
126131
"""Return a tuple of keycodes needed to type the given character.
127132

0 commit comments

Comments
 (0)