Sign in to follow this  

windows api and joystick reading

This topic is 2046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:

[code]
#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;
}
[/code] Edited by slicer4ever

Share this post


Link to post
Share on other sites
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: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx[/url]


#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: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/dd757107(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/dd757107(v=vs.85).aspx[/url]

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1336110892' post='4937291']This is a pretty old and (AFAIK) deprecated API. Have you tried DirectInput or XInput?[/quote]
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.

Share this post


Link to post
Share on other sites
I believe DirectInput is only[i] officially [/i]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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1336110892' post='4937291']
This is a pretty old and (AFAIK) deprecated API. Have you tried DirectInput or XInput?
[/quote]

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. Edited by jfalstaff

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1336172350' post='4937495'](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)[/quote]
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).

[quote name='jfalstaff' timestamp='1336209207' post='4937572']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.[/quote]
XInput only supports 360 controllers (well, or anything that the driver can make look like one).

Share this post


Link to post
Share on other sites

This topic is 2046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this