Getting Joystick/Gamepad names
by Jaybill · 03/17/2006 (7:01 pm) · 4 comments
winInputDevice.h after line 102:
add:
At the end of winInputDevice.cc add:
In winDirectInput.h, after line 84
add
at the end of winDirectInput.cc, add
And also in winDirectInput.cc after line 472, add:
In winInput.cc after line 150 (After ConsoleFunction( getJoystickAxes ) close brace, add:
So now, in script, you can do the following:
When you run this from the console, you'll get something like the following:
U8 getDeviceID();
add:
U8 getJoystickCount(); const char* getJoystickMname();
At the end of winInputDevice.cc add:
U8 DInputDevice::getJoystickCount()
{
return smJoystickCount;
}
const char* DInputDevice::getJoystickMname()
{
return mName;
}In winDirectInput.h, after line 84
const char* getJoystickAxesString( U32 deviceID );
add
const char* getJoystickName( U32 deviceID ); const char* getJoystickShortname( U32 deviceID );
at the end of winDirectInput.cc, add
//------------------------------------------------------------------------------
ConsoleFunction( getJoystickCount, S32, 1, 1, "getJoystickCount()" )
{
argc; argv;
DInputDevice* dptr;
S32 jcount = static_cast<S32>( dptr->getJoystickCount() );
return jcount;
}And also in winDirectInput.cc after line 472, add:
//------------------------------------------------------------------------------
const char* DInputManager::getJoystickName( U32 deviceID )
{
DInputDevice* dptr;
for ( iterator ptr = begin(); ptr != end(); ptr++ )
{
dptr = dynamic_cast<DInputDevice*>( *ptr );
if ( dptr && ( dptr->getDeviceType() == JoystickDeviceType ) && ( dptr->getDeviceID() == deviceID ) )
return( dptr->getName() );
}
return( "" );
}
//------------------------------------------------------------------------------
const char* DInputManager::getJoystickShortname( U32 deviceID )
{
DInputDevice* dptr;
for ( iterator ptr = begin(); ptr != end(); ptr++ )
{
dptr = dynamic_cast<DInputDevice*>( *ptr );
if ( dptr && ( dptr->getDeviceType() == JoystickDeviceType ) && ( dptr->getDeviceID() == deviceID ) )
return( dptr->getJoystickMname() );
}
return( "" );
}
//------------------------------------------------------------------------------
ConsoleFunction( getJoystickShortname, const char*, 2, 2, "getJoystickShortname( index )" )
{
argc;
DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
if ( mgr )
return( mgr->getJoystickShortname( dAtoi( argv[1] ) ) );
return( "" );
}In winInput.cc after line 150 (After ConsoleFunction( getJoystickAxes ) close brace, add:
//------------------------------------------------------------------------------
ConsoleFunction( getJoystickName, const char*, 2, 2, "getJoystickName( index )" )
{
argc;
DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
if ( mgr )
return( mgr->getJoystickName( dAtoi( argv[1] ) ) );
return( "" );
}So now, in script, you can do the following:
function joystickDump(){
for(%i = 0; %i < getJoystickCount(); %i++){
echo(getJoystickShortname(%i) @ " is a " @ getJoystickName(%i) );
echo("Axis String for " @ getJoystickShortname(%i) @": "@getJoystickAxes(getJoystickShortname(%i)));
}
}When you run this from the console, you'll get something like the following:
==>joystickdump(); joystick0 is a WingMan Cordless Gamepad Axis String for joystick0: 5^S^V^Z^Y^X joystick1 is a GamePad Pro USB Axis String for joystick1: 5^S^V^Z^Y^X
#3
c:\torque\sdk\engine\platformwin32\windirectinput.cc(1042): warning C4700: local variable 'dptr' used without having been initialized
Usually dptr is initialized through some sort of cast, however that is not the case here. Is there a good way to do this without causing further problems? Or should I just ignore the warning?
12/04/2006 (1:58 pm)
Hey guys I have been trying to use this. Although it seems to work fine, I am getting a warning when I compile.c:\torque\sdk\engine\platformwin32\windirectinput.cc(1042): warning C4700: local variable 'dptr' used without having been initialized
//------------------------------------------------------------------------------ConsoleFunction( getJoystickCount, S32, 1, 1, "getJoystickCount()" ){ argc; argv; DInputDevice* dptr; S32 jcount = static_cast<S32>( dptr->getJoystickCount() ); return jcount;}Usually dptr is initialized through some sort of cast, however that is not the case here. Is there a good way to do this without causing further problems? Or should I just ignore the warning?
#4
02/20/2008 (1:02 pm)
I'm really interested in this but I'm getting the same error as Ron above, and to me this is an error that breaks compiling.
Torque Owner Simon Love