3

While using the Automagica package to automate processes using Python, I have run into an unexpected issue.

I cannot type unicode characters using this tool.

from automagica import *

PressHotkey('win','r')
Wait(seconds=1)
Type(text='notepad', interval_seconds=0)
PressKey('enter')
Wait(seconds=2)
Type(text='Hello æ ø å ', interval_seconds=0)

Should result in a notepad being opened and the text Hello æ ø å typed into it.

enter image description here

The æøå characters are not typed, the spaces are though.

when I look into the definition for the function Type i get

def Type(text=None, interval_seconds=0.001):
    '''
    Type text in the current active field. The first argument represent the text and is entered as a string. 
    The second variable is the time between two keystrokes. Pay attention that you can only press single 
    character keys. Keys like ":", "F1",... can not be part of the text argument.
    '''
    from pyautogui import typewrite
    # Set keyboard layout for Windows platform
    if platform.system() == 'Windows':
        from win32api import LoadKeyboardLayout
        LoadKeyboardLayout('00000409', 1)
    return typewrite(text, interval=interval_seconds)

Could it be a keyboard layout issue? The function description states that only character keys can be used, but here in Denmark the stated characters are such keys

---------EDIT---------

I figured out that the issue is in pyautogui that does not support special characters

this is my solution

from automagica import *

def type_unicode(text):
    import pyautogui
    import pyperclip
    pyperclip.copy(text)
    pyautogui.hotkey("ctrl", "v")

PressHotkey('win','r')
Wait(seconds=1)
Type(text='notepad', interval_seconds=0)
PressKey('enter')
Wait(seconds=2)
type_unicode('Hello æ ø å')
Henrik Poulsen
  • 935
  • 2
  • 13
  • 32

0 Answers0