It doesn't send ascii char ! to program - it sends keyboard's code to system (probably code for key 1 which in standard layout is used for char !) and system decides what char send to program. If your system has non-standard layout then system may send wrong char.
Probably only using clipboad you can send it correctly. If you will use clipboard to copy single char and wait 0.1s between chars then you can get similar result.
Copyimport time
import pyperclip
import pyautogui
time.sleep(2)
for char in 'Hello World!':
pyperclip.copy(char)
pyautogui.hotkey('ctrl', 'v', interval=0.1)
BTW: using print(pyautogui.__file__) you can find folder with source code and in file _pyautogui_win.py you can see what key codes it uses in Windows.
You should see key codes assigned to chars using also
Window:
Copyprint(pyautogui._pyautogui_win.keyboardMapping)
Linux:
Copyprint(pyautogui._pyautogui_x11.keyboardMapping)
Maybe if you change values in keyboardMapping then it will send it correctly but for every layout you would have to set different values.
For example on Linux this
Copyimport pyautogui
#pyautogui._pyautogui_win.keyboardMapping['!'] = 12
pyautogui._pyautogui_x11.keyboardMapping['!'] = 12
pyautogui.typewrite('!!!')
gives me ### instead of !!!
Videos
» pip install PyAutoGUI
It doesn't send ascii char ! to program - it sends keyboard's code to system (probably code for key 1 which in standard layout is used for char !) and system decides what char send to program. If your system has non-standard layout then system may send wrong char.
Probably only using clipboad you can send it correctly. If you will use clipboard to copy single char and wait 0.1s between chars then you can get similar result.
Copyimport time
import pyperclip
import pyautogui
time.sleep(2)
for char in 'Hello World!':
pyperclip.copy(char)
pyautogui.hotkey('ctrl', 'v', interval=0.1)
BTW: using print(pyautogui.__file__) you can find folder with source code and in file _pyautogui_win.py you can see what key codes it uses in Windows.
You should see key codes assigned to chars using also
Window:
Copyprint(pyautogui._pyautogui_win.keyboardMapping)
Linux:
Copyprint(pyautogui._pyautogui_x11.keyboardMapping)
Maybe if you change values in keyboardMapping then it will send it correctly but for every layout you would have to set different values.
For example on Linux this
Copyimport pyautogui
#pyautogui._pyautogui_win.keyboardMapping['!'] = 12
pyautogui._pyautogui_x11.keyboardMapping['!'] = 12
pyautogui.typewrite('!!!')
gives me ### instead of !!!
This seems to be a known issue:
https://github.com/asweigart/pyautogui/issues/38
User on Windows 7, Python 3.4, running PyAutoGUI 0.9.30 and a French "AZERTY" keyboard reported being unable to simulate pressing :
Running the unit tests, they got these results:
[...]
a
ba
.Hello world§
https://github.com/asweigart/pyautogui/pull/55
https://github.com/asweigart/pyautogui/issues/137
Use pyautogui.press(“enter”) or pyautogui.hotkey(“enter”)
for pressing 3 times:
use pyautogui.press(“enter”, presses=3)
or
for i in range(3):
pyautogui.press(“enter”)
for pressing lots of keys:
pyautogui.press([“enter”, “shift”])
or
for key in [“enter”, “shift”]:
pyautogui.press(key)
dispatch user holding down the key until keyup:
pyautogui.keyDown(“enter”)
and for keyup:
pyautogui.keyUp(“enter”)
and also one thing, if you’re used keyDown, you can still use pyautogui.press(“enter”) too :D
If you want to know more go to https://pyautogui.readthedocs.io/en/latest/keyboard.html
Short answer
pyautogui.press('enter')
or
pyautogui.write('\n')
source
If not working, could be because the mouse cursor is not on the desired place, maybe you would need to first click over the app you want to enter with for example pyautogui.click(100, 200); where (100,200) are the X,Y coordinates of screen, you will need to locate where do you need that enter.
For more details, you could see this