Found 2 DirectInput devices:

0: 'Keyboard' axes: 0, hats: 0, buttons: 256 (buffered)
   1: 'Mouse' axes: 3, hats: 0, buttons: 8 (buffered)

So let's get this straight:
Left, Right, and Middle clicks work.
Wheel Up and Wheel Down work.
X/Y axis doesn't seem to work yet.
This commit is contained in:
AJ Kelly
2011-02-14 17:08:29 -06:00
parent 5597b86887
commit 641777ddf7
8 changed files with 168 additions and 101 deletions
-2
View File
@@ -559,9 +559,7 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
vector<InputDeviceInfo> vDevices;
INPUTMAN->GetDevicesAndDescriptions(vDevices);
//
// fill vector with all auto mappings
//
vector<AutoMappings> vAutoMappings;
{
// file automaps - Add these first so that they can match before the hard-coded mappings
+6 -6
View File
@@ -38,7 +38,7 @@ RageInput::RageInput()
RageInput::~RageInput()
{
/* Delete optional devices. */
// Delete optional devices.
for( unsigned i = 0; i < m_InputHandlers.size(); ++i )
delete m_InputHandlers[i].m_pDevice;
m_InputHandlers.clear();
@@ -55,28 +55,28 @@ void RageInput::LoadDrivers()
m_InputHandlers.clear();
g_mapDeviceToHandler.clear();
/* Init optional devices. */
// Init optional devices.
vector<InputHandler *> apDevices;
InputHandler::Create( g_sInputDrivers, apDevices );
for( unsigned i = 0; i < apDevices.size(); ++i )
AddHandler( apDevices[i] );
/* If no input devices are loaded, the user won't be able to input anything. */
// If no input devices are loaded, the user won't be able to input anything.
if( apDevices.size() == 0 )
LOG->Warn( "No input devices were loaded." );
}
void RageInput::Update()
{
/* Update optional devices. */
// Update optional devices.
for( unsigned i = 0; i < m_InputHandlers.size(); ++i )
m_InputHandlers[i].m_pDevice->Update();
}
bool RageInput::DevicesChanged()
{
/* Update optional devices. */
// Update optional devices.
for( unsigned i = 0; i < m_InputHandlers.size(); ++i )
{
if( m_InputHandlers[i].m_pDevice->DevicesChanged() )
@@ -111,7 +111,7 @@ void RageInput::AddHandler( InputHandler *pHandler )
g_mapDeviceToHandler[idi->id] = pHandler;
}
/* Return the first InputDriver for the requested InputDevice. */
/** @brief Return the first InputDriver for the requested InputDevice. */
InputHandler *RageInput::GetHandlerForDevice( const InputDevice id )
{
map<InputDevice, InputHandler *>::iterator it = g_mapDeviceToHandler.find(id);
+2 -2
View File
@@ -130,10 +130,10 @@ static void InitNames()
g_mapNamesToString[MOUSE_LEFT] = "left mouse button";
g_mapNamesToString[MOUSE_RIGHT] = "right mouse button";
g_mapNamesToString[MOUSE_MIDDLE] = "middle mouse button";
g_mapNamesToString[MOUSE_FORWARD] = "forward mouse button";
g_mapNamesToString[MOUSE_BACK] = "back mouse button";
g_mapNamesToString[MOUSE_WHEELUP] = "mousewheel up";
g_mapNamesToString[MOUSE_WHEELDOWN] = "mousewheel down";
g_mapNamesToString[MOUSE_FORWARD] = "forward mouse button";
g_mapNamesToString[MOUSE_BACK] = "back mouse button";
FOREACHM( DeviceButton, RString, g_mapNamesToString, m )
g_mapStringToNames[m->second] = m->first;
+5
View File
@@ -297,6 +297,11 @@ enum DeviceButton
MOUSE_WHEELUP, MOUSE_WHEELDOWN,
// for mice with forward and backwards buttons
MOUSE_FORWARD, MOUSE_BACK,
// axis
MOUSE_X_LEFT, MOUSE_X_RIGHT,
MOUSE_Y_UP, MOUSE_Y_DOWN,
// mousewheel?
MOUSE_Z_UP, MOUSE_Z_DOWN,
NUM_DeviceButton,
DeviceButton_Invalid
+1 -3
View File
@@ -163,7 +163,7 @@ static LocalizedString DEBUG_MENU( "ScreenDebugOverlay", "Debug Menu" );
void ScreenDebugOverlay::Init()
{
Screen::Init();
// Init debug mappings
// TODO: Arch-specific?
{
@@ -539,7 +539,6 @@ void ChangeVisualDelay( float fDelta )
pRet->Set( fSecs );
}
// DebugLines
static LocalizedString AUTO_PLAY ( "ScreenDebugOverlay", "AutoPlay" );
static LocalizedString ASSIST ( "ScreenDebugOverlay", "Assist" );
@@ -579,7 +578,6 @@ static LocalizedString SONG ( "ScreenDebugOverlay", "Song" );
static LocalizedString MACHINE ( "ScreenDebugOverlay", "Machine" );
static LocalizedString SYNC_TEMPO ( "ScreenDebugOverlay", "Tempo" );
class DebugLineAutoplay : public IDebugLine
{
virtual RString GetDisplayTitle() { return AUTO_PLAY.GetValue() + " (+Shift = AI) (+Alt = hide)"; }
@@ -307,71 +307,71 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
switch(in.type)
{
case in.BUTTON:
{
DeviceInput di( dev, enum_add2(JOY_BUTTON_1, in.num), !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0], tm );
ButtonPressed( di );
break;
}
case in.AXIS:
{
DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid;
int val = 0;
switch( in.ofs )
case in.BUTTON:
{
case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT;
val = state.lX;
break;
case DIJOFS_Y: neg = JOY_UP; pos = JOY_DOWN;
val = state.lY;
break;
case DIJOFS_Z: neg = JOY_Z_UP; pos = JOY_Z_DOWN;
val = state.lZ;
break;
case DIJOFS_RX: neg = JOY_ROT_LEFT; pos = JOY_ROT_RIGHT;
val = state.lRx;
break;
case DIJOFS_RY: neg = JOY_ROT_UP; pos = JOY_ROT_DOWN;
val = state.lRy;
break;
case DIJOFS_RZ: neg = JOY_ROT_Z_UP; pos = JOY_ROT_Z_DOWN;
val = state.lRz;
break;
case DIJOFS_SLIDER(0):
neg = JOY_AUX_1; pos = JOY_AUX_2;
val = state.rglSlider[0];
break;
case DIJOFS_SLIDER(1):
neg = JOY_AUX_3; pos = JOY_AUX_4;
val = state.rglSlider[1];
break;
default: LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs );
continue;
}
if( neg != DeviceButton_Invalid )
{
float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f );
ButtonPressed( DeviceInput(dev, neg, max(-l,0), tm) );
ButtonPressed( DeviceInput(dev, pos, max(+l,0), tm) );
DeviceInput di( dev, enum_add2(JOY_BUTTON_1, in.num), !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0], tm );
ButtonPressed( di );
break;
}
break;
}
case in.HAT:
if( in.num == 0 )
case in.AXIS:
{
const int pos = TranslatePOV( state.rgdwPOV[in.ofs - DIJOFS_POV(0)] );
ButtonPressed( DeviceInput(dev, JOY_HAT_UP, !!(pos & HAT_UP_MASK), tm) );
ButtonPressed( DeviceInput(dev, JOY_HAT_DOWN, !!(pos & HAT_DOWN_MASK), tm) );
ButtonPressed( DeviceInput(dev, JOY_HAT_LEFT, !!(pos & HAT_LEFT_MASK), tm) );
ButtonPressed( DeviceInput(dev, JOY_HAT_RIGHT, !!(pos & HAT_RIGHT_MASK), tm) );
DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid;
int val = 0;
switch( in.ofs )
{
case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT;
val = state.lX;
break;
case DIJOFS_Y: neg = JOY_UP; pos = JOY_DOWN;
val = state.lY;
break;
case DIJOFS_Z: neg = JOY_Z_UP; pos = JOY_Z_DOWN;
val = state.lZ;
break;
case DIJOFS_RX: neg = JOY_ROT_LEFT; pos = JOY_ROT_RIGHT;
val = state.lRx;
break;
case DIJOFS_RY: neg = JOY_ROT_UP; pos = JOY_ROT_DOWN;
val = state.lRy;
break;
case DIJOFS_RZ: neg = JOY_ROT_Z_UP; pos = JOY_ROT_Z_DOWN;
val = state.lRz;
break;
case DIJOFS_SLIDER(0):
neg = JOY_AUX_1; pos = JOY_AUX_2;
val = state.rglSlider[0];
break;
case DIJOFS_SLIDER(1):
neg = JOY_AUX_3; pos = JOY_AUX_4;
val = state.rglSlider[1];
break;
default: LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs );
continue;
}
if( neg != DeviceButton_Invalid )
{
float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f );
ButtonPressed( DeviceInput(dev, neg, max(-l,0), tm) );
ButtonPressed( DeviceInput(dev, pos, max(+l,0), tm) );
}
break;
}
break;
case in.HAT:
if( in.num == 0 )
{
const int pos = TranslatePOV( state.rgdwPOV[in.ofs - DIJOFS_POV(0)] );
ButtonPressed( DeviceInput(dev, JOY_HAT_UP, !!(pos & HAT_UP_MASK), tm) );
ButtonPressed( DeviceInput(dev, JOY_HAT_DOWN, !!(pos & HAT_DOWN_MASK), tm) );
ButtonPressed( DeviceInput(dev, JOY_HAT_LEFT, !!(pos & HAT_LEFT_MASK), tm) );
ButtonPressed( DeviceInput(dev, JOY_HAT_RIGHT, !!(pos & HAT_RIGHT_MASK), tm) );
}
break;
}
}
}
@@ -383,7 +383,6 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
return;
// do button checks here
for( unsigned i = 0; i < device.Inputs.size(); ++i )
{
const input_t &in = device.Inputs[i];
@@ -392,9 +391,40 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
switch(in.type)
{
case in.BUTTON:
{
DeviceInput di( dev, enum_add2(MOUSE_LEFT, in.num), !!state.rgbButtons[in.ofs - DIMOFS_BUTTON0], tm );
ButtonPressed( di );
break;
}
case in.AXIS:
{
DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid;
int val = 0;
switch( in.ofs )
{
case DIMOFS_X: neg = MOUSE_X_LEFT; pos = MOUSE_X_RIGHT;
val = state.lX;
break;
case DIMOFS_Y: neg = MOUSE_Y_UP; pos = MOUSE_Y_DOWN;
val = state.lY;
break;
case DIMOFS_Z: neg = MOUSE_Z_UP; pos = MOUSE_Z_DOWN;
val = state.lZ;
break;
default: LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset, %i",
device.m_sName.c_str(), in.ofs );
continue;
}
if( neg != DeviceButton_Invalid )
{
float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f );
ButtonPressed( DeviceInput(dev, neg, max(-l,0), tm) );
ButtonPressed( DeviceInput(dev, pos, max(+l,0), tm) );
}
break;
}
}
}
break;
@@ -427,7 +457,6 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
return;
}
// todo: update for mouse? -aj
for( int i = 0; i < (int) numevents; ++i )
{
for(unsigned j = 0; j < device.Inputs.size(); ++j)
@@ -445,7 +474,6 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
break;
case in.BUTTON:
// hope this works...
if(dev == DEVICE_MOUSE)
{
DeviceButton mouseInput = DeviceButton_Invalid;
@@ -455,12 +483,8 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
case DIMOFS_BUTTON1: mouseInput = MOUSE_RIGHT; break;
case DIMOFS_BUTTON2: mouseInput = MOUSE_MIDDLE; break;
//case DIMOFS_BUTTON3: break;
// todo: handle directions
case DIMOFS_X: break;
case DIMOFS_Y: break;
case DIMOFS_Z: break;
default: LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset, %i",
"Mouse '%s' is returning an unknown mouse offset [button], %i",
device.m_sName.c_str(), in.ofs );
continue;
}
@@ -473,20 +497,37 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
case in.AXIS:
{
DeviceButton up = DeviceButton_Invalid, down = DeviceButton_Invalid;
switch(in.ofs)
if(dev == DEVICE_MOUSE)
{
case DIJOFS_X: up = JOY_LEFT; down = JOY_RIGHT; break;
case DIJOFS_Y: up = JOY_UP; down = JOY_DOWN; break;
case DIJOFS_Z: up = JOY_Z_UP; down = JOY_Z_DOWN; break;
case DIJOFS_RX: up = JOY_ROT_UP; down = JOY_ROT_DOWN; break;
case DIJOFS_RY: up = JOY_ROT_LEFT; down = JOY_ROT_RIGHT; break;
case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break;
case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break;
case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break;
default: LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs );
continue;
switch(in.ofs)
{
case DIMOFS_X: up = MOUSE_X_LEFT; down = MOUSE_X_RIGHT; break;
case DIMOFS_Y: up = MOUSE_Y_UP; down = MOUSE_Y_DOWN; break;
case DIMOFS_Z: up = MOUSE_Z_UP; down = MOUSE_Z_DOWN; break;
default: LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown mouse offset [axis], %i",
device.m_sName.c_str(), in.ofs );
continue;
}
}
else
{
switch(in.ofs)
{
// joystick
case DIJOFS_X: up = JOY_LEFT; down = JOY_RIGHT; break;
case DIJOFS_Y: up = JOY_UP; down = JOY_DOWN; break;
case DIJOFS_Z: up = JOY_Z_UP; down = JOY_Z_DOWN; break;
case DIJOFS_RX: up = JOY_ROT_UP; down = JOY_ROT_DOWN; break;
case DIJOFS_RY: up = JOY_ROT_LEFT; down = JOY_ROT_RIGHT; break;
case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break;
case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break;
case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break;
default: LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs );
continue;
}
}
float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f );
@@ -24,7 +24,6 @@ DIDevice::DIDevice()
dev = InputDevice_Invalid;
buffered = true;
memset(&JoystickInst, 0, sizeof(JoystickInst));
memset(&MouseInst, 0, sizeof(MouseInst));
Device = NULL;
}
@@ -100,7 +99,7 @@ bool DIDevice::Open()
}
break;
case MOUSE:
Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_PSHBUTTON );
Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS );
break;
}
@@ -191,7 +190,7 @@ static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev
dilong.dwData = 0;
hr = device->Device->SetProperty( DIPROP_DEADZONE, &dilong.diph );
if ( hr != DI_OK )
return DIENUM_CONTINUE; /* don't use this axis */
return DIENUM_CONTINUE; // don't use this axis
device->axes++;
}
@@ -323,21 +322,49 @@ static int ConvertScancodeToKey( int scancode )
static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data)
{
DIDevice *device = (DIDevice *) data;
//HRESULT hr;
input_t in;
// todo: check mask for accuracy -aj
const int SupportedMask = DIDFT_BUTTON;
const int SupportedMask = DIDFT_BUTTON | DIDFT_AXIS;
if(!(dev->dwType & SupportedMask))
return DIENUM_CONTINUE; // unsupported
in.ofs = dev->dwOfs;
// xxx: does this check for scrollwheels? -aj
if(dev->dwType & DIDFT_BUTTON ) {
if(dev->dwType & DIDFT_BUTTON)
{
in.type = in.BUTTON;
in.num = device->buttons;
device->buttons++;
}
else if(dev->dwType & DIDFT_AXIS)
{
LOG->Trace("found a mouse axis");
// todo: how to handle this correctly? -aj
//DIPROPRANGE diprg;
in.type = in.AXIS;
in.num = device->axes;
/*
diprg.diph.dwSize = sizeof(diprg);
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
diprg.diph.dwObj = dev->dwOfs;
diprg.diph.dwHow = DIPH_BYOFFSET;
diprg.lMin = -100;
diprg.lMax = 100;
hr = device->Device->SetProperty( DIPROP_RANGE, &diprg.diph );
if ( hr != DI_OK )
{
LOG->Trace("error setting properties on mouse axis");
return DIENUM_CONTINUE; // don't use this axis
}
*/
device->axes++;
}
device->Inputs.push_back(in);
@@ -23,11 +23,9 @@ typedef struct input_t
struct DIDevice
{
DIDEVICEINSTANCE JoystickInst;
DIDEVICEINSTANCE MouseInst;
LPDIRECTINPUTDEVICE2 Device;
RString m_sName;
//enum { KEYBOARD, JOYSTICK } type;
enum { KEYBOARD, JOYSTICK, MOUSE } type;
bool buffered;