diff --git a/internal/devtools.py b/internal/devtools.py index 3a1d9bcd2..3d20de860 100644 --- a/internal/devtools.py +++ b/internal/devtools.py @@ -1313,7 +1313,7 @@ def key_info(self, key): info['text'] = definition['text'] return info - def key_down(self, key): + def key_down(self, key, modifier): """Press down a key""" info = self.key_info(key) params = { @@ -1321,7 +1321,8 @@ def key_down(self, key): 'key': info['key'], 'windowsVirtualKeyCode': info['keyCode'], 'code': info['code'], - 'location': info['location'] + 'location': info['location'], + 'modifiers': modifier } if 'text' in info: params['type'] = 'keyDown' @@ -1331,7 +1332,7 @@ def key_down(self, key): params['isKeypad'] = True self.send_command('Input.dispatchKeyEvent', params) - def key_up(self, key): + def key_up(self, key, modifier): """Let up a key""" info = self.key_info(key) self.send_command('Input.dispatchKeyEvent', { @@ -1339,14 +1340,15 @@ def key_up(self, key): 'key': info['key'], 'windowsVirtualKeyCode': info['keyCode'], 'code': info['code'], - 'location': info['location'] + 'location': info['location'], + 'modifiers': modifier }) - def keypress(self, key): + def keypress(self, key, modifier): """Simulate pressing a keyboard key""" try: - self.key_down(key) - self.key_up(key) + self.key_down(key, modifier) + self.key_up(key, modifier) except Exception: logging.exception('Error running keypress command') @@ -1355,7 +1357,7 @@ def type_text(self, string): try: for char in string: if char in self.key_definitions: - self.keypress(char) + self.keypress(char, 0) else: self.send_character(char) except Exception: diff --git a/internal/devtools_browser.py b/internal/devtools_browser.py index 81708b9f4..76aaffc33 100644 --- a/internal/devtools_browser.py +++ b/internal/devtools_browser.py @@ -30,6 +30,11 @@ import json from .optimization_checks import OptimizationChecks +KeyModifiers = { + "ALT": 1, + "CTRL": 2, + "SHIFT": 8 +} class DevtoolsBrowser(object): """Devtools Browser base""" @@ -765,7 +770,13 @@ def process_command(self, command): elif command['command'] == 'type': self.devtools.type_text(command['target']) elif command['command'] == 'keypress': - self.devtools.keypress(command['target']) + modifier = 0 + value = command['value'] + if value is not None: + keyModifier = value.upper() + if keyModifier in KeyModifiers.keys(): + modifier = KeyModifiers[keyModifier] + self.devtools.keypress(command['target'], modifier) elif command['command'] == 'mouseClick': if 'target' in command: target = command['target']