PyAutoGui - Press key for X seconds

后端 未结 1 1768
有刺的猬
有刺的猬 2021-01-06 01:23

I\'m currently working on a script that presses the \'w,a,s,d\' keys in order to move a character in any game. For this to work, i need to have the \'

相关标签:
1条回答
  • 2021-01-06 01:52

    As said in the doc-string from pyautogui.keyDown():

    Performs a keyboard key press without the release. This will put that key in a held down state.

    NOTE: For some reason, this does not seem to cause key repeats like would happen if a keyboard key was held down on a text field.


    You need a different approach - you can may use pygame - with this

    Or, if you want to stay with pyautogui you can try something like this:

    def hold_W (hold_time):
        import time, pyautogui
        start = time.time()
        while time.time() - start < hold_time:
            pyautogui.press('w')
    
    0 讨论(0)
提交回复
热议问题