| ... | @@ -176,6 +176,10 @@ async def desktop(name, actions=None, platform=None, screenshot=True, native_tex | ... | @@ -176,6 +176,10 @@ async def desktop(name, actions=None, platform=None, screenshot=True, native_tex |
| 176 | | 176 | |
| 177 | | 177 | |
| 178 | async def capture(name, actions, platform, screenshot=True, native_text=True): | 178 | async def capture(name, actions, platform, screenshot=True, native_text=True): |
| | 179 | if not native_text: |
| | 180 | for action in actions or (): |
| | 181 | if action['type'] == 'text' and any(not (32 <= ord(char) <= 126 or char in '\n\r\t') for char in action['text']): |
| | 182 | raise ValueError('This connection supports ASCII text only. Use key actions for other keyboard input.') |
| 179 | target = vms.console_target(name, timeout=remaining(10)) | 183 | target = vms.console_target(name, timeout=remaining(10)) |
| 180 | reader, writer = await asyncio.wait_for(asyncio.open_connection('127.0.0.1', target['port']), 10) | 184 | reader, writer = await asyncio.wait_for(asyncio.open_connection('127.0.0.1', target['port']), 10) |
| 181 | screen = rfb.Desktop(reader, writer, lambda _: None) | 185 | screen = rfb.Desktop(reader, writer, lambda _: None) |
| ... | @@ -234,11 +238,8 @@ async def capture(name, actions, platform, screenshot=True, native_text=True): | ... | @@ -234,11 +238,8 @@ async def capture(name, actions, platform, screenshot=True, native_text=True): |
| 234 | with contextlib.suppress(Exception): | 238 | with contextlib.suppress(Exception): |
| 235 | await pending | 239 | await pending |
| 236 | else: | 240 | else: |
| 237 | text = action['text'] | | |
| 238 | if any(not (32 <= ord(char) <= 126 or char in '\n\r\t') for char in text): | | |
| 239 | raise ValueError('This connection supports ASCII text only. Use key actions for other keyboard input.') | | |
| 240 | shifted = dict(zip('~!@#$%^&*()_+{}|:"<>?', '`1234567890-=[]\\;\',./')) | 241 | shifted = dict(zip('~!@#$%^&*()_+{}|:"<>?', '`1234567890-=[]\\;\',./')) |
| 241 | for char in text.replace('\r\n', '\n'): | 242 | for char in action['text'].replace('\r\n', '\n'): |
| 242 | shift = char in shifted | 243 | shift = char in shifted |
| 243 | base = shifted.get(char, char) | 244 | base = shifted.get(char, char) |
| 244 | key = {'\n': 0xff0d, '\r': 0xff0d, '\t': 0xff09}.get(base, ord(base)) | 245 | key = {'\n': 0xff0d, '\r': 0xff0d, '\t': 0xff09}.get(base, ord(base)) |