Input unicode string with pyautogui

testlnord

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 unicode characters in them. For example:

Næst

According to documentation typewrite can only press single-character keys. So it just ignores the æ character.

Can you advise some simple workaround?

testlnord

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')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related