windows api and joystick reading

Started by
7 comments, last by Sik_the_hedgehog 11 years, 11 months ago
hello, i'm trying to get just basic joypad support in my application, and can't seem to figure out this problem.

essentially joyGetPos keeps returning JOYERR_PARAMS, even though it supposedly does not return such an error.

here's a sample of usage:


#include <windows.h>

int main(int argc, char **argv){
printf("Joys supported: %d\n", joyGetNumDevs()); //Output: "Joys supported: 16"
JOYINFO jp;
for(unsigned int i=0;i<joyGetNumDevs();i++){
MMRESULT Result = joyGetPos(i, &jp);
printf("Joy %d: %d\n", i, Result); //Output: "Joy (0-15): 165" (165 is JOYERR_PARAMS)
}
return 0;
}
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Advertisement
This is a pretty old and (AFAIK) deprecated API. Have you tried DirectInput or XInput?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

What type of joypad are you using?


#Advice 0:

For legacy controllers use DirectInput. (XInput does not support them).
Most new controllers (such as the Xbox360 gamepad & new logitech controllers) do support DirectInput as well although in the cost of limited functionality.

Read more here: http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx


#Advice 1:

Try to use joyGetPosEx instead of joyGetPos.

MSDN: L"For devices that have four to six axes of movement, a point-of-view control, or more than four buttons, use the joyGetPosEx function."
Link: http://msdn.microsoft.com/en-us/library/windows/desktop/dd757107(v=vs.85).aspx
ok, thanks for the info guys, wasn't certain how old this part of the api i was, i'll look into DirectInput.

@Eliad, I've tried the Ex version as well, it returns the same error, even though i've set the dwSize parameter.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
This is a pretty old and (AFAIK) deprecated API. Have you tried DirectInput or XInput?

I thought it was DirectInput that was deprecated (not sure if officially, but it isn't part of modern DirectX versions and Microsoft suggests to move to raw input and XInput instead). And the problem with XInput is that it's geared towards 360-like controllers (if you have a controller that can't be somehow mapped to 360 controls you're screwed).

In any case I doubt support for joyGetPosEx and the like will be gone anytime soon, and it's pretty easy to use. You lose some functionality (e.g. no force feedback), but a lot of programs use it for simple joystick input.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
I believe DirectInput is only officially deprecated for keyboard and mouse input ... but I agree with Sik-the-hedgehog, even though those are really old API calls I'd be surprised if they couldn't be gotten to work. If I were the OP, I guess I'd look for old sample code that uses those calls and see if the sample app works, if you can find one.
i've looked at sdl's joystick source code on windows, it uses the same simple case as above essentially, although i haven't compiled an sdl app with joystick support(so i can't test to see if sdl somehow makes it work unfortunately), i would personally prefer to actually use this api for the backend support so i'm not limited 360 controllers(i'm also trying to distance myself from anything that is directX related as that's windows only, and i'd like to eventually target more platforms), i've currently implemented XInput, which for now meets my needs i suppose.

i'd also like to ask if anyone else can compile the above(requires linking to winmm.lib) and get it to actually return data?

as for DirectInput, i think i'll skip over that for xinput for now.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

This is a pretty old and (AFAIK) deprecated API. Have you tried DirectInput or XInput?


Does XInput support joysticks or only gamepads? As of now, I'm using DI, was looking at XI, but it seems to only work with gamepads.
(i'm also trying to distance myself from anything that is directX related as that's windows only, and i'd like to eventually target more platforms)

By using the Windows API you're kind of limiting yourself to Windows already =P You'd be better off ditching that immediately and go with SDL directly if that's your goal. SDL works perfectly fine on Windows after all, and already should handle a lot of weird cases where things don't work as expected (on everything, not just joysticks, mind you).

Does XInput support joysticks or only gamepads? As of now, I'm using DI, was looking at XI, but it seems to only work with gamepads.

XInput only supports 360 controllers (well, or anything that the driver can make look like one).
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

This topic is closed to new replies.

Advertisement