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 !!!

Answer from furas on Stack Overflow
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › keyboard.html
Keyboard Control Functions — PyAutoGUI documentation
>>> pyautogui.write('Hello world!') # prints out "Hello world!" instantly >>> pyautogui.write('Hello world!', interval=0.25) # prints out "Hello world!" with a quarter second delay after each character
🌐
PyAutoGUI
pyautogui.readthedocs.io › en › latest › quickstart.html
Cheat Sheet — PyAutoGUI documentation - Read the Docs
>>> pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=secs_between_keys)
Discussions

Pyautogui.typewrite() not typing #
the pyautogui.typewrite() doesn't want to print # it prints ~. my keyboard is on the us layout.. any help?? More on github.com
🌐 github.com
7
August 25, 2018
high sierra - Pyautogui not entering all characters when using typewrite function - Ask Different
we are trying to automate the SecurityAgent dialog where we are inputting password using pyautogui in 10.13 OSx password = "12345678" using pyautogui.typewrite(password) this function solved the More on apple.stackexchange.com
🌐 apple.stackexchange.com
Pyautogui typewrite types numbers only (EDIT: azerty keyboard issue)
Hello! My Pyautogui typewriter doesn't want to type letters. For example when I'm executing pyautogui.typewrite("abc123") only "123" appears. I have a Windows 7 machine, Python 3.5 and Pyautogui 0.... More on github.com
🌐 github.com
11
February 26, 2016
Pyautogui type issue
I don’t have any experience with pyautogui but looking at the docs I can only find using typewrite() for tests. Then on this page for keyboard actions it says that you can use the * with a specific set of functions of which write is not one of them. It’s the last thing on that page. So I am guessing that it may not be a valid char you can pass to that function. Edit: I see the cheat sheet has typewrite() on there for keyboard functions but it’s not under the keyboard page. That’s interesting. Maybe give write() a try. More on reddit.com
🌐 r/learnpython
10
0
July 8, 2023
Top answer
1 of 4
5

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 !!!

2 of 4
1

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

