pyautogui-按键x秒
我目前正在编写一个脚本,该脚本按“ w,a,s,d ”键,以便在任何游戏中移动角色。 为此,我需要将' w '键施加特定时间。我该如何实现?
我想到了类似的事情:
pyautogui.keyDown('w')
time.sleep(2)
pyautogui.keyUp('w')
但是这只是暂停了整个程序,而没有按下钥匙,所以这对我没有用。
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 'w' key pressed for a specific amount of time. How can I achieve this?
I thought of something like:
pyautogui.keyDown('w')
time.sleep(2)
pyautogui.keyUp('w')
But this just pauses the whole program and no key is being pressed so this has no use to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如
pyautogui.keydown()
的文档弦乐中所述:您需要其他方法 - 您可以使用 pygame-使用此
或,如果您想留下
pyautogui
,则可以尝试这样的事情:As said in the doc-string from
pyautogui.keyDown()
: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:这将在不做自己的功能的情况下解决问题。
This will do the trick without making your own function.