找出了一个hack:
PS4按钮编号如下:
0 = SQUARE
1 = X
2 = CIRCLE
3 = TRIANGLE
4 = L1
5 = R1
6 = L2
7 = R2
8 = SHARE
9 = OPTIONS
10 = LEFT ANALOG PRESS
11 = RIGHT ANALOG PRESS
12 = PS4 ON BUTTON
13 = TOUCHPAD PRESS
为了弄清楚哪个按钮被按下,我使用
j.get_button(int),传入匹配的按钮整数。
例:
import pygamepygame.init()j = pygame.joystick.Joystick(0)j.init()try: while True: events = pygame.event.get() for event in events: if event.type == pygame.JOYBUTTONDOWN: print("Button Pressed") if j.get_button(6): # Control Left Motor using L2 elif j.get_button(7): # Control Right Motor using R2 elif event.type == pygame.JOYBUTTONUP: print("Button Released")except KeyboardInterrupt: print("EXITING NOW") j.quit()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)