Beispiel #1
0
bool initDIDevice(HINSTANCE hInstance, HWND hWnd)
{
	// Initialisation de DirectInput
	if(FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL)))
		return false;

	// Initialisation du clavier
	if(FAILED(g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboardDevice, NULL)))
		return false;
	if(FAILED(g_pKeyboardDevice->SetDataFormat(&c_dfDIKeyboard))) 
		return false;
	if(FAILED(g_pKeyboardDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
		return false;
	if(FAILED(g_pKeyboardDevice->Acquire()))
		return false;

	// Initialisation de la souris
	if(FAILED(g_pDI->CreateDevice(GUID_SysMouse, &g_pMouseDevice, NULL)))
		return false;
	if(FAILED(g_pMouseDevice->SetDataFormat(&c_dfDIMouse)))
		return false;
	if(FAILED(g_pMouseDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE)))
		return false;
	if(FAILED(g_pMouseDevice->Acquire()))
		return false;

	return true;
}
Beispiel #2
0
bool DirectInput_Init(HWND hwnd)
{
    //initialize DirectInput object
    DirectInput8Create(
        GetModuleHandle(NULL), 
        DIRECTINPUT_VERSION, 
        IID_IDirectInput8,
        (void**)&dinput,
        NULL);

    //initialize the keyboard
    dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
    dikeyboard->SetDataFormat(&c_dfDIKeyboard);
    dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    dikeyboard->Acquire();

    //initialize the mouse
    dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);
    dimouse->SetDataFormat(&c_dfDIMouse);
    dimouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    dimouse->Acquire();
    d3ddev->ShowCursor(false);

    return true;
}
Beispiel #3
0
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
Summary: Initializes a new input device 
Parameters: 
[in] pDI – IDirectInput interface 
[in] hWnd – Window handle 
[in] type – Member of DIRECTINPUTTYPE enum. 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 
BOOL InputDevice::Initialize( LPDIRECTINPUT8 pDI, HWND hWnd, DIRECTINPUTTYPE type )
{ 
	// Check for a valid parent DIRECTINPUT8 interface 
	if ( pDI == NULL || type == DIT_FORCE_DWORD ) 
	{ 
		return FALSE; 
	} 
	Release();
	DIDATAFORMAT* pDataFormat; 
	m_hWnd = hWnd; 
	m_type = type; 

	// Create the device 
	switch( type ) 
	{ 
	case DIT_KEYBOARD: 
		if ( FAILED( pDI->CreateDevice( GUID_SysKeyboard, &m_pDevice, NULL ) ) ) 
		{ 
			//SHOWERROR("Unable to create keyboard device.", __FILE__, __LINE__ ); 
			return FALSE; 
		} 
		pDataFormat = (DIDATAFORMAT*)&c_dfDIKeyboard; 
		break; 
	case DIT_MOUSE: 
		if ( FAILED( pDI->CreateDevice( GUID_SysMouse, &m_pDevice, NULL ) ) ) 
		{ 
			//SHOWERROR( "Unable to create mouse device.", __FILE__, __LINE__ ); 
			return FALSE; 
		} 
		pDataFormat = (DIDATAFORMAT*)&c_dfDIMouse; 
		break; 
	default: 
		return FALSE; 
	}

	// Set the data format 
	if( FAILED( m_pDevice->SetDataFormat( pDataFormat ) ) ) 
	{ 
		//SHOWERROR( “Unable to set input data format.", __FILE__, __LINE__ ); 
		return FALSE; 
	}

	// Set the cooperative level 
	if( FAILED( m_pDevice->SetCooperativeLevel( hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ) ) ) 
	{ 
		//SHOWERROR( “Unable to set input cooperative level.", __FILE__, __LINE__ ); 
		return FALSE; 
	}

	// Acquire the device 
	if( FAILED( m_pDevice->Acquire() ) ) 
	{ 
		//SHOWERROR("Unable to acquire the input device.", __FILE__, __LINE__ ); 
		return FALSE; 
	}

	return TRUE; 
}
Beispiel #4
0
int GutInputInit(void)
{
	memset(g_pKeyDownFuncs, 0, sizeof(g_pKeyDownFuncs));
	memset(g_pKeyUpFuncs, 0, sizeof(g_pKeyUpFuncs));
	memset(g_pKeyPressedFuncs, 0, sizeof(g_pKeyPressedFuncs));

	int hr;
	HWND hwnd = GutGetWindowHandleWin32();
	HINSTANCE hinst = GutGetWindowInstanceWin32();
	hr = DirectInput8Create( hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL);
	if ( FAILED(hr) )
		return 0;

	// create keyboard device
	hr = g_pDI->CreateDevice( GUID_SysKeyboard, &g_pKeyboard, NULL );
	if ( FAILED(hr) )
		return 0;

	if ( g_pKeyboard )
	{
		g_pKeyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
		g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
		g_pKeyboard->Acquire();
	}

	// create mouse device
	hr = g_pDI->CreateDevice(GUID_SysMouse, &g_pMouse, NULL);
	if ( FAILED(hr) )
		return 0;

	if ( g_pMouse )
	{
		g_pMouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
		g_pMouse->SetDataFormat(&c_dfDIMouse2);
		g_pMouse->Acquire();
	}

	GetCursorPos(&g_op);
	ScreenToClient(hwnd, &g_op);
	g_mouse = g_op;

	// create joystick device
	hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY);
	if ( FAILED(hr) )
		return 0;

	if ( g_pJoystick )
	{
		g_pJoystick->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
		g_pJoystick->SetDataFormat(&c_dfDIJoystick);
		g_pJoystick->Acquire();
	}

	return 1;
}
int Init_DirectInput(HWND hwnd)
{
    HRESULT result = DirectInput8Create(
        GetModuleHandle(NULL), 
        DIRECTINPUT_VERSION, 
        IID_IDirectInput8,
        (void**)&dinput,
        NULL);

    result = dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);

    result = dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);

    return 1;
}
int InitDirectInput (HWND hWnd) {
    HRESULT hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&dinput, NULL);
    if (hr != DI_OK)
        return 0;

    hr = dinput->CreateDevice(GUID_SysMouse, &diMouse, NULL);
    if (hr != DI_OK)
        return 0;

    hr = dinput->CreateDevice(GUID_SysKeyboard, &diKeyboard, NULL);
    if (hr != DI_OK)
        return 0;

    return 1;
}
Beispiel #7
0
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext )
{
    LPDIRECTINPUTDEVICE8 dinJoystick;
    // Obtain an interface to the enumerated joystick.
    HRESULT hr = din->CreateDevice( pdidInstance->guidInstance, &dinJoystick, NULL );
    if ( FAILED( hr ) )
        return ( DIENUM_CONTINUE );
    
    dinJoystick->SetDataFormat( &c_dfDIJoystick2 );
    
    HWND hWnd = *( (HWND*)pContext );
    dinJoystick->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND );
    
    unsigned char i = numJoysticks++;
    dinJoysticks[i] = dinJoystick;
    unsigned int nameLength = strlenW( pdidInstance->tszInstanceName );
    char* name = (char*)malloc( nameLength + 1 );
    //memcpy( name, pdidInstance->tszInstanceName, nameLength + 1 );
    copyWideStringToString( pdidInstance->tszInstanceName, name );
    joystickNames[i] = name;
    
    numButtons[i] = 0;
    buttonNames[i] = (char**)malloc( 256 );
    dinJoystick->EnumObjects( &EnumButtonsCallback, &i, DIDFT_BUTTON );
    
    //return ( DIENUM_STOP );
    return ( DIENUM_CONTINUE );
}
/// a function that Initializes all direct input stuff
void TSRInputSubSystem::Init()
{
#if defined( WIN32 ) || defined( WIN64 )     
	if ( FAILED( DirectInput8Create( GetModuleHandle( 0 ), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_lpdi, NULL) ) )
	{
		TSRFatalError( "Error Creating main direct input object" );
	}
	if ( FAILED( m_lpdi->CreateDevice( GUID_SysMouse, &m_lpdimouse, NULL ) ) )
	{
        TSRFatalError( "Error Creating mouse device" );
    }
	if ( FAILED( m_lpdimouse->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ) ) )
	{ 
        TSRFatalError( "Error Setting mouse cooperative level" );
    }
	if ( FAILED( m_lpdimouse->SetDataFormat( &c_dfDIMouse ) ) )
	{
        TSRFatalError( "Error setting mouse data fromat" );
    }
	if ( FAILED ( m_lpdimouse->Acquire() ) )
	{ 
        TSRFatalError( "error aquiring mouse" );
    }
