python-uinput: Add delay before starting to type keys
Kernel/Chrome/ARC takes a while to register the new input device, wait
a little while (200ms), before starting to input characters.
Also take this opportunity to properly capitalize DEFAULT_DELAY
constant.
BUG=chromium:714950,b:62209867
TEST=emerge-${B} -av python-uinput && \
cros deploy --root /usr/local ${IP} python-uinput
sudo python -m uinput.cros_type_keys $'yourpassword\n'
=> no lost keys
Change-Id: I8d5a4e82eed5ee94f4fa031fce5d728932388397
Reviewed-on: https://chromium-review.googlesource.com/486560
Commit-Ready: Daniel Kurtz <djkurtz@chromium.org>
Tested-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Chung-yih Wang <cywang@google.com>
Reviewed-by: Ilja H. Friedel <ihf@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
diff --git a/dev-python/python-uinput/files/cros_keys.py b/dev-python/python-uinput/files/cros_keys.py
index 6b830dc..a6d5489 100644
--- a/dev-python/python-uinput/files/cros_keys.py
+++ b/dev-python/python-uinput/files/cros_keys.py
@@ -10,8 +10,18 @@
import time
import uinput
+
+# Time to wait after uinput device creation, before starting to type. This is
+# needed as kernel/Chrome takes some time to register the new input device.
+#
+# TODO(crbug.com/714950): This is a hack, we should figure out a way to check
+# when kernel/Chrome is ready (monitor udev events?), instead of waiting for
+# an arbitrary amount of time.
+STARTUP_DELAY = 0.2
+
# Default delay between key presses in seconds. 12ms is the xdotool default.
-default_delay = 0.012
+DEFAULT_DELAY = 0.012
+
uinput_device_keyboard = None
@@ -247,6 +257,7 @@
# For DUTs without keyboard attached force load uinput.
subprocess.Popen(['modprobe', 'uinput']).wait()
uinput_device_keyboard = uinput.Device(_CROS_KEYS_ALL)
+ time.sleep(STARTUP_DELAY)
return uinput_device_keyboard
@@ -262,7 +273,7 @@
Wrapper for uinput.emit_combo. Emits sequence of events.
Example: [KEY_LEFTCTRL, KEY_LEFTALT, KEY_F5]
"""
- time.sleep(default_delay)
+ time.sleep(DEFAULT_DELAY)
device.emit_combo(events, syn)
diff --git a/dev-python/python-uinput/python-uinput-0.10.2-r4.ebuild b/dev-python/python-uinput/python-uinput-0.10.2-r5.ebuild
similarity index 100%
rename from dev-python/python-uinput/python-uinput-0.10.2-r4.ebuild
rename to dev-python/python-uinput/python-uinput-0.10.2-r5.ebuild