gpt4 book ai didi

python - 读取操纵杆功能

转载 作者:太空狗 更新时间:2023-10-29 21:11:44 25 4
gpt4 key购买 nike

我正在尝试使用 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))

当我尝试这样做时,出现错误...

function 'joyGetDevCaps' not found

在搜索源代码后,我发现 joyGetDevCapsW 是 unicode 而 joyGetDevCapsA 不是。我尝试了这两种方法并得到了相同的结果。

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

The specified joystick identifier is invalid

我正在使用 windows 10 和 python 3.6

当使用 joyGetPosjoyGetPosEx 时,代码可以正常工作。

谢谢

最佳答案

这个 Gist 做的事情与你所做的类似,甚至更多:https://gist.github.com/rdb/8883307

可能是 TCHAR 需要一个长度。

关于python - 读取操纵杆功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49707878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com