阅读操纵杆功能

Dud*_*i b 8 python msdn ctypes joystick python-3.x

我正试图通过使用winmm.dll库来阅读我的操纵杆功能.我是这样做的......

from ctypes import windll, Structure, c_uint, c_ushort, c_char, c_ulong
WORD = c_ushort
UINT = c_uint
TCHAR = c_char
winmm = windll.LoadLibrary('winmm.dll')
class JOYCAPS(Structure):
   _fields_ = [
    ('wMid', WORD),
    ('wPid', WORD),
    ('szPname', TCHAR * MAXPNAMELEN),  # originally szPname[MAXPNAMELEN]
    ('wXmin', UINT),
    ('wXmax', UINT),
    ('wYmin', UINT),
    ('wYmax', UINT),
    ('wZmin', UINT),
    ('wZmax', UINT),
    ('wNumButtons', UINT),
    ('wPeriodMin', UINT),
    ('wPeriodMax', UINT),
    ('wRmin', UINT),
    ('wRmax', UINT),
    ('wUmin', UINT),
    ('wUmax', UINT),
    ('wVmin', UINT),
    ('wVmax', UINT),
    ('wCaps', UINT),
    ('wMaxAxes', UINT),
    ('wNumAxes', UINT),
    ('wMaxButtons', UINT),
    ('szRegKey', TCHAR * MAXPNAMELEN),  # originally szRegKey[MAXPNAMELEN]
    ('szOEMVxD', TCHAR * MAX_JOYSTICKOEMVXDNAME)  # originally szOEMVxD[MAX_JOYSTICKOEMVXDNAME]
   ]
joyinf = JOYCAPS()
err = winmm.joyGetDevCaps(0, pointer(joyinf), sizeof(joyinf))
if err == JOYERR_NOERROR:
    for l in [s for s in dir(joyinf) if "_" not in s]:
        print(l, getattr(joyinf, l))
Run Code Online (Sandbox Code Playgroud)

当我尝试这样做时,我得到一个错误......

功能'joyGetDevCaps'找不到

在源代码中搜索后,我发现joyGetDevCapsW是unicode,而joyGetDevCapsA不是.我尝试了两者并获得了相同的结果.

当我尝试读取它们时,我得到一个错误号165,它没有在原始函数MSDN站点中列出,但是是一个错误代码JOYERR_PARMS,意味着......

指定的操纵杆标识符无效

我正在使用Windows 10和python 3.6

使用joyGetPos和时代码正常工作joyGetPosEx.

谢谢

Gün*_*erl 0

这个要点与您所做的类似,甚至更多:https://gist.github.com/rdb/8883307

可能 TCHAR 需要一个长度。