Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] DirectInput .NET 2.0

Started by chadmv Dec 18, 2005 at 5:32 PM 11 replies 4.5k views
Original Post
chadmv
chadmv
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
Alpha_ProgDes
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
Beginner in Game Development?  Read here. And read here.  
chadmv
chadmv
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;    }}
Maddin
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?
chadmv
chadmv
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.

SlimTimmy
SlimTimmy
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?
SlimTimmy
SlimTimmy
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.
Maddin
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.

        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
SlimTimmy
SlimTimmy
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);
Maddin
Maddin
Thanks a lot. That was, what I was missing. Now it works...
GregWoods
GregWoods
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.