使用pygame,因为它可以读取操纵杆,对于pygame使用哪种类型的控制器并不重要。例如,当我们按下'A'按钮时,我们希望python打印“A Has Been Pressed”。在
import pygame
pygame.init()
joysticks = []
clock = pygame.time.Clock()
keepPlaying = True
# for al the connected joysticks
for i in range(0, pygame.joystick.get_count()):
# create an Joystick object in our list
joysticks.append(pygame.joystick.Joystick(i))
# initialize them all (-1 means loop forever)
joysticks[-1].init()
# print a statement telling what the name of the controller is
print ("Detected joystick "),joysticks[-1].get_name(),"'"
while keepPlaying:
clock.tick(60)
for event in pygame.event.get():
#The zero button is the 'a' button, 1 the 'b' button, 3 the 'y'
#button, 2 the 'x' button
if event.button == 0:
print ("A Has Been Pressed")
使用pygame,因为它可以读取操纵杆,对于pygame使用哪种类型的控制器并不重要。例如,当我们按下'A'按钮时,我们希望python打印“A Has Been Pressed”。在
相关问题 更多 >
编程相关推荐