Sign in to follow this  

Joystick Input with DirectInput

This topic is 4162 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

Hi guys. I'm using MDX and am wondering how I can get the GUID for use with the Device(GUID) constructor. For keyboard and mouse, I use SystemGuid.Keyboard or SystemGuid.Mouse, but what do I use for a joystick? Thanks.

Share this post


Link to post
Share on other sites
The 'system' mouse and keyboard are always present under Windows, which is why there are pre-defined GUIDs for them.

Joysticks are optional, there are multiple types, and having more than one installed/connected at a time is more common than it is with the keyboard and mouse.

For this reason, you need to enumerate all of the "game controller" input devices on the system, and choose the GUID of the one you want to use.

The following code from the "Joystick" sample in the DirectX SDK enumerates the game controller/joystick devices in the system and creates a DirectInput device using the GUID of the first device it finds:


// Enumerate Joysticks in the system.
foreach (DeviceInstance instance in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly))
{
// Create the device. Just pick the first one
applicationDevice = new Device(instance.InstanceGuid);
break;
}



(using Microsoft.DirectX.DirectInput)

Share this post


Link to post
Share on other sites
Thanks. I have another question. What do the different CooperativeLevelFlags mean? I've been using Background and NonExclusive because that's what some of the sample projects I have found use, but I don't know what they mean.

Share this post


Link to post
Share on other sites
Quote:
Original post by yaroslavd
Thanks. I have another question. What do the different CooperativeLevelFlags mean? I've been using Background and NonExclusive because that's what some of the sample projects I have found use, but I don't know what they mean.


Background: the device can be used & acquired even when your application window isn't active/in the foreground.

Foreground: the device can only be used & acquired when your application window is active/in the foreground. When your window loses focus, the device is unacquired.

Exclusive: only your application has access to the device - nobody else can acquire it while you have exclusive access. NB: with this flag you still need to handle re-acquiring the device if it becomes unacquired.

NonExclusive: you're happy for other running applications to use the device too.

NoWindowsKey: stops the Windows key from bringing up a context menu (and so interrupting gameplay) for keyboard devices.


For a fullscreen game for your joystick, you'd likely want Foreground/Exclusive, and for a windowed game, you'd likely want Foreground/NonExclusive.

For the keyboard in windowed mode, disabling the Windows key isn't a 'friendly' thing to do. In fullscreen you usually would want to.

Share this post


Link to post
Share on other sites

This topic is 4162 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