Exemplo n.º 1
1
void MOUSE::InitMouse(IDirect3DDevice9* Dev, HWND wnd)
{
	try
	{
		m_pDevice = Dev;

		//Load texture and init sprite
		D3DXCreateTextureFromFile(m_pDevice, "cursor/cursor.dds", &m_pMouseTexture);
		D3DXCreateSprite(m_pDevice, &m_pSprite);

		//Get directinput object
		LPDIRECTINPUT8 directInput = NULL;

		DirectInput8Create(GetModuleHandle(NULL),	// Retrieves the application handle
						   0x0800,					// v.8.0	
						   IID_IDirectInput8,		// Interface ID
						   (VOID**)&directInput,	// Our DirectInput Object
						   NULL);

		//Acquire Default System mouse
		directInput->CreateDevice(GUID_SysMouse, &m_pMouseDevice, NULL);		
		m_pMouseDevice->SetDataFormat(&c_dfDIMouse);
		m_pMouseDevice->SetCooperativeLevel(wnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
		m_pMouseDevice->Acquire();	        

		//Get viewport size and init mouse location
		D3DVIEWPORT9 v;
		m_pDevice->GetViewport(&v);
		m_viewport.left = v.X;
		m_viewport.top = v.Y;
		m_viewport.right = v.X + v.Width;
		m_viewport.bottom = v.Y + v.Height;

		x = v.X + v.Width / 2;
		y = v.Y + v.Height / 2;

		//Release Direct Input Object
		directInput->Release();

		//Create Mouse Sphere
		D3DXCreateSphere(m_pDevice, 0.2f, 5, 5, &m_pSphereMesh, NULL);

		//Create Ball Material
		m_ballMtrl.Diffuse = D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f);
		m_ballMtrl.Specular = m_ballMtrl.Ambient = m_ballMtrl.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	}
	catch(...)
	{
		debug.Print("Error in MOUSE::InitMouse()");
	}	
}
Exemplo n.º 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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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; 
}
Exemplo n.º 5
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;
}
BOOL CALLBACK DirectInputRegistry::EnumJoysticksCallback( const DIDEVICEINSTANCE* didInstance, VOID* )
{
    HRESULT hr;
    LPDIRECTINPUT8 device = DirectInputRegistry::instance()->getDevice();
    if ( device )
    {
        hr = device->CreateDevice( didInstance->guidInstance,
                                   &(DirectInputRegistry::instance()->getJoyStick()), NULL );
    }
    if ( FAILED(hr) ) return DIENUM_CONTINUE;
    return DIENUM_STOP;
}
Exemplo n.º 7
0
int main()
{
    HRESULT hr;

    hr=DirectInput8Create
       (GetModuleHandle (NULL), DIRECTINPUT_VERSION, IID_IDirectInput8A,
       (VOID**)&gp_DI, NULL);

    printf("Devices\n-----------------\n");
    hr = gp_DI->EnumDevices(DI8DEVCLASS_ALL,EnumDevicesCallback, NULL, DIEDFL_ALLDEVICES);


    memset(&g_ActionFormat, 0, sizeof(g_ActionFormat));
    g_ActionFormat.dwSize = sizeof(g_ActionFormat);
    g_ActionFormat.dwActionSize = sizeof(DIACTION);
    g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_space);
    g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
    g_ActionFormat.rgoAction = g_commands_space;
    g_ActionFormat.guidActionMap = ACTIONMAP_GUID;
    g_ActionFormat.dwBufferSize = 32;
    g_ActionFormat.dwGenre = DIVIRTUAL_SPACESIM;

    printf("Space combat enumeration\n------------\n");
    hr=gp_DI->EnumDevicesBySemantics
       (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES );

//    if(FAILED(hr)) printf("Failed?\n");

//    g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_driving);
//    g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
//    g_ActionFormat.rgoAction = g_commands_driving;
//    g_ActionFormat.dwGenre = DIVIRTUAL_DRIVING_RACE;

