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

DirectInput

Started by code_swimmer Dec 19, 2008 at 4:22 PM 5 replies 750+ views
Original Post
code_swimmer
code_swimmer
Hello everyone! This is my first post so please inform me if I do not adhere to the forum etiquette. I am writing a class to read generic usb gamepads/joysticks mainly as a wrapper to xna but I am trying to make it general purpose. I am using BufferedInput to make my class event base, but I am also adding a custom poll function to retrieve immediate values. First, I wanted to get all available axes/buttons/pov etc. So I enumerate through the device objects and add them to a list along with it's name (Button 1, Axis X, etc). This works great, and when I read the BufferedInput I can cross reference everything against my list to see which input was changed. However, my last 4 buttons are not in the Objects collection of the device, yet they are in the BufferedInput. Does anyone have experience using BufferedInput or know of a better way to accomplish this? I apologize for the long post, but I have been all over the internet trying to see if this has occurred to anyone else.
code_swimmer
code_swimmer
Maybe some code would help:

            foreach (DeviceObjectInstance doi in m_device.Objects)            {                if (!GamePadObjects.ContainsKey(doi.Offset)) GamePadObjects.Add(doi.Offset, doi.Name);            }


And the code to read the BufferedInput:
            BufferedDataCollection bdc;            bdc = m_device.GetBufferedData();            if (bdc != null)            {                foreach (BufferedData bd in bdc)                {                    if (Objects.ContainsKey(bd.Offset))                    {                        Console.WriteLine(Objects[bd.Offset] + " = " + bd.Data);                    }                    else                    {                        Console.WriteLine("Unknown Input Object: " + bd.Offset);                    }                }            }


If the BufferedData (bd) object's offset is in the list then everything is fine, I am getting correct results (ie Button 1, Button 2, etc). My test controller has four more buttons that are registering in the BufferedInput but not in the m_device.Objects collection. I can read the buttons using a traditional Poll and reading the JoystickState but this does not tell me what axes are being used and such, only how many it has. Please help!!!
DividedByZero
DividedByZero
Waiting for the compulsory abuse from Evil Steve regarding the use of DirectInput....
code_swimmer
code_swimmer
Well I did consider using the raw usb hid library but that is way beyond my expertise, and it seems like an overly complicated method for achieving my goal, when I plan on using the XNA framework for the rest of my engine.
MJP
MJP
Perhaps you should have a look at this?
MJP
MJP
Quote:
Original post by lonewolff
Waiting for the compulsory abuse from Evil Steve regarding the use of DirectInput....


Nah he'd only do that if he were using DirectInput for keyboard and mouse input, which isn't the case here. :P
code_swimmer
code_swimmer
Quote:
Original post by MJP
Perhaps you should have a look at this?


Thank you, I will definitely look at the source for that. It's not the approach I really wanted to take, but seems to be the most efficient.

Topic Locked

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

Sign in to reply to this topic.