diff --git a/src/RageInputDevice.h b/src/RageInputDevice.h index ac46d71152..58e89c2b01 100644 --- a/src/RageInputDevice.h +++ b/src/RageInputDevice.h @@ -294,10 +294,10 @@ enum DeviceButton MOUSE_LEFT = 700, MOUSE_RIGHT, MOUSE_MIDDLE, - // for mice with forward and backwards buttons - MOUSE_FORWARD, MOUSE_BACK, // wheel mice MOUSE_WHEELUP, MOUSE_WHEELDOWN, + // for mice with forward and backwards buttons + MOUSE_FORWARD, MOUSE_BACK, */ NUM_DeviceButton, @@ -354,6 +354,7 @@ public: void MakeInvalid() { device = InputDevice_Invalid; }; bool IsJoystick() const { return ::IsJoystick(device); } + //bool IsMouse() const { return ::IsMouse(device); } }; typedef vector DeviceInputList; diff --git a/src/arch/InputHandler/InputHandler_DirectInput.cpp b/src/arch/InputHandler/InputHandler_DirectInput.cpp index f941745b81..180191f123 100644 --- a/src/arch/InputHandler/InputHandler_DirectInput.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInput.cpp @@ -37,12 +37,6 @@ static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance, switch( device.type ) { - /* - case device.MOUSE: - device.dev = DEVICE_MOUSE; - break; - */ - case device.JOYSTICK: if( g_iNumJoysticks == NUM_JOYSTICKS ) return DIENUM_CONTINUE; @@ -54,6 +48,12 @@ static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance, case device.KEYBOARD: device.dev = DEVICE_KEYBOARD; break; + + /* + case device.MOUSE: + device.dev = DEVICE_MOUSE; + break; + */ } Devices.push_back(device); @@ -383,7 +383,26 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm ) /* case device.MOUSE: DIMOUSESTATE state; + HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state); + 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]; + const InputDevice dev = device.dev; + + 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; + } + } + break; */ } @@ -415,6 +434,7 @@ 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) @@ -428,38 +448,33 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm switch( in.type ) { case in.KEY: - /* - switch( in.num ) - { - // "Joystick with Keyboard" hack - case 115: //s - ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_UP, !!(evtbuf[i].dwData & 0x80), tm) ); - break; - case 120: //x - ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_DOWN, !!(evtbuf[i].dwData & 0x80), tm) ); - break; - case 122: //z - ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_LEFT, !!(evtbuf[i].dwData & 0x80), tm) ); - break; - case 99: //c - ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_RIGHT, !!(evtbuf[i].dwData & 0x80), tm) ); - break; - case 100: //d - ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_BUTTON_1, !!(evtbuf[i].dwData & 0x80), tm) ); - break; - case 101: //e - ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_BUTTON_2, !!(evtbuf[i].dwData & 0x80), tm) ); - break; - default: - */ - ButtonPressed( DeviceInput(dev, (DeviceButton) in.num, !!(evtbuf[i].dwData & 0x80), tm) ); - /* - break; - } - */ + ButtonPressed( DeviceInput(dev, (DeviceButton) in.num, !!(evtbuf[i].dwData & 0x80), tm) ); break; case in.BUTTON: + /* + if(dev == DEVICE_MOUSE) + { + DeviceButton mouseInput = DeviceButton_Invalid; + switch(in.ofs) + { + case DIMOFS_BUTTON0: mouseInput = MOUSE_LEFT; break; + 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", + device.m_sName.c_str(), in.ofs ); + continue; + } + ButtonPressed( DeviceInput(dev, mouseInput, !!evtbuf[i].dwData, tm) ); + } + else + */ ButtonPressed( DeviceInput(dev, enum_add2(JOY_BUTTON_1, in.num), !!evtbuf[i].dwData, tm) ); break; diff --git a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp index d07cb4ed8c..939ad6cc24 100644 --- a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp @@ -16,7 +16,7 @@ LPDIRECTINPUT g_dinput = NULL; static int ConvertScancodeToKey( int scancode ); static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data); -//static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data); +static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data); DIDevice::DIDevice() { @@ -24,6 +24,7 @@ DIDevice::DIDevice() dev = InputDevice_Invalid; buffered = true; memset(&JoystickInst, 0, sizeof(JoystickInst)); + //memset(&MouseInst, 0, sizeof(MouseInst)); Device = NULL; } @@ -51,8 +52,27 @@ bool DIDevice::Open() return false; } - // todo: load mouse + // load mouse + /* + hr = g_dinput->CreateDevice( MouseInst.guidInstance, &tmpdevice, NULL ); + if ( hr != DI_OK ) + { + LOG->Info( hr_ssprintf(hr, "OpenDevice: IDirectInput_CreateDevice") ); + return false; + } + */ + // is this ok? -aj + //hr = tmpdevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *) &Device ); + /* + tmpdevice->Release(); + if ( hr != DI_OK ) + { + LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice::QueryInterface", m_sName.c_str()) ); + return false; + } + */ + // should mouse be foreground? -aj int coop = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; if( type == KEYBOARD ) coop = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND; @@ -86,27 +106,27 @@ bool DIDevice::Open() switch( type ) { - case JOYSTICK: - Device->EnumObjects( DIJoystick_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); - break; - case KEYBOARD: - // Always 256-button. - for( int b = 0; b < 256; ++b ) - { - input_t in; - in.type = in.KEY; + case JOYSTICK: + Device->EnumObjects( DIJoystick_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); + break; + case KEYBOARD: + // Always 256-button. + for( int b = 0; b < 256; ++b ) + { + input_t in; + in.type = in.KEY; - in.num = ConvertScancodeToKey(b); - in.ofs = b; - buttons++; - Inputs.push_back(in); - } - break; - /* - case MOUSE: - Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON ); - break; - */ + in.num = ConvertScancodeToKey(b); + in.ofs = b; + buttons++; + Inputs.push_back(in); + } + break; + /* + case MOUSE: + Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_PSHBUTTON ); + break; + */ } { @@ -325,32 +345,29 @@ static int ConvertScancodeToKey( int scancode ) }; } -/* static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data) { + /* DIDevice *device = (DIDevice *) data; input_t in; // todo: check mask for accuracy -aj - const int SupportedMask = DIDFT_BUTTON; + const int SupportedMask = DIDFT_BUTTON | DIDFT_PSHBUTTON; if(!(dev->dwType & SupportedMask)) return DIENUM_CONTINUE; // unsupported // xxx: does this check for scrollwheels? -aj - if(dev->dwType & DIDFT_BUTTON) { - if( device->buttons == 10 ) - return DIENUM_CONTINUE; // too many buttons - + if(dev->dwType & (DIDFT_BUTTON | DIDFT_PSHBUTTON) ) { in.type = in.BUTTON; in.num = device->buttons; device->buttons++; } device->Inputs.push_back(in); + */ return DIENUM_CONTINUE; } -*/ /* * (c) 2003-2011 Glenn Maynard, AJ Kelly diff --git a/src/arch/InputHandler/InputHandler_DirectInputHelper.h b/src/arch/InputHandler/InputHandler_DirectInputHelper.h index ba88f0f5e6..8519a2dbf2 100644 --- a/src/arch/InputHandler/InputHandler_DirectInputHelper.h +++ b/src/arch/InputHandler/InputHandler_DirectInputHelper.h @@ -23,11 +23,12 @@ typedef struct input_t struct DIDevice { DIDEVICEINSTANCE JoystickInst; + DIDEVICEINSTANCE MouseInst; LPDIRECTINPUTDEVICE2 Device; RString m_sName; - enum { KEYBOARD, JOYSTICK } type; - //enum { KEYBOARD, JOYSTICK, MOUSE } type; + //enum { KEYBOARD, JOYSTICK } type; + enum { KEYBOARD, JOYSTICK, MOUSE } type; bool buffered; int buttons, axes, hats;