Reading joystick capability
Asked Answered
V

1

8

I'm trying to read my joystick capability by using the winmm.dll library. Here is how I'm doing it...

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))

When I try to do so I get an error...

function 'joyGetDevCaps' not found

After searching in the source code I found that joyGetDevCapsW is for unicode and the joyGetDevCapsA is not. I tried them both and got the same result.

When trying to read them I get an error number of 165 which is not listed in the original function MSDN site but is an error code for JOYERR_PARMS which means...

The specified joystick identifier is invalid

I'm using windows 10 and python 3.6

The code is working when using the joyGetPos and joyGetPosEx.

Thank you

Volin answered 7/4, 2018 at 13:30 Comment(5)
After more probing I found out that joyGetDevCapsW is for unicode, and I found the MAXPNAMELEN and MAX_JOYSTICKOEMVXDNAME values. But it still doesn't workVolin
Update your code so that the strict is correct, also try getting the win32 api error? programcreek.com/python/example/7186/win32api.GetLastError and codegists.com/snippet/python/controllerpy_wezu_pythonAmalberga
Thank you I updated the code and when runnig GetLastError the return value is 126 meaning The specified module could not be found. I don't think that this is connected the the winmm.dll file because I ran a command that return correctly and I get the same error. So could be it is not updated.Volin
Could it have something to do with 32bit/64bit process? Can you try in both 32 bit as well as 64bit python and see if something changes?Amalberga
No tried both of them just now get the same errorVolin
R
0

This Gist does something similar to what you do and more: https://gist.github.com/rdb/8883307

Might be that TCHAR needs a length.

Riddance answered 11/4, 2018 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.