Skip to content
Advertisement

How to simulate human keyboard input of a long text using Python?

I would like to simulate typing of huge text. I’ve tried to use pyautogui to do that, but I’t didn’t worked properly since the computer was not detecting the keys being pressed:

JavaScript

I couldn’t think of another way to do that than using pynput.keyboard library, but as I have a huge text, that would not be a viable option. I don’t know if there is a way to simulate the keys other than create a line for each letter.

JavaScript

Is there a way to simulate keys being pressed to write a text without having to create a single line for each letter that the script would have to type?

Advertisement

Answer

The code below demonstrates that there is a way to simulate keys being pressed to write a text without having to create a single line for each letter that the script would have to type.

In addition to that the provided solution allows to execute code placed in the same script after the code for automated typing which feature is used to show the automated keyboard input in a typing speed test GUI:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement