xboxscene.org forums

Author Topic: Gamepad/mouse Detection  (Read 30 times)

lubby

  • Archived User
  • Newbie
  • *
  • Posts: 10
Gamepad/mouse Detection
« on: February 16, 2004, 02:52:00 AM »

If you are talking about initialisation at XInitDevices() then no, there is no way to know what devices are currently plugged in. You need to check the bit array results from the function XGetDeviceChanges() to find currently 'inserted' devices.
This is a bit of a hassle as you need to alloc enough resources to support all possible combinations.. could be 4x keyboard, 4x mouse and 4 x gamepads.


Logged

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
Gamepad/mouse Detection
« Reply #1 on: February 16, 2004, 03:02:00 AM »

QUOTE (lubby @ Feb 16 2004, 07:52 AM)
If you are talking about initialisation at XInitDevices() then no, there is no way to know what devices are currently plugged in. You need to check the bit array results from the function XGetDeviceChanges() to find currently 'inserted' devices.
This is a bit of a hassle as you need to alloc enough resources to support all possible combinations.. could be 4x keyboard, 4x mouse and 4 x gamepads.

Actually, you only need to support 1 keyboard and 1 mouse.

These allocated spaces will only be taken by the first detected keyboard and mouse. "extras" will be ignored.

You need to allocate for 4 controllers, though.
Logged

BenJeremy

  • Archived User
  • Hero Member
  • *
  • Posts: 5645
Gamepad/mouse Detection
« Reply #2 on: February 16, 2004, 04:53:00 AM »

QUOTE (p0pp @ Feb 16 2004, 09:41 AM)
Actually my problem comes when I want to know what port the mouse is plugged into.  Having a bit array will only tell you that there is a mouse present, but not where.  Is there a way to tell without a doubt what port it is in?

The API does, absolutely, tell you where it's plugged in. Read the XDK help files.

You seem to have a problem understanding how XGetDeviceChanges() works. It's really VERY VERY SIMPLE. It returns a bitmap of the insertions and deletions. Examples are in the XDK help.

Read up on it.

Logged

lubby

  • Archived User
  • Newbie
  • *
  • Posts: 10
Gamepad/mouse Detection
« Reply #3 on: February 16, 2004, 05:44:00 PM »

CODE


if TRUE == XGetDeviceChanges( XDEVICE_TYPE_GAMEPAD, &insertions, &removals ); // returns true is the function call was a sucess

for int i=0;i<4;i++
{
    // check for removals first
   if( removals & (1<    {
     // device type gamepad was removed from port # i
     XInputClose(...);
   }
   
   if ( insertions & (1<    {
     // device type of gamepad was inserted in port # i
     XInputOpen(XDEVICE_TYPE_GAMEPAD, ...);
   }
}

thats basically all there is to is.. Obviously things are a little different for kb and mouse but its mosltly the same. Ports are numbered 0 through 3 with 0 being the first of the left.

Something interesting here, most other gaming devices are detected as type gampad. You can check if a wheel/snowboard/lightgun or whatever is inserted by calling XInputGetCapabilities() passing the device handle returned by XInputOpen and a XINPUT_CAPABILITIES structure.

for example
CODE

       if (  insertions....

         handle = XInputOpen(XDEVICE_TYPE_GAMEPAD,...)
         XINPUT_CAPABILITIES caps;
         XInputGetCapabilities(handle, &caps);
         
         if( caps.SubType == XINPUT_DEVSUBTYPE_GC_GAMEPAD )
            // its a standard config gamepad inserted
         
         if( caps.SubType == XINPUT_DEVSUBTYPE_GC_SNOWBOARD)
            // its a snowboard inserted

         .. an so on



You will find those defines in xbox.h

Logged