コード例 #1
0
ファイル: Input.cpp プロジェクト: DavidKnight247/simcoupe
void Input::Exit (bool fReInit_/*=false*/)
{
    TRACE("Input::Exit(%d)\n", fReInit_);

    if (pdiKeyboard) { pdiKeyboard->Unacquire(); pdiKeyboard->Release(); pdiKeyboard = NULL; }
    if (pdidJoystick1) { pdidJoystick1->Unacquire(); pdidJoystick1->Release(); pdidJoystick1 = NULL; }
    if (pdidJoystick2) { pdidJoystick2->Unacquire(); pdidJoystick2->Release(); pdidJoystick2 = NULL; }
    if (pdi) { pdi->Release(); pdi = NULL; }

    Keyboard::Exit(fReInit_);
}
コード例 #2
0
ファイル: Input.cpp プロジェクト: DavidKnight247/simcoupe
bool InitJoystick (LPDIRECTINPUTDEVICE2 &pJoystick_)
{
    HRESULT hr;

    // Set the joystick device to use the joystick format
    if (FAILED(hr = pJoystick_->SetDataFormat(&c_dfDIJoystick)))
        TRACE("!!! Failed to set data format of joystick device (%#08lx)\n", hr);
    else if (FAILED(hr = pJoystick_->SetCooperativeLevel(g_hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
        TRACE("!!! Failed to set cooperative level of joystick device (%#08lx)\n", hr);
    else
    {
        // Deadzone tolerance percentage and range of each axis (-100 to +100)
        DIPROPDWORD diPdw = { { sizeof(diPdw), sizeof(diPdw.diph), 0, DIPH_BYOFFSET }, 10000UL * JOYSTICK_DEADZONE / 100UL };
        DIPROPRANGE diPrg = { { sizeof(diPrg), sizeof(diPrg.diph), 0, DIPH_BYOFFSET }, -100, +100 };

        int anAxes[] = { DIJOFS_X, DIJOFS_Y, DIJOFS_RX, DIJOFS_RY };

        for (int i = 0 ; i < _countof(anAxes) ; i++)
        {
            diPdw.diph.dwObj = diPrg.diph.dwObj = anAxes[i];

            if (FAILED(hr = pJoystick_->SetProperty(DIPROP_DEADZONE, &diPdw.diph)))
                TRACE("!!! Failed to set joystick deadzone (%#08lx)\n", hr);
            else if (FAILED(hr = pJoystick_->SetProperty(DIPROP_RANGE, &diPrg.diph)))
                TRACE("!!! Failed to set joystick range (%#08lx)\n", hr);
        }

        return true;
    }

    // Clean up
    pJoystick_->Release();
    pJoystick_ = NULL;

    return false;
}