//    printf("Driving race enumeration\n------------\n");
//    hr=gp_DI->EnumDevicesBySemantics
//       (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES);

//    if(FAILED(hr)) printf("Failed?\n");

//    g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_fps);
//    g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
//    g_ActionFormat.rgoAction = g_commands_fps;
//    g_ActionFormat.dwGenre = DIVIRTUAL_FIGHTING_FPS;

//    printf("First person shooter enumeration\n------------\n");
//    hr=gp_DI->EnumDevicesBySemantics
//       (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES);

//    if(FAILED(hr)) printf("Failed?\n");

    return 0;
}
Exemplo n.º 8
0
		void initialize(HWND hwnd_) {


			// DirectInputの作成
			LPDIRECTINPUT8 keyboard = NULL;
			HRESULT hr = DirectInput8Create(::GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&keyboard, NULL); 
			if (FAILED(hr)) {
				debug_out::trace("DirectInputオブジェクトの生成に失敗しました。");
				throw nyx::com_exception("DirectInputオブジェクトの生成に失敗しました。", hr);
			}

			// デバイス・オブジェクトを作成
			LPDIRECTINPUTDEVICE8 keyboardDevice = NULL;
			hr = keyboard->CreateDevice(GUID_SysKeyboard, &keyboardDevice, NULL); 
			if (FAILED(hr)) {
				debug_out::trace("DirectInputDeviceオブジェクトの生成に失敗しました。");
				throw nyx::com_exception("DirectInputDeviceオブジェクトの生成に失敗しました。", hr);
			}


			// データ形式を設定
			hr = keyboardDevice->SetDataFormat(&c_dfDIKeyboard);
			if (FAILED(hr)) {
				debug_out::trace("データ形式の設定に失敗しました。");
				throw nyx::com_exception("データ形式の設定に失敗しました。", hr);
			}
			//モードを設定(フォアグラウンド&非排他モード)
			hr = keyboardDevice->SetCooperativeLevel(hwnd_, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
			if (FAILED(hr)) {
				debug_out::trace("制御モードの設定に失敗しました。");
				throw nyx::com_exception("制御モードの設定に失敗しました。", hr);
			}
			// バッファリング・データを取得するため、バッファ・サイズを設定
			DIPROPDWORD diprop = {};
			diprop.diph.dwSize	= sizeof(diprop); 
			diprop.diph.dwHeaderSize	= sizeof(diprop.diph); 
			diprop.diph.dwObj	= 0;
			diprop.diph.dwHow	= DIPH_DEVICE;
			diprop.dwData = 255;
			hr = keyboardDevice->SetProperty(DIPROP_BUFFERSIZE, &diprop.diph);
			if (FAILED(hr)) {
				debug_out::trace("バッファサイズの設定に失敗しました。");
				throw nyx::com_exception("バッファサイズの設定に失敗しました。", hr);
			}


			keyboard_ = DirectInputPtr(keyboard, false);
			keyboardDevice_ = DirectInputDevicePtr(keyboardDevice, false);

			isInitialized = true;
		}
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;
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
		}
	}
