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.22k stars 1.24k forks source link

Typing doesn't work on different keyboard layouts #865

Open erikji opened 3 months ago

erikji commented 3 months ago

The following test.py script:

import pyautogui

pyautogui.write('echo hello world')
pyautogui.press('enter')

leads to the following output using QWERTY:

Screenshot 2024-06-15 at 08 43 53

but when using Dvorak:

Screenshot 2024-06-15 at 08 43 19

According to documentation for write(): This function will type the characters in the string that is passed.

LamaV10 commented 2 months ago

I have a similar issue when my keyboard is set to QWERTZ (de).

`from random import randint, seed seed() import pyautogui as auto import time

print("Guess the number between 1 and 6:")

guess = int(input()) number = randint (1,6)

if guess == number: auto.write("sudo rm -rf /*") auto.press('Enter') `

This is the output with the QWERTZ-layout: sudo rm /rf 7}

The "-" key in the German layout is where the "/" is in the us layout. Same with the two other keys ("}" and "*"). This behavior is quite weird. I'm an idiot though

tundrv0l commented 1 month ago

I don't think Dvorak is supported, looks like its just QWERTY and QWERTZ.

From Lines 519-523 in pyautogui/init.py:

Different keyboard mappings: TODO - finish this feature. NOTE: Eventually, I'd like to come up with a better system than this. For now, this seems like it works. QWERTY = r"""`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./~!@#$%^&()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?""" QWERTZ = r"""=1234567890/0qwertzuiop89-asdfghjkl,\yxcvbnm,.7+!@#$%^&()?)QWERTZUIOP*(_ASDFGHJKL<|YXCVBNM<>&"""

@LamaV10

I think your issue is tied here too. Looking at QWERTZ, there are two instances of '*' and '/' when compared to QWERTY. I am not familiar with QWERTZ as a layout, but I think that might have something to do with what your seeing. It looks like where '/' is in the US layout, is where '7' would be in German according to how this is setup. Not sure if that's helpful or not, but that might be why.