asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.45k stars 1.26k forks source link

pyautogui fails to recognize special characters such as "á, é, í, ó and ú" #858

Open afpg89 opened 6 months ago

afpg89 commented 6 months ago

""" watch out for blank lines watch out for using the word space at end of line Please be careful which window this types into """

import pyautogui import time

spaces = 0 delay_speed = 0.17 #Bigger number slower typing

def tabbing_mech(line): #Needed for IDEs global spaces count_space = 0 for char in line: if char == " ": count_space += 1 else: break print(count_space, spaces, line)

if spaces > count_space:
    back_tab = (spaces - count_space) // 4 #Number of spaces per indent
    spaces = count_space
    print("tab back")
    for i in range(back_tab):
        pyautogui.keyDown('shift')
        pyautogui.press('tab')
        pyautogui.keyUp('shift')
    return line.replace("  ", "")
elif count_space == 0:
    return line
elif spaces == count_space:
    return line.replace("  ", "")
elif spaces < count_space:
    print("indenting")
    spaces = count_space
    return line.replace("  ", "")

for i in range(3): #Seconds before it starts typing time.sleep(1) print(i)

with open("texto.txt", 'r') as f: for lines in f:

type_me = lines #Use this if on a word processor

    type_me = tabbing_mech(lines) #Used for IDEs
    pyautogui.typewrite(type_me, delay_speed)

I personally don't know how to solve this issue, as one of my initial changes to the code was including UTF-8 codification reader, but nothing seemed to work.

THX in advance