#endif 
}
Beispiel #9
0
//=============================================================================
// ジョイパッド問い合わせ用コールバック関数
//=============================================================================
BOOL CALLBACK EnumJoyCallback(const DIDEVICEINSTANCE* lpddi, VOID* pvRef)
{
	DIDEVCAPS	diDevCaps;			// デバイス情報

	// ジョイパッド用デバイスオブジェクトを作成
	if(FAILED(g_pInput->CreateDevice(lpddi->guidInstance, &g_pDIDevJoypad[g_nJoypadNum], NULL)))
		return DIENUM_CONTINUE;		// 列挙を続ける

	// ジョイパッドの能力を調べる
	diDevCaps.dwSize = sizeof(DIDEVCAPS);
	if(FAILED(g_pDIDevJoypad[g_nJoypadNum]->GetCapabilities(&diDevCaps)))
	{
		if(g_pDIDevJoypad[g_nJoypadNum])
			g_pDIDevJoypad[g_nJoypadNum]->Release();
		g_pDIDevJoypad[g_nJoypadNum] = NULL;
		return DIENUM_CONTINUE;		// 列挙を続ける
	}

	// 規定数に達したら終了
	g_nJoypadNum++;
	if(g_nJoypadNum == MAX_CONTROLER)
		return DIENUM_STOP;			// 列挙を終了する
	else
		return DIENUM_CONTINUE;		// 列挙を続ける
}
Beispiel #10
0
//=============================================================================
// 初期化
//=============================================================================
HRESULT CKeyboard::Init(LPDIRECTINPUT8 DInput,HINSTANCE hInstance,HWND hWnd)
{

	HRESULT hr;

	// デバイスオブジェクトを作成
	hr = DInput->CreateDevice(GUID_SysKeyboard,&InputDevice,NULL);
	if (FAILED(hr))
	{
		MessageBox(NULL,"デバイスオブジェクトの作成に失敗しました","ERROR!",(MB_ICONERROR | MB_OK));
		return hr;
	}
	// データフォーマットを設定
	hr = InputDevice->SetDataFormat(&c_dfDIKeyboard);

	if(FAILED(hr))
	{
		MessageBox(NULL,"データフォーマットの設定に失敗しました","ERROR!",(MB_ICONERROR|MB_OK));
		return hr;
	}

	// 協調モードを設定(フォアグラウンド&非排他モード)
	hr = InputDevice->SetCooperativeLevel(hWnd,(DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));

	if(FAILED(hr))
	{
		MessageBox(NULL,"強調モードの設定に失敗しました","ERROR!",(MB_ICONERROR|MB_OK));
		return hr;
	}

	// キーボードへのアクセス権を獲得(入力制御開始)
	InputDevice->Acquire();
	return S_OK;
}
Beispiel #11
0
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hDlg )
{
    HRESULT hr;

    // Register with the DirectInput subsystem and get a pointer
    // to a IDirectInput interface we can use.
    if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
                                         IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
        return hr;

    // Retrieve the system mouse
    if( FAILED( g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) )
    {
        MessageBox( NULL, TEXT( "Mouse not found. The sample will now exit." ),
                    TEXT( "DirectInput Sample" ),
                    MB_ICONERROR | MB_OK );
        EndDialog( hDlg, 0 );
        return S_OK;
    }

    // A data format specifies which controls on a device we are interested in,
    // and how they should be reported. This tells DInput that we will be
    // passing a MouseState structure to IDirectInputDevice::GetDeviceState().
    if( FAILED( hr = g_pMouse->SetDataFormat( &g_dfMouse ) ) )
        return hr;

    // Set the cooperative level to let DInput know how this device should
    // interact with the system and with other DInput applications.
    if( FAILED( hr = g_pMouse->SetCooperativeLevel( hDlg, DISCL_NONEXCLUSIVE |
                                                    DISCL_FOREGROUND ) ) )
        return hr;

    return S_OK;
}
Beispiel #12
0
BOOL CALLBACK DInput_Joystick_EnumCallback( const DIDEVICEINSTANCE* instance, VOID* context )
{
	if( FAILED( dinput->CreateDevice( instance->guidInstance, &di_joystick[ di_joystick_count ], NULL )) )
		return DIENUM_CONTINUE;

	if( FAILED( di_joystick[ di_joystick_count ]->SetDataFormat( &c_dfDIJoystick2 )) )
		return DIENUM_CONTINUE;

	if( FAILED( di_joystick[ di_joystick_count ]->SetCooperativeLevel( di_enum_hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND )) )
		return DIENUM_CONTINUE;


	/*
	DIDEVCAPS capabilities;

	// Determine how many axis the joystick has (so we don't error out setting
	// properties for unavailable axis)

	capabilities.dwSize = sizeof(DIDEVCAPS);
	if (FAILED(hr = joystick->GetCapabilities(&capabilities))) {
			return hr;
	}
	*/


	if( FAILED( di_joystick[ di_joystick_count ]->EnumObjects( DInput_joystick_enumAxesCallback, NULL, DIDFT_AXIS )) )
	  return DIENUM_CONTINUE;



	// save name
	guid_to_string( &instance->guidInstance, di_joystick_guid[ di_joystick_count ] );

	di_joystick_count++;
}
Beispiel #13
0
int DInput_Init_Mouse(void)
{
// this function intializes the mouse

// create a mouse device 
if (lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL)!=DI_OK)
   return(0);

