Jump to content
  • Advertisement
Sign in to follow this  
chadmv

[.net] DirectInput .NET 2.0

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

Does anyone know where the DirectInput Device guids are located in .NET 2.0? They used to be SystemGuid.* but now I have no idea where they are. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Microsoft.DirectX.DirectInput ?

here's a link. hope it helps.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/microsoft.directx.directinput.asp

Share this post


Link to post
Share on other sites
Quote:
Original post by Alpha_ProgDes
Microsoft.DirectX.DirectInput ?

here's a link. hope it helps.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/microsoft.directx.directinput.asp

Nah, that's for .NET 1.1 and the August SDK. But I figured out how to do it. Here's what I did in case anyone's interested:

Guid guid = new Guid();
InputList<DeviceInstance> inputList = Manager.Devices;
foreach ( DeviceInstance d in inputList )
{
if ( d.ProductName == "Mouse" )
{
guid = d.Product;
break;
}
}

Share this post


Link to post
Share on other sites
Hi, I actually did the same thing, but I was using the DeviceInstance.Instance property. But it doesen't matter wether I user DeviceInstance.Instance or DeviceInstance.Product I always get an Exception when trying to aquire the device: "Value does not fall within the expected range!".
The code worked flawlessly with the .NET 1.1 MDX-SDK. Anyone else experiencing this kind of problem?

Share this post


Link to post
Share on other sites
Quote:
Original post by Maddin
Hi, I actually did the same thing, but I was using the DeviceInstance.Instance property. But it doesen't matter wether I user DeviceInstance.Instance or DeviceInstance.Product I always get an Exception when trying to aquire the device: "Value does not fall within the expected range!".
The code worked flawlessly with the .NET 1.1 MDX-SDK. Anyone else experiencing this kind of problem?
Yeah, I had that problem, you have to set the data format like in unmanaged.

Share this post


Link to post
Share on other sites
I have encountered the same problem. But the solution you presented won't work in every case as some device names may be localized. I tried to check the device type of the DeviceInstance, but there was no match.
DeviceType of mouse: 274
DeviceType of keyboard: 1043

And these are the possible values of the DeviceType enumeration:

public enum DeviceType
{
LimitedGameSubtype = 1,
Device = 17,
Mouse = 18,
Keyboard = 19,
Joystick = 20,
Gamepad = 21,
Driving = 22,
Flight = 23,
FirstPerson = 24,
DeviceControl = 25,
ScreenPointer = 26,
Remote = 27,
Supplemental = 28,
}



Does anybody know a different solution?

Share this post


Link to post
Share on other sites
I developed something which seems to work fine:

Guid keyboardGuid = new Guid();
InputList<DeviceInstance> deviceInstances = Manager.GetDevices(DeviceType.Keyboard, EnumDevicesFlags.AllDevices);
if (deviceInstances.Count >= 1)
keyboardGuid = deviceInstances[0].Instance;





I don't know whether this is the officially proposed method but at least you avoid comparing strings.

Share this post


Link to post
Share on other sites
Looks like I'm the only one who's not able to acquire the created devices. I use the following code and I still always get an "Value does not fall within the expected range" - exception when trying to acquire the device. The code lies directly within my form-class, so this.Handle points to the handle of the form.


public void CreateDevices()
{
InputList<DeviceInstance> inputlist = Manager.GetDevices(DeviceClass.Keyboard, EnumDevicesFlags.AttachedOnly);
if (inputlist.Count > 0)
{
try
{
m_keyboard = new Device(inputlist[0].Instance);
try
{
m_keyboard.SetCooperativeLevel(this.Handle, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
m_keyboard.Acquire();
MessageBox.Show("Keyboard-Device acquired");
}
catch (Exception e2)
{
MessageBox.Show("Could not acquire device : " + e2.ToString());
}
}
catch (Exception e)
{
MessageBox.Show("Could not create device " + inputlist[0] + ": " + e.ToString());
}
}
}




Anyone has a solution for this?

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Maddin
Looks like I'm the only one who's not able to acquire the created devices. I use the following code and I still always get an "Value does not fall within the expected range" - exception when trying to acquire the device. The code lies directly within my form-class, so this.Handle points to the handle of the form.

*** Source Snippet Removed ***

Anyone has a solution for this?

Thanks


You just need to add one line of code (put this before you try to acquire the device):

m_keyboard.SetDataFormat(DeviceDataFormat.Keyboard);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!