Index: telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py |
diff --git a/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py b/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py |
index 022bd291bac5a1972e6d9b16b393adba237f0e01..ab27d535f3c3690f0cada0d5ca1d208d005f6827 100644 |
--- a/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py |
+++ b/telemetry/telemetry/internal/backends/chrome_inspector/inspector_backend.py |
@@ -275,6 +275,75 @@ class InspectorBackend(object): |
} |
return self._runtime.RunInspectorCommand(scroll_command, timeout) |
+ @_HandleInspectorWebSocketExceptions |
+ def DispatchKeyEvent(self, keyEventType='char', modifiers=None, |
+ timestamp=None, text=None, unmodifiedText=None, |
+ keyIdentifier=None, domCode=None, domKey=None, |
+ windowsVirtualKeyCode=None, nativeVirtualKeyCode=None, |
+ autoRepeat=None, isKeypad=None, isSystemKey=None, |
+ timeout=60): |
+ """Dispatches a key event to the page. |
+ |
+ Args: |
+ type: Type of the key event. Allowed values: 'keyDown', 'keyUp', |
+ 'rawKeyDown', 'char'. |
+ modifiers: Bit field representing pressed modifier keys. Alt=1, Ctrl=2, |
+ Meta/Command=4, Shift=8 (default: 0). |
+ timestamp: Time at which the event occurred. Measured in UTC time in |
+ seconds since January 1, 1970 (default: current time). |
+ text: Text as generated by processing a virtual key code with a keyboard |
+ layout. Not needed for for keyUp and rawKeyDown events (default: ''). |
+ unmodifiedText: Text that would have been generated by the keyboard if no |
+ modifiers were pressed (except for shift). Useful for shortcut |
+ (accelerator) key handling (default: ""). |
+ keyIdentifier: Unique key identifier (e.g., 'U+0041') (default: ''). |
+ windowsVirtualKeyCode: Windows virtual key code (default: 0). |
+ nativeVirtualKeyCode: Native virtual key code (default: 0). |
+ autoRepeat: Whether the event was generated from auto repeat (default: |
+ False). |
+ isKeypad: Whether the event was generated from the keypad (default: |
+ False). |
+ isSystemKey: Whether the event was a system key event (default: False). |
+ |
+ Raises: |
+ exceptions.TimeoutException |
+ exceptions.DevtoolsTargetCrashException |
+ """ |
+ params = { |
+ 'type': keyEventType, |
+ } |
+ |
+ if modifiers is not None: |
+ params['modifiers'] = modifiers |
+ if timestamp is not None: |
+ params['timestamp'] = timestamp |
+ if text is not None: |
+ params['text'] = text |
+ if unmodifiedText is not None: |
+ params['unmodifiedText'] = unmodifiedText |
+ if keyIdentifier is not None: |
+ params['keyIdentifier'] = keyIdentifier |
+ if domCode is not None: |
+ params['code'] = domCode |
+ if domKey is not None: |
+ params['key'] = domKey |
+ if windowsVirtualKeyCode is not None: |
+ params['windowsVirtualKeyCode'] = windowsVirtualKeyCode |
+ if nativeVirtualKeyCode is not None: |
+ params['nativeVirtualKeyCode'] = nativeVirtualKeyCode |
+ if autoRepeat is not None: |
+ params['autoRepeat'] = autoRepeat |
+ if isKeypad is not None: |
+ params['isKeypad'] = isKeypad |
+ if isSystemKey is not None: |
+ params['isSystemKey'] = isSystemKey |
+ |
+ key_command = { |
+ 'method': 'Input.dispatchKeyEvent', |
+ 'params': params |
+ } |
+ return self._runtime.RunInspectorCommand(key_command, timeout) |
+ |
# Methods used internally by other backends. |
def _HandleInspectorDomainNotification(self, res): |