mrwnt10
mrwnt10

Reputation: 1415

pyautogui typewrite() writes to shell instead of clicked input/document

I am following Chapter 18 of Automate the Boring Stuff with Python. I'm on OS X.

I am trying to use pyautogui to click on a text input or text document and then input text.

I am entering the following into a shell ((370, 80) are the coordinates of my Chrome address bar):

pyautogui.click(370,80); pyautogui.typewrite('Hello world!')

click() seems to not be working as expected. It will highlight text in an input when I click on the input, but even when I manually type after the click, the text shows up in the shell. See the below screenshot of the result of running the above line:

enter image description here

Other methods like position, moveTo, moveRel, and dragTo are working as expected.

If I run time.sleep(5); pyautogui.typewrite('test') and manually click on the text document or input while the thread is sleeping, the text is inputted as desired.

What might be the problem?

Upvotes: 1

Views: 2529

Answers (1)

mrwnt10
mrwnt10

Reputation: 1415

Turns out there is a bug related to click() in OSX. Here is the solve:

  1. Open the __init__.py file in the pyautogui package directory (find the location of your Python packages using this answer.
  2. On line 510 (in the click() function), change the fourth argument to platformModule._multiClick() from 3 to clicks (no quotes). So the correct invocation is platformModule._multiClick(x, y, button, clicks)
  3. Save the edited file.

There is an open PR to fix the issue.

Upvotes: 1

Related Questions