Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

windows api and joystick reading


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 slicer4ever   Crossbones+   -  Reputation: 1458

Like
0Likes
Like

Posted 03 May 2012 - 09:26 PM

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;
}

Edited by slicer4ever, 03 May 2012 - 09:27 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 7668

Like
0Likes
Like

Posted 03 May 2012 - 11:54 PM

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

#3 Eliad Moshe   Members   -  Reputation: 485

Like
0Likes
Like

Posted 04 May 2012 - 04:21 AM

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

#4 slicer4ever   Crossbones+   -  Reputation: 1458

Like
0Likes
Like

Posted 04 May 2012 - 10:19 AM

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.

#5 Sik_the_hedgehog   Members   -  Reputation: 957

Like
0Likes
Like

Posted 04 May 2012 - 02:40 PM

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.

#6 jwezorek   Crossbones+   -  Reputation: 1334

Like
0Likes
Like

Posted 04 May 2012 - 03:24 PM

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.

#7 slicer4ever   Crossbones+   -  Reputation: 1458

Like
0Likes
Like

Posted 04 May 2012 - 04:59 PM

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.

#8 jfalstaff   Members   -  Reputation: 101

Like
0Likes
Like

Posted 05 May 2012 - 03:13 AM

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.

Edited by jfalstaff, 05 May 2012 - 03:14 AM.


#9 Sik_the_hedgehog   Members   -  Reputation: 957

Like
0Likes
Like

Posted 05 May 2012 - 02:41 PM

(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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS