游戏操纵杆。获取轴()始终返回z

2024-10-01 13:43:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我买了一台罗技游戏机F310来遥控机器人。我在LinuxMint(18版,Sarah)上使用Pygame(1.9.1版,Python 2.7.11版以上)。在

作为检查操纵杆功能的简单测试,我编写了一个简短的脚本,用于输出不同轴的值:

import pygame

pygame.display.init()
pygame.joystick.init()
pygame.joystick.Joystick(0).init()

# Get the name of the joystick and print it
JoyName = pygame.joystick.Joystick(0).get_name()
print "Name of the joystick:"
print JoyName

# Get the number of axes
JoyAx = pygame.joystick.Joystick(0).get_numaxes()
print "Number of axis:"
print JoyAx

# Print the values for the axes
pygame.event.pump()
print pygame.joystick.Joystick(0).get_axis(0)
print pygame.joystick.Joystick(0).get_axis(1)
print pygame.joystick.Joystick(0).get_axis(2)
print pygame.joystick.Joystick(0).get_axis(3)

运行脚本时,无论轴处于什么位置,都会得到以下输出:

^{pr2}$

我知道输出“SDL_操纵杆。操纵杆(0).getAxis value“是由于开发人员在编译源代码时保留了debug标志。但是我不明白为什么所有的轴值都不在0的位置,脚本都会返回0。在

我用jstest gtk包测试了操纵杆。使用这个软件包,它工作得很顺利。我的代码有错误吗?在

我在windows下运行代码,它运行得很顺利。你知道为什么它在Linux发行版下不能工作吗?在


Tags: ofthename脚本getinitpygameprint
1条回答
网友
1楼 · 发布于 2024-10-01 13:43:35

从对问题的编辑中提取。

在最初的代码中(上面没有发布),我有一个while循环,但是我犯了一个新手错误,把pygame.event.pump()行放在while循环之外。我现在要学习如何使用这个模块的代码非常完美。在

import pygame

pygame.display.init()
pygame.joystick.init()
pygame.joystick.Joystick(0).init()

# Prints the joystick's name
JoyName = pygame.joystick.Joystick(0).get_name()
print "Name of the joystick:"
print JoyName
# Gets the number of axes
JoyAx = pygame.joystick.Joystick(0).get_numaxes()
print "Number of axis:"
print JoyAx

# Prints the values for axis0
while True:
        pygame.event.pump()
        print pygame.joystick.Joystick(0).get_axis(0)

我确实需要花一些时间来调整和重新编译jozy.c源代码,以消除“SDL”_操纵杆。操纵杆(0).getAxis值:0:“打印输出。显然,这个问题已经知道了好几年了,但是在Ubuntu/Mint中还没有被修复。在

相关问题 更多 >