Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ctypes
- import time
- import pyautogui
- """
- script for typing russian keys from pyautogui
- ideas was looked:
- translate converter: https://github.com/asweigart/pyautogui/issues/137
- change keyboard ctype: https://www.cyberforum.ru/post12039342.html
- """
- qwerty = """qwertyuiop[]asdfghjkl;'zxcvbnm,.?/QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>"""
- ycuken = """йцукенгшщзхъфывапролджэячсмитьбю,.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ"""
- tr = dict(zip(ycuken, qwerty))
- def translate(text):
- """Returns qwerty text or the given text itself if no mapping found"""
- return "".join(map(lambda x: tr.get(x, x), text))
- # only fow windows!
- def ruwrite(text, pause=True):
- # change to ru_ru
- ctypes.windll.user32.PostMessageW(ctypes.windll.user32.GetForegroundWindow(),0x0050, 2, 68748313)
- # pause for change keyboard assurance
- if pause:
- time.sleep(1)
- try:
- converted_text = translate(text)
- pyautogui.write(converted_text)
- except Exception as err:
- print('err in ruwrite fuicntion: %s' % err)
- finally:
- # change to en_us
- ctypes.windll.user32.PostMessageW(ctypes.windll.user32.GetForegroundWindow(), 0x0050, 2, 67699721)
- if pause:
- time.sleep(1)
- pyautogui.ruwrite = ruwrite
- if __name__ == '__main__':
- s = 'Привет, мир!'
- pyautogui.write('\n"write method only works for ascii chars, for cyrillc text use ruwrite method!"\n')
- pyautogui.write('"')
- pyautogui.ruwrite(s)
- pyautogui.write('"\n')
- # ! stay cursor here:
- # >>"write method only for ascii chars, for cyrillc text use ruwrite method!"
- # >>"Привет, мир!"
- print('done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement