sends the text 'txt' to the window handle hwnd using SendMessage

def send_text(hwnd, txt):
    """
    sends the text 'txt' to the window handle hwnd using SendMessage
    """
    try:
        for c in txt:
            if c == '\n':
                win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
                win32api.SendMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
            else:
                win32api.SendMessage(hwnd, win32con.WM_CHAR, ord(c), 0)            
    except Exception as ex:
        print('error calling SendMessage ' + str(ex))