1
我正在尝试制作最简单的pythong代码,它会在按下游戏杆上的按钮时作出响应。我使用了几个不同示例的代码,但仍然无法实现。当我按下触发(或与此有关的任何按钮)当执行事件时,PyGame代码无法正确执行
import pygame
joy = []
def handleJoyEvent(e):
if e.type == pygame.JOYBUTTONDOWN:
str = "Button: %d" % (e.dict['button'])
if (e.dict['button'] == 0):
print ("Pressed!\n")
else:
pass
def joystickControl():
while True:
e = pygame.event.wait()
if (e.type == pygame.JOYBUTTONDOWN):
handleJoyEvent(e)
# main method
def main():
pygame.joystick.init()
pygame.display.init()
for i in range(pygame.joystick.get_count()):
myjoy = pygame.joystick.Joystick(i)
myjoy.init()
joy.append(myjoy)
# run joystick listener loop
joystickControl()
# allow use as a module or standalone script
if __name__ == "__main__":
main()
我试过你的代码,它为我工作。因此,您的电脑可能会识别您的操纵杆或其他问题。您是否已经成功地使用其他应用程序试用过游戏杆 – 2010-12-11 15:16:51