Score:0

Can't simulate key presses in python

tj flag

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
Score:0
cn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.