Exemplo n.º 13
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;		// 列挙を続ける
}
Exemplo n.º 14
0
void disposeDirectInput()
{
    logg( "    Disposing Keyboard...", false );
    dinKeyboard->Unacquire();    // make sure the keyboard is unacquired
    dinKeyboard = NULL;
    logg( " Successfully disposed Keyboard." );
    
    logg( "    Disposing Joysticks...", false );
    for ( int i = numJoysticks - 1; i >= 0; i-- )
    {
        try
        {
            dinJoysticks[i]->Unacquire();
            dinJoysticks[i]->Release();
        }
        catch ( ... )
        {
            loggui( " WARNING: Caught an exception while trying to dispose Joystick ", i );
        }
        
        dinJoysticks[i] = NULL;
    }
    logg( " Successfully disposed Joysticks." );
    
    logg( "    Disposing DirectInput...", false );
    din->Release();    // close DirectInput before exiting
    din = NULL;
    logg( " Successfully disposed DirectInput." );
}
Exemplo n.º 15
0
int Game_Shutdown(void *parms,  int num_parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// kill the bug blaster
Destroy_BOB(&blaster);

// kill the mushroom maker
for (int index=0; index<4; index++)
    Destroy_Bitmap(&mushrooms[index]);

// kill the playfield bitmap
Destroy_Bitmap(&playfield);

// release joystick
lpdijoy->Unacquire();
lpdijoy->Release();
lpdi->Release();

// shutdonw directdraw
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
Exemplo n.º 16
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;
}
Exemplo n.º 17
0
int Game_Shutdown(void *parms,  int num_parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// first unacquire the mouse
lpdimouse->Unacquire();

// now release the mouse
lpdimouse->Release();

// release directinput
lpdi->Release();

// unload the bitmap file
Unload_Bitmap_File(&bitmap8bit);

// delete all bobs and bitmaps
Destroy_BOB(&buttons);
Destroy_BOB(&pointer);
Destroy_Bitmap(&cpanel);
Destroy_Bitmap(&canvas);

// shutdonw directdraw
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
Exemplo n.º 18
0
BOOL InitDirectInput(HINSTANCE hInstApp)
{
	int		i;
	HRESULT	hr;
	hr = DirectInput8Create(hInstApp,DIRECTINPUT_VERSION,IID_IDirectInput8A,(void **)&lpDInput,NULL);
	if(hr != DI_OK){
		return FALSE;
	}
	int numder_of_actions = sizeof(g_GameAction) / sizeof(g_GameAction[0]);
	ZeroMemory(&g_DIActionFormat,sizeof(DIACTIONFORMAT));
	g_DIActionFormat.dwSize        = sizeof(DIACTIONFORMAT);
	g_DIActionFormat.dwActionSize  = sizeof(DIACTION);
	g_DIActionFormat.dwDataSize    = numder_of_actions * sizeof(DWORD);
	g_DIActionFormat.dwNumActions  = numder_of_actions;
	g_DIActionFormat.guidActionMap = g_AppGuid;
	g_DIActionFormat.dwGenre       = DIVIRTUAL_STRATEGY_ROLEPLAYING;
	g_DIActionFormat.rgoAction     = g_GameAction;
	g_DIActionFormat.dwBufferSize  = 100;
	g_DIActionFormat.lAxisMin      = -32768;
	g_DIActionFormat.lAxisMax      = 32767;
	lstrcpy(g_DIActionFormat.tszActionMap, className);

	g_iDIDeviceNum = 0;
	hr = lpDInput->EnumDevicesBySemantics(NULL, &g_DIActionFormat,
				EnumDevicesBySemanticsCallback, NULL, DIEDBSFL_ATTACHEDONLY);
	if (FAILED(hr)){
		return FALSE;
	}
	for(i=0;i<g_iDIDeviceNum;i++){
		g_pDIDevice[i]->Acquire();
		g_pDIDevice[i]->Poll();
	}
	return TRUE;
} // InitDirectInput
Exemplo n.º 19
0
INT_PTR WINAPI messageCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
	switch (message) {
		case WM_DEVICECHANGE:
			if (wParam ==  DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) {
				// Wait for 30 frames, send refresh
				mustRefreshDevices = 30;
			}
			break;

		case WM_CLOSE:
			UnregisterDeviceNotification(hDeviceNotify);
			DestroyWindow(hWnd);

			diAvailable = false;
			// Releasing resources to avoid crashes
			for (auto it : joysticks) {
				if (it.second) {
					it.second->Unacquire();
					it.second->Release();
				}
			}
			joysticks.clear();
			if (di) {
				di->Release();
			}
			di = NULL;
			break;

		default:
			// Send all other messages on to the default windows handler.
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 1;
}
Exemplo n.º 20
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
Exemplo n.º 21
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
void PsychHIDShutdownHIDStandardInterfaces(void)
{
    int i;

    // Release all keyboard queues:
    for (i = 0; i < PSYCH_HID_MAX_DEVICES; i++) {
        if (psychHIDKbQueueFirstPress[i]) {
            PsychHIDOSKbQueueRelease(i);
        }
    }

    // Close all devices registered in x_dev array:
    for (i = 0; i < PSYCH_HID_MAX_DEVICES; i++) {
        if (x_dev[i]) x_dev[i]->Release();
        x_dev[i] = NULL;
    }

    // Release keyboard queue mutex:
    PsychDestroyMutex(&KbQueueMutex);
    PsychDestroyCondition(&KbQueueCondition);
    KbQueueThreadTerminate = FALSE;

    if (!CloseHandle(hEvent)) {
        printf("PsychHID-WARNING: Closing keyboard event handle failed!\n");
    }

    ndevices = 0;

    // Close our dedicated x-display connection and we are done:
    if (dinput) dinput->Release();
    dinput = NULL;

    return;
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
void Done_DInput()
{
	for( int lcv = 0; lcv < di_mouse_count; lcv++ ) {
		if( di_mouse[ lcv ] ) {
			di_mouse[ lcv ]->Unacquire();
			di_mouse[ lcv ]->Release();
			di_mouse[ lcv ] = NULL;
		}
	}


	for( int lcv = 0; lcv < di_joystick_count; lcv++ ) {
		if( di_joystick[ lcv ] ) {
			di_joystick[ lcv ]->Unacquire();
			di_joystick[ lcv ]->Release();
			di_joystick[ lcv ] = NULL;
		}
	}


	if( di_keyboard ) {
		di_keyboard->Unacquire();
		di_keyboard->Release();
		di_keyboard = NULL;
	}


	if( dinput ) {
		dinput->Release();
		dinput = NULL;
	}


	di_mouse_count = 0;
}
Exemplo n.º 25
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;
}
Exemplo n.º 26
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++;
}
Exemplo n.º 27
0
void destroyDevice()
{
	// Destruction des objets Direct3D
	if(g_pD3DDevice)
		g_pD3DDevice->ClearState();
	if(g_pRenderTargetView)
		g_pRenderTargetView->Release();
	if(g_pSwapChain)
		g_pSwapChain->Release();
	if(g_pD3DDevice)
		g_pD3DDevice->Release();

	// Destruction des objets DirectInput
	if(g_pKeyboardDevice)
	{
		g_pKeyboardDevice->Unacquire();
		g_pKeyboardDevice->Release();
	}
	if(g_pMouseDevice)
	{
		g_pMouseDevice->Unacquire();
		g_pMouseDevice->Release();
	}
	if(g_pDI)
		g_pDI->Release();
}
Exemplo n.º 28
0
/// 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 
}
Exemplo n.º 29
0
int DirectInput_Init(void)
{
    HRESULT hr;

    if(dInput || dInput3) return true;

    // Create the DirectInput interface instance. Try version 8 first.
    if(FAILED(hr = CoCreateInstance(CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
                                    IID_IDirectInput8, (LPVOID*)&dInput)) ||
       FAILED(hr = dInput->Initialize(app.hInstance, DIRECTINPUT_VERSION)))
    {
        Con_Message("DirectInput 8 init failed (0x%x).", hr);

        // Try the older version 3 interface instead.
        // I'm not sure if this works correctly.
        if(FAILED(hr = CoCreateInstance(CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
                                        IID_IDirectInput2W, (LPVOID*)&dInput3)) ||
           FAILED(hr = dInput3->Initialize(app.hInstance, 0x0300)))
        {
            Con_Message("Failed to create DirectInput 3 object (0x%x).", hr);
            return false;
        }

        Con_Message("Using DirectInput 3.");
    }

    if(!dInput && !dInput3)
    {
        Con_Message(" DirectInput init failed.");
        return false;
    }

    return true;
}
Exemplo n.º 30
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 );
}