I’ve encountered an issue in Ubuntu that seems to have persisted since at least version 20.04. The problem appears to be related to the handling of nonprintable characters such as \n, \t, and \e.

Here’s a Python snippet that demonstrates the issue:

import sys
from pynput.keyboard import Controller, Key

keyboard = Controller()
message = ' '.join(sys.argv[1:])
keyboard.type(message.replace('\n', r'\n'))

In the above code, if I remove the .replace('\n', r'\n') part, the script runs significantly slower. It seems as though the presence of newlines (and other nonprintable characters) slows down the execution.

This issue isn’t limited to Python or the pynput library. I’ve been able to reproduce it using xlib, and it appears to be the underlying cause of slow performance in libxdo (and xdotool), pyautogui, and similar tools on Ubuntu.

Interestingly, this problem doesn’t occur on Arch Linux.

My question is: can anyone identify and explain why this is happening? Any insights would be greatly appreciated.



You must log in to answer this question.

Browse other questions tagged .