[.net] DirectInput .NET 2.0

Started by
11 comments, last by GregWoods 15 years, 3 months ago
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
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

Beginner in Game Development?  Read here. And read here.

 

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

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?
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.
Nice, I'll probably use that method instead.
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
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);

This topic is closed to new replies.

Advertisement