Joystick/controller input???

Pages: 12
Hello guys,

I was wondering if there was any simple (or at least fairly basic) way to get input from a joystick or controller that's plugged into your computer. In Game Editor (a 2d game engine), you use two functions called: getjoystickbutton(int) and getjoystickaxis(int). These functions will return values such as whether a button is pressed or how far on the x axis a joystick has been moved. Is there a basic way for me to make similar functions? Thank you in advance =D

SuperSonic
If this is for Windows, have a look at DirectInput: http://msdn.microsoft.com/en-us/library/windows/desktop/ee416842(v=vs.85).aspx .

I don't have suggestions for any other OS.
Thanks =D

And yes, it is for Windows
Umm, I'm sorry for the dumb question, but where do I downlaod DirectInput? I can't find the answer anywhere =?
AFAIK, it is installed with Windows, so all you should need is the Windows SDK. For example, I have dinput.h in my Windows SDK 7.0 include folder.

I must tell you, though, that I have never used it so I may be wrong.
Also, there is the old Joystick API
http://www.google.com/search?btnI=1&q=msdn+Joysticks

Hope this helps.
Thanks guys. I'll try to see if I can get it to work in the morning =)
Get a game lib.

SFML has easy and crossplatform joystick support

http://www.sfml-dev.org
I was thinking about a game lib. But then I decided not to for the simple reason that I only want joystick support and I don't want to mess with graphics and stuff. But thank you for your tip. I'll definitely check it out later =D
AFAIK, it is installed with Windows, so all you should need is the Windows SDK. For example, I have dinput.h in my Windows SDK 7.0 include folder.

Ok, another silly question. I don't even know if I have a windows sdk =? Do I have to download it or something?

please note that I have little experience with libraries other than iostream so could you please explain in detail? Thanks =D
Last edited on
What compiler and version are you using?
If you are using Visual Studio 2010, your Windows SDK is current; no need for downloading. If you have Visual Studio 2008, your SDK is for Windows Vista; you should download the latest SDK.

I don't know if other compilers/IDE's come with the SDK or not, so to be on the safe side you might want to download it.
I'm using Code::Blocks so I don't think I have the sdk. Is it easy to download?
Code::Blocks is an IDE that works with many different compilers, but it tends to come bundled with the GCC, which on Windows would be called "MinGW".

The Windows SDK is not magical -- it has to be properly implemented for each compiler. Hence, we need to know what compiler you are using.

If it is MinGW, then one of these is correct: http://sourceforge.net/projects/mingw/files/MinGW/Base/w32api/
You need to determine the version of your compiler to get the correct WinAPI kit.
Duoas wrote:
The Windows SDK is not magical -- it has to be properly implemented for each compiler. Hence, we need to know what compiler you are using.


Wow, really??? I really thought it was! I guess that's what I get for never using anything else than Visual Studio.

Do you know what are the changes made? Just out of curiosity. I really don't NEED to know.
Right now, I'm using Code::Blocks ver 10.05. What version of the api should I download?
I am pretty sure that DirectInput is part of the DirectX SDK. The DirectX SDK may be a part of the windows sdk, but downloading it just for DirectInput seems a bit like a waste.

Oh, and there's really no easy way of getting Joystick input, even when you're using DirectInput (actually, especially when you're using DirectInput - it's not exactly straight forward).
@webJose
It depends on how the compiler links to external symbols, and on how to properly define and align types. That's all.
Last edited on

Oh, and there's really no easy way of getting Joystick input, even when you're using DirectInput (actually, especially when you're using DirectInput - it's not exactly straight forward).


Nothing involving MS Windows is straight forward.
Bull.
Pages: 12