Search code examples
ubuntukeypresskeydownpyautogui

PyAutoGUI Key Press slow performance in Linux Ubuntu


I'm facing an issue running PyAutoGUI on Linux Ubuntu 19.06 x64, when I need to use the keyDown/KeyPress function.

After running the code, it freezes the computer for about 4 or 5 seconds, and the CPU usage goes to 100%

Something really simple like this:

import pyautogui

pyautogui.keyDown('altleft')
pyautogui.click(910, 477)
pyautogui.click(840, 477)
pyautogui.click(844, 412)
pyautogui.keyUp('altleft')

I can see the mouse moving on my screen, but the whole computer freezes after that. I tested in different computers, physicals and VM's, all the same behaviour.

I also did test in my Windows computer, and with that one I had no problems.

Any ideas about this?

I'm not very familiar with Python nor Linux. I believe I might be missing to install or configure something.


Solution

  • Figure it out that the problem is actually on the graphical server.

    The answer is in this post: https://bugs.launchpad.net/ubuntu/+source/meta-gnome3/+bug/1777708

    When I changed to Wayland I did not have the problem.

    If anyone has similar issue, to change the graphical server, see the steps in the link below: enter link description here