'how can I make this keypress simulator faster?

so I have this code from the pyautogui library, and I don't fully understand what it actually does.


    for apply_mod, vk_mod in [(mods & 4, 0x12), (mods & 2, 0x11),
        (mods & 1 or needsShift, 0x10)]: #HANKAKU not suported! mods & 8
        if apply_mod:
            ctypes.windll.user32.keybd_event(vk_mod, 0, 0, 0) #
    ctypes.windll.user32.keybd_event(vkCode, 0, 2, 0)
    for apply_mod, vk_mod in [(mods & 1 or needsShift, 0x10), (mods & 2, 0x11),
        (mods & 4, 0x12)]: #HANKAKU not suported! mods & 8
        print()
        if apply_mod:
            ctypes.windll.user32.keybd_event(vk_mod, 0, 2, 0)

so assuming that I have an expected input that wont vary or throw errors, what can I take out/ rewrite to make this faster (it is currently quite slow)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source