encoding of backslash in pythons pyautogui

Viewed 3750

I am trying write a python script that runs an external program automatically by clicking buttons and give keyboard input (usually file paths) with pyautogui. Now if I try use the funktion pyautogui.typewriter(filepath) it always types the backslashes as questionmarks. This minimal example:

pyautogui.typewrite('\\')

returns simply ?

Now, if I change my keyboard layout in the system settings to english, it correctly returns \

My default layout is german, and I cant really change that because this messes up the later stages of the program due to wrong date formats. Any ideas how to solve this problem?

5 Answers

I am having the same problem, but I am working on Linux. The solution for me was just to use the divide.

When I am typing 'cd /home/pi' the '/' never appear, the solution was:

if key == '/':
    pyautogui.press('divide')

It works for me!

It looks hard but is actually easy what you have to do is just make a variable and type '\\' in it then just write the variable in pyautogui like this:

x = "\\"
pyautogui.write(x)

I think your problem is now solved.

Related