I just found this script that does EXACTLY what I wanted.
It is based on a Linux command line that generates fake inputs xte (use sudo apt-get install xte
in debian based distribution to download it.
I'm using a system call in python to do the job.
In this example, we are generating two right arrow strikes each two seconds. We can test it by positioning the cursor in a text document, launch the script, and watch the cursor move.
from subprocess import Popen, PIPE
import time
def keypress(sequence):
p = Popen(['xte'], stdin=PIPE)
p.communicate(input=sequence)
time.sleep(2)
keypress("key Right ")
time.sleep(2)
keypress("key Right ")
time.sleep(2)
keypress("key Right ")
time.sleep(2)
keypress("key Right ")