0

I am using python to simulate key presses, the Pyautogui library is working fine for windows, but When I use it for linux, It only executes in the IDE in which it is running not other applications, how to fix this problem?

Here is my code:

import pyautogui #pip install pyautogui
import time

time.sleep(1)

pyautogui.keyDown('w') #press W key

1 Answers1

1

You do not specify any version of Ubuntu you might be using, nor did you specify the python libraries you are using to send keystrokes. Still, I strongly suspect you are running on the Wayland display server, which has become the default on Ubuntu since 21.10. Even after an upgrade, you have been moved to Wayland. The python libraries, such as PyAutoGui, that allow to simulate keystrokes do not work on Wayland.

Awaiting the availability of updated or alternative Python libraries that do run on Wayland, you will need to switch to an Xorg session to make it work.

vanadium
  • 88,010