import time
import usb.device

from usb.device.keyboard import KeyboardInterface, KeyCode

keyboard = KeyboardInterface()
usb.device.get().init(keyboard, builtin_driver=True)

# Wait until the computer recognizes the keyboard.
while not keyboard.is_open():
    time.sleep(0.1)

# Give yourself time to click inside TextEdit.
time.sleep(2)

# Type A three times.
for _ in range(3):
    keyboard.send_keys((KeyCode.A,))
    keyboard.send_keys(())
    time.sleep(0.1)

# Program ends here.