🌐
GitHub
github.com › asweigart › pyautogui › issues › 259
Pyautogui.typewrite() not typing # · Issue #259 · asweigart/pyautogui
August 25, 2018 - the pyautogui.typewrite() doesn't want to print # it prints ~. my keyboard is on the us layout.. any help??
Author   DylanMcBean
🌐
ProgramCreek
programcreek.com › python › example › 103343 › pyautogui.typewrite
Python Examples of pyautogui.typewrite
See valid keyboard keys in `Press Combination`. Examples: | Type with keys down | write this in caps | Key.Shift | ''' valid_keys = self._validate_keys(keys) for key in valid_keys: ag.keyDown(key) ag.typewrite(text) for key in valid_keys: ag.keyUp(key) ... def auto_message(name, message): """Searches for friend on Google Hangouts and messages them.""" print("Make sure the Google Hangout 'Conversations' page is visible and " "your cursor is not currently on the page.") time.sleep(3) search_bar = pyautogui.locateOnScreen('search.png') pyautogui.click(search_bar) pyautogui.typewrite(name) time.sl
🌐
GitHub
github.com › asweigart › pyautogui › issues › 70
Pyautogui typewrite types numbers only (EDIT: azerty keyboard issue) · Issue #70 · asweigart/pyautogui
February 26, 2016 - Hello! My Pyautogui typewriter doesn't want to type letters. For example when I'm executing pyautogui.typewrite("abc123") only "123" appears. I have a Windows 7 machine, Python 3.5 and Pyautogui 0....
Author   PaulBobyrev
Find elsewhere
🌐
Snyk
snyk.io › advisor › pyautogui › functions › pyautogui.typewrite
How to use the pyautogui.typewrite function in PyAutoGUI | Snyk
def NumberProcess(start, inputLastPageList): for page in range(start, len(NumberList), 2): pyautogui.hotkey('ctrl', 'p', interval = 0.25) pyautogui.press('tab', 2, interval = 0.25) pyautogui.press('delete', 5, interval = 0.25) pyautogui.typewrite(NumberList[page], interval = 0.25) pyautogui.press('tab', interval = 0.25) pyautogui.press('delete', 5, interval = 0.25) pyautogui.typewrite(NumberList[page + 1]) pyautogui.typewrite(['tab', 'tab', 'enter', 'enter'], interval = 0.75) pyautogui.typewrite("File2", interval = 0.5) pyautogui.press('enter', interval = 0.5) time.sleep(5) while (os.path.isfi
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 1e › chapter18
Controlling the Keyboard and Mouse with GUI Automation
The pyautogui.typewrite() function sends virtual keypresses to the computer. What these keypresses do depends on what window and text field have focus.
🌐
Python Forum
python-forum.io › thread-23308.html
Doesn't work function pyautogui.typewrite()
Hello, i'm learning pyautogui library and was faced with a problem with typewrite function. It doesn't type anything but the other functions of the library succesfully work. I presume that problem is in cyrillic, russian language in my PC but I am no...
🌐
Reddit
reddit.com › r/learnpython › making pyautogui typewrite variables.
r/learnpython on Reddit: Making pyautogui typewrite variables.
January 3, 2021 -
import time
import pyautogui

time.sleep(3)
numbers = 601

while True:
    time.sleep(0.3)
    pyautogui.write(numbers)
    pyautogui.press("enter")
    numbers = numbers+1

I just want to type the variable "numbers" but pyautogui don't want to
Any ideas ?

🌐
Topcoder
topcoder.com › thrive › articles › python-for-gui-automation-pyautogui
PYTHON FOR GUI AUTOMATION – PYAUTOGUI
December 15, 2020 - pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'])
🌐
AskPython
askpython.com › home › auto-type text using python pyautogui
Auto-Type Text Using Python Pyautogui - AskPython
January 30, 2022 - We do so by using the typewrite() method of the module. pyautogui.typewrite(line) We are required to send messages every time, for each and every line, this means we need to send our message line by line, for this we, press enter on every iteration.
🌐
Python
bugs.python.org › issue31663
Issue 31663: pyautogui.typewrite() method doesn't work as expected. - Python tracker
October 2, 2017 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/75844
🌐
Reddit
reddit.com › r/python › problem pyautogui module; typewrite()
r/Python on Reddit: Problem pyautogui module; typewrite()
February 10, 2016 -

Hi,

I began programming with python (and in general) a couple of weeks ago. So I am still a total noob with it (in case the answer is so obvious it hurts). Recently I installed the module 'pyautogui' and although it's awesome I have a 'big' trouble with typewrite().

I use a ES Keyboard (Spanish Layout) and when I use typewrite() using some symbols, for example: pyautogui.typewrite('xxxxx@gmail.com') or the '/' (/usr/local/lib) it types not @ but " and not / but 7. (the spanish layout is this one : https://www.terena.org/activities/multiling/ml-mua/test/img/kbd_spanish.gif).

I also have an US keyboard (the author of the module is Mr. Sweigart who is, as far as i know, american) so i tried to use some kind of comibation with it like pyautogui.keyDown(shift); pyautogui.press(2) to type @ (and the same to type /) and it didn't work out. (clarification: I used all the time in the process my ES keyboard but I knew where those keys where on the US keyboard and how to type them, so for example to type @ in the US Keyboard you just need to pressshift + 2, while on the spanish one is rightalt + 2, so what i did is, using my ES keyboard, pressed shift + 2 as in the US keyboard) So is it possible to type down special characters like those or any like €, %, $... using my ES Keyboard or do i have to change the OS Keyboard (ubuntu 14.04 btw) to US and use my US Keyboard?.

Thank you very much in advance. And sorry if I misspelled.

Top answer
1 of 2
2
Hola! ;) Probably you are using Ubuntu in virtualbox right? For some time I faced the same issue, with pyautogui, sikuli, xdotool until i read the last line of this page ReadTheDocs :\ I've tried several methods and the only who works has on windows... So much fun! lol Anyway, I hope you can figuring this out, in last resort /u/Al is already here, and maybe he can help you, I never talk with him, but seems a nice and helpful person, from his python lessons ;)
2 of 2
1
Hi, I tried on my French keyboard and I found the problem. When you look at the code (depending on your configuration): https://github.com/asweigart/pyautogui/blob/da09fe4f259fbc66477351d085c21e77e3b53c1f/pyautogui/_pyautogui_osx.py , you'll see there is: keyboardMapping = dict([(key, None) for key in pyautogui.KEY_NAMES]) keyboardMapping.update({ 'a': 0x00, # kVK_ANSI_A 's': 0x01, # kVK_ANSI_S 'd': 0x02, # kVK_ANSI_D you'll see that the mappings are hardcoded for the US Keyboard layout. Now when you do: pyautogui.platformModule.keyboardMapping['@'] it will return 19, which corresponds on my keyboard to '2'. If you can lookup all the keycodes for your keyboard and set them like this: pyautogui.platformModule.keyboardMapping['@'] = keycode Then it could work. You'll maybe need some combination of keycodes. For example, on my keyboard ALT + à gives @. So instead of doing: pyautogui.typewrite(' xxxxx@gmail.com ') you'll want: pyautogui.typewrite('xxxxx') >> specific to my french keyboard pyautogui.hotkey('option','0') pyautogui.typewrite('gmail.com') this yields: xxxxx@gmail.com ;)