我正在尝试使用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))
当我尝试这样做时,我收到错误...
找不到函数'joyGetDevCaps'
在源代码中搜索后,我发现joyGetDevCapsW
用于unicode而joyGetDevCapsA
不是。我试过了两个并得到了同样的结果。
尝试阅读时,我得到的错误编号为165,未在原始函数MSDN site中列出,但是JOYERR_PARMS
的错误代码,这意味着......
指定的操纵杆标识符无效
我正在使用Windows 10和python 3.6
使用joyGetPos
和joyGetPosEx
时,代码正常工作。
谢谢