Input unicode string with pyautogui

前端 未结 3 1489
野的像风
野的像风 2020-12-11 03:07

I\'m creating an autotesting app with pyautogui lib. I want to use typewrite method to input text into forms. But some of my input strings have uni

3条回答
  •  天命终不由人
    2020-12-11 03:37

    Found one quite simple one.

    In Mac and Linux there is an opportunity to input unicode characters using their hex codes. There is article on wikipedia about that. I'm writing my program for Mac so I enabled Unicode Hex Input in my keyboard settings and wrote this code:

    def type_unicode(word):
        for c in word:
            c = '%04x' % ord(c)
            pyautogui.keyDown('optionleft')
            pyautogui.typewrite(c)
            pyautogui.keyUp('optionleft')
    

提交回复
热议问题