Sign in to follow this  

[.net] DirectInput .NET 2.0

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

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
Guest Anonymous Poster
DirectInput Device guids are back in their original location (SystemGuid.*) as from April 2006 release

They had been unintentionally removed from the previous releases.

Cheers

Share this post


Link to post
Share on other sites
OK, so this post is 4 years old, but I'm new to DirectInput (I'm using it through SlimDX), and I too was confused by the DeviceType Enumeration http://msdn.microsoft.com/en-us/library/ms836016.aspx (the one where a Mouse is 18, and a keyboard 19). Yet when a wrote a small application to enumerate the DeviceInstance 'Type' property, I got 1043 for keyboard and 274 for mouse - as SlimTimmy mentioned in his post.

Then I found this page, which clears it up...
http://msdn.microsoft.com/en-us/library/ms835109.aspx
"Device type specifier. The least-significant byte of the device type description code specifies the device type. The next-significant byte specifies the device subtype. This value can also be combined with DIDEVTYPE_HID, which specifies a Human Interface Device (TermHid)."

So using windows calc to do some quick decimal-hex conversions, we can see:

Mouse 274dec -> 0112hex -> least sig byte = 12hex -> 18dec (Mouse)
Keyboard 1043dec -> 0413hex -> least sig byte = 13hex -> 19dec (Keyboard)
Comfort Curve Keyboard 2000 -> 65553dec -> 010011hex -> least sig byte = 11hex -> 17dec (Device)

This info may or may not be of use, but I thought I'd post it anyway.

Greg

Share this post


Link to post
Share on other sites

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