【问题标题】:How do you get pygame to continue to run/look for user input while in the background如何让 pygame 在后台继续运行/查找用户输入
【发布时间】:2022-08-15 04:23:45
【问题描述】:

我希望让我的游戏在后台运行,如果单击 WASD 来移动屏幕上的角色,无论是否选择了程序窗口。为了更好地说明,我希望使用一个应用程序,同时让我的游戏在另一个应用程序单击 W、A、S 或 D 按钮时更新玩家位置。

  • 您可以使用其他不需要窗口的库,如果需要,可以同时使用 pygame 窗口。
  • pynputkeyboard 库可能会对您有所帮助。未选中时,pygame 窗口无法检测到键。
  • 谢谢杰瑞,我已经上传了我想出的东西,但如果你有任何意见,我就无法解决这些错误。 stackoverflow.com/questions/73333872/…

标签: pygame background running-other-programs


【解决方案1】:

您可以使用键盘为了它:

pip install keyboard

import keyboard
# This will detect q key press.
# And returns True/False.
# You need to put this code inside you game loop.
keyboard.is_pressed('q')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    相关资源
    最近更新 更多