Created
June 1, 2020 14:42
-
-
Save kraftwerk28/fd6a33e7ba25bd5ee4cfa985a30171e2 to your computer and use it in GitHub Desktop.
Keybr hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # Run $('.TextInput-fragment').textContent in browser console | |
| # Then run this script and copy-paste text from browser console to terminal. | |
| # Script will Alt+Tab to browser so make sure it won't go to the wrong window. | |
| import os | |
| import time | |
| import pyautogui as pag | |
| import random | |
| def type(text): | |
| pieces = [text[i:i + 5] for i in range(0, len(text), 5)] | |
| pag.hotkey('alt', 'tab') | |
| pag.sleep(0.2) | |
| for p in pieces: | |
| interval = random.randint(3, 10) | |
| print(f'Writing "{p}" with interval {interval}.') | |
| pag.write(p, interval=interval / 100) | |
| pag.hotkey('alt', 'tab') | |
| if __name__ == '__main__': | |
| print('Enter a text:') | |
| lines = [] | |
| while True: | |
| l = input('> ') | |
| if l: | |
| lines.append(l) | |
| else: | |
| break | |
| text = '\n' \ | |
| .join(lines) \ | |
| .replace('␣', ' ') \ | |
| .replace('↵', '\n') \ | |
| .replace('\\', '') | |
| try: | |
| type(text) | |
| except pag.FailSafeException: | |
| print('Fail safe called.') | |
| except KeyboardInterrupt: | |
| sys.exit(0) | |
| except Exception as e: | |
| print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment