shift_a_sequence = """keydown Shift_L
key A
keyup Shift_L
"""

def keypress(sequence):
    p = Popen(['xte'], stdin=PIPE)
p.communicate(input=sequence)
keypress(shift_a_sequence)
keypress(control_f4_sequence)
Имитация нажатия клавиш в Linux с помощью Python