// set cooperation level
// change to EXCLUSIVE FORGROUND for better control
if (lpdimouse->SetCooperativeLevel(main_window_handle, 
                       DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
   return(0);

// set data format
if (lpdimouse->SetDataFormat(&c_dfDIMouse)!=DI_OK)
   return(0);

// acquire the mouse
if (lpdimouse->Acquire()!=DI_OK)
   return(0);

// return success
return(1);

} // end DInput_Init_Mouse
Beispiel #14
0
C_RESULT open_dx_keyboard(void)
{
  HRESULT hr;
  HWND hDlg = GetConsoleHwnd();

    // Register with the DirectInput subsystem and get a pointer
    // to a IDirectInput interface we can use.
    // Create a DInput object

  	if (g_pDI==NULL)
    if( VP_FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
                                         IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
        return hr;

	// Create the connection to the keyboard device
		g_pDI->CreateDevice(GUID_SysKeyboard, &fDIKeyboard, NULL);

		if (fDIKeyboard)
		{
				fDIKeyboard->SetDataFormat(&c_dfDIKeyboard);
				fDIKeyboard->SetCooperativeLevel(hDlg,DISCL_FOREGROUND | DISCL_EXCLUSIVE);
				fDIKeyboard->Acquire();
		}
		return C_OK;
}
Beispiel #15
0
//=============================================================================
// キーボードの初期化
//=============================================================================
HRESULT InitKeyboard(HINSTANCE hInst, HWND hWnd)
{
	HRESULT hr;

	// デバイスオブジェクトを作成
	hr = g_pDInput->CreateDevice(GUID_SysKeyboard, &g_pDIDevKeyboard, NULL);
	if(FAILED(hr) || g_pDIDevKeyboard == NULL)
	{
		MessageBox(hWnd, "キーボードがねぇ!", "警告!", MB_ICONWARNING);
		return hr;
	}

	// データフォーマットを設定
	hr = g_pDIDevKeyboard->SetDataFormat(&c_dfDIKeyboard);
	if(FAILED(hr))
	{
		MessageBox(hWnd, "キーボードのデータフォーマットを設定できませんでした。", "警告!", MB_ICONWARNING);
		return hr;
	}

	// 協調モードを設定(フォアグラウンド&非排他モード)
	hr = g_pDIDevKeyboard->SetCooperativeLevel(hWnd, (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
	if(FAILED(hr))
	{
		MessageBox(hWnd, "キーボードの協調モードを設定できませんでした。", "警告!", MB_ICONWARNING);
		return hr;
	}

	// キーボードへのアクセス権を獲得(入力制御開始)
	g_pDIDevKeyboard->Acquire();

	return S_OK;
}
Beispiel #16
0
	// コンストラクタ
	Mouse::Mouse(LPDIRECTINPUT8 dInput, HWND hWnd)
	{
		if (FAILED(dInput->CreateDevice(GUID_SysMouse, &dmouse, nullptr)))
		{
			return;
		}

		if (FAILED(dmouse->SetDataFormat(&c_dfDIMouse2)))
		{
			return;
		}

		if (FAILED(dmouse->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
		{
			return;
		}

		DIPROPDWORD diprop;
		diprop.diph.dwSize = sizeof(diprop);
		diprop.diph.dwHeaderSize = sizeof(diprop.diph);
		diprop.diph.dwObj = 0;
		diprop.diph.dwHow = DIPH_DEVICE;
		diprop.dwData = DIPROPAXISMODE_ABS;

		if (FAILED(dmouse->SetProperty(DIPROP_AXISMODE, &diprop.diph)))
		{
			return;
		}
	}
Beispiel #17
0
//-----------------------------------------------------------------------------
// Name: EnumJoysticksCallback()
// Desc: Called once for each enumerated Joystick. If we find one, create a
//       device interface on it so we can play with it.
//-----------------------------------------------------------------------------
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
                                     VOID* pContext )
{
    DI_ENUM_CONTEXT* pEnumContext = ( DI_ENUM_CONTEXT* )pContext;
    HRESULT hr;

    if( g_bFilterOutXinputDevices && IsXInputDevice( &pdidInstance->guidProduct ) )
        return DIENUM_CONTINUE;

    // Skip anything other than the perferred Joystick device as defined by the control panel.  
    // Instead you could store all the enumerated Joysticks and let the user pick.
    if( pEnumContext->bPreferredJoyCfgValid &&
        !IsEqualGUID( pdidInstance->guidInstance, pEnumContext->pPreferredJoyCfg->guidInstance ) )
        return DIENUM_CONTINUE;

    // Obtain an interface to the enumerated Joystick.
    hr = g_pDI->CreateDevice( pdidInstance->guidInstance, &g_pJoystick, NULL );

    // If it failed, then we can't use this Joystick. (Maybe the user unplugged
    // it while we were in the middle of enumerating it.)
    if( FAILED( hr ) )
        return DIENUM_CONTINUE;

    // Stop enumeration. Note: we're just taking the first Joystick we get. You
    // could store all the enumerated Joysticks and let the user pick.
    return DIENUM_STOP;
}
Beispiel #18
0
int DInput_Init_Keyboard(void)
{
// this function initializes the keyboard device

// create the keyboard device  
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
   return(0);

// set cooperation level
if (lpdikey->SetCooperativeLevel(main_window_handle, 
                 DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
    return(0);

// set data format
if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
   return(0);

// acquire the keyboard
if (lpdikey->Acquire()!=DI_OK)
   return(0);

// return success
return(1);

} // end DInput_Init_Keyboard
Beispiel #19
0
BOOL KeyboardInit (HWND hWindow, int iMin, int iMax,
                            int iDeadZone)
{
    if (FAILED(m_lpkDI->CreateDevice (
        pdidInstance->guidInstance, m_lpkDKB, NULL)) )
	{
        return DIENUM_CONTINUE;
	}
    else
	{
        return DIENUM_STOP;
	}

    if (FAILED(m_lpkDKB->SetDataFormat (&c_dfDIKeyboard)))
	{
        return FALSE;
	}
 
    /* Acquire joystick */
    HRESULT hRet = m_lpkDKB->Poll (); 
    if (FAILED (hRet)) 
	{
        hRet = m_lpkDKB->Acquire ();
  
        while (hRet == DIERR_INPUTLOST) 
		{
            hRet = m_lpkDKB->Acquire ();
		}
	}
    return TRUE;
}
Beispiel #20
0
//-----------------------------------------------------------------------------
// Name: EnumFFDevicesCallback()
// Desc: Get the first enumerated force feedback device
//-----------------------------------------------------------------------------
BOOL CALLBACK EnumFFDevicesCallback( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef )
{
    if( FAILED( g_pDI->CreateDevice( pDDI->guidInstance, &g_pFFDevice, NULL ) ) )
        return DIENUM_CONTINUE; // If failed, try again

    // Stop when a device was successfully found
    return DIENUM_STOP;
}
Beispiel #21
0
//================================================= game pad
//---------------------------------------- コールバック関数
BOOL CALLBACK SearchGamePadCallback(LPDIDEVICEINSTANCE lpddi, LPVOID)
{
	HRESULT result;

	result = g_pDInput->CreateDevice(lpddi->guidInstance, &pGamePad[padCount++], NULL);
	return DIENUM_CONTINUE;	// 次のデバイスを列挙

}
 /*** IDirectInput8W methods ***/
 HRESULT _stdcall CreateDevice(REFGUID r,LPDIRECTINPUTDEVICE8W *device,LPUNKNOWN unused) {
     HRESULT hr;
     if(r==GUID_SysKeyboard||r==GUID_SysMouse) {
         hr=RealInput->CreateDevice(r,device,unused);    //Create a real device
         if(hr!=DI_OK) return hr;       //If there's an erro then return
         //Create a fake device and pass it to morrowind
         if(r==GUID_SysKeyboard) {
             *device=new FakeDevice(*device,DeviceType_KEYBOARD);
         } else {
             *device=new FakeDevice(*device,DeviceType_MOUSE);
         }
         return DI_OK;
     } else {
         //This must be a joystick, so ignore it
         return RealInput->CreateDevice(r,device,unused);
     }
 }
Beispiel #23
0
//-----------------------------------------------------------------------------
// Name: Enumg_pJoysticksCallback()
// Desc: Called once for each enumerated g_pJoystick. If we find one, create a
//       device interface on it so we can play with it.
//-----------------------------------------------------------------------------
BOOL CALLBACK Enumg_pJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
                                     VOID* pContext )
{
    DI_ENUM_CONTEXT* pEnumContext = ( DI_ENUM_CONTEXT* )pContext;
    HRESULT hr;

    if( g_bFilterOutXinputDevices && IsXInputDevice( &pdidInstance->guidProduct ) )
        return DIENUM_CONTINUE;

    // Skip anything other than the perferred g_pJoystick device as defined by the control panel.  
    // Instead you could store all the enumerated g_pJoysticks and let the user pick.
    if( pEnumContext->bPreferredJoyCfgValid &&
        !IsEqualGUID( pdidInstance->guidInstance, pEnumContext->pPreferredJoyCfg->guidInstance ) )
        return DIENUM_CONTINUE;

    // Obtain an interface to the enumerated g_pJoystick.
    hr = g_pDI->CreateDevice( pdidInstance->guidInstance, &g_pJoystick, NULL );

    // If it failed, then we can't use this g_pJoystick. (Maybe the user unplugged
    // it while we were in the middle of enumerating it.)
    if( VP_FAILED( hr ) )
        return DIENUM_CONTINUE;

    // Stop enumeration. Note: we're just taking the first g_pJoystick we get. You
    // could store all the enumerated g_pJoysticks and let the user pick.

	     if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_127F&PID_E018") )==0) 
		 {
			 JoystickType=GAMEPAD_RADIO_GP; 
			 printf("Using gamepad settings for an Icarus Gamepad.\n");
		 }
		else 
		if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_046D&PID_C21A") )==0) 
		{ 
			JoystickType=GAMEPAD_LOGITECH_PRECISION; 
			printf("Using gamepad settings for a Logitech Precision gamepad.\n");
		}
		else 
		if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_054C&PID_0268") )==0) 
		{ 
			JoystickType=GAMEPAD_PLAYSTATION3; 
			printf("Using gamepad settings for a Playstation3 gamepad.\n");
		}
		else 
		if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_06A3&PID_0836") )==0) 
		{ 
			JoystickType=JOYSTICK_CYBORG_X; 
			printf("Using gamepad settings for a CyborgX joystick.\n");
		}
	


		else { JoystickType=GAMEPAD_UNKNOWN; 
		printf("Unknown gamepad. Controls are disabled.\n");
		}
	
    return DIENUM_STOP;
}
Beispiel #24
0
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hWnd )
{
    HRESULT hr;

    // Register with the DirectInput subsystem and get a pointer
    // to a IDirectInput interface we can use.
    // Create a DInput object
    if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, 
                                         IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) )
        return hr;
    
    // Obtain an interface to the system mouse device.
    if( FAILED( hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) )
        return hr;

    // Set the data format to "mouse format" - a predefined data format 
    //
    // A data format specifies which controls on a device we
    // are interested in, and how they should be reported.
    //
    // This tells DirectInput that we will be passing a
    // DIMOUSESTATE structure to IDirectInputDevice::GetDeviceState.
    if( FAILED( hr = g_pMouse->SetDataFormat( &c_dfDIMouse ) ) )
        return hr;

    // Set the cooperativity level to let DirectInput know how
    // this device should interact with the system and with other
    // DirectInput applications.
    if( FAILED( hr = g_pMouse->SetCooperativeLevel( hWnd, 
                                         DISCL_EXCLUSIVE|DISCL_FOREGROUND ) ) )
        return hr;

    // Create a win32 event which is signaled when mouse data is availible
    g_hMouseEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
    if( NULL == g_hMouseEvent )
        return E_FAIL;

    // Give the event to the mouse device
    if( FAILED( hr = g_pMouse->SetEventNotification( g_hMouseEvent ) ) )
        return hr;

    // Setup the buffer size for the mouse data
    DIPROPDWORD dipdw;
    dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    dipdw.diph.dwObj        = 0;
    dipdw.diph.dwHow        = DIPH_DEVICE;
    dipdw.dwData            = SAMPLE_BUFFER_SIZE; // Arbitary buffer size

    if( FAILED( hr = g_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) )
        return hr;

    // Not necessary, but nice for left handed users that have
    // their swapped mouse buttons
    g_bSwapMouseButtons = GetSystemMetrics( SM_SWAPBUTTON );

    return S_OK;
}
Beispiel #25
0
	// ゲームパッドを列挙する
	BOOL CALLBACK Gamepad::EnumGamepad(const DIDEVICEINSTANCE *dInstance, VOID *context)
	{
		if (FAILED(dInput->CreateDevice(dInstance->guidInstance, &dpad, nullptr)))
		{
			return DIENUM_CONTINUE;
		}

		return DIENUM_STOP;
	}
Beispiel #26
0
DirectInputKeyboard::DirectInputKeyboard(HWND const &hwnd, LPDIRECTINPUT8 const &directInput)
:
key(std::vector<unsigned char const>(KEY_LENGTH))
{
	directInput->CreateDevice(GUID_SysKeyboard, &keyboardDevice, nullptr);
	keyboardDevice->SetDataFormat(&c_dfDIKeyboard);
	keyboardDevice->SetCooperativeLevel(hwnd, (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE | DISCL_NOWINKEY));
	keyboardDevice->Acquire();
}
Beispiel #27
0
static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext )
{
	HRESULT hr;
	// Obtain an interface to the enumerated joystick.
	hr = g_pDI->CreateDevice( pdidInstance->guidInstance, &g_pJoystick, NULL );
	if( FAILED(hr) ) 
		return DIENUM_CONTINUE;
	return DIENUM_STOP;
}
Beispiel #28
0
    void initialize(HWND hwnd)
    {
	DirectInput8Create(
	    GetModuleHandle(NULL),
	    DIRECTINPUT_VERSION,
	    IID_IDirectInput8,
	    (VOID**)&directInput,
	    NULL);

	directInput->CreateDevice(GUID_SysMouse, &mouseDevice, 0);
	mouseDevice->SetDataFormat(&c_dfDIMouse);
	mouseDevice->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE );
	mouseDevice->Acquire();

	directInput->CreateDevice( GUID_SysKeyboard, &keyboardDevice, 0);
	keyboardDevice->SetDataFormat(&c_dfDIKeyboard);
	keyboardDevice->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE );
	keyboardDevice->Acquire();
    }
static LPDIRECTINPUTDEVICE8 GetXDevice(int deviceIndex)
{
    if (deviceIndex < 0 || deviceIndex >= PSYCH_HID_MAX_DEVICES || deviceIndex >= ndevices) PsychErrorExitMsg(PsychError_user, "Invalid deviceIndex specified. No such device!");
    if (x_dev[deviceIndex] == NULL) {
        if (DI_OK != dinput->CreateDevice(info[deviceIndex].guidInstance, &(x_dev[deviceIndex]), NULL)) {
            PsychErrorExitMsg(PsychError_user, "Could not open connection to device. CreateDevice() failed!");
        }
    }
    return(x_dev[deviceIndex]);
}
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
                                     VOID* pContext )
{
    // Obtain an interface to the enumerated joystick.
    if(FAILED(gDirectInput->CreateDevice( pdidInstance->guidInstance, &gJoystick, NULL )))
        return DIENUM_CONTINUE;
    strcpy(gJoystickName, pdidInstance->tszProductName);
    logprintf("Joystick found: %s", gJoystickName);
    return DIENUM_STOP;
}