Example #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;
}
Example #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;
}
Example #3
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;
}
Example #4
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;
}
Example #5
0
/////////////////////////////////////
// Name:	INPMouseInit
// Purpose:	initialize mouse
//			if bExclusive, this means
//			we don't get actual windows
//			mouse location.  Use it on
//			fullscreen only.
// Output:	mouse initialized
// Return:	success if so
/////////////////////////////////////
s32 F_API INPMouseInit(void *hMain, u8 bExclusive, iPoint *pBound)
{
	INPMouseDestroy();

	HRESULT hr;

	//create the mouse device
	hr = g_pDInput->CreateDevice(GUID_SysMouse, &g_pDMouse, NULL);
	if(FAILED(hr))
	{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }

	//set mouse device as a REAL mouse
	hr = g_pDMouse->SetDataFormat(&c_dfDIMouse2);
	if(FAILED(hr))
	{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }

	//set up mouse coop level
	u32 coop = g_coopFlag & ~(INP_EXCLUSIVE | INP_NONEXCLUSIVE);
	coop |= bExclusive ? INP_EXCLUSIVE : INP_NONEXCLUSIVE;

	hr = g_pDMouse->SetCooperativeLevel((HWND)hMain, coop);
	if(FAILED(hr))
	{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }

	//acquire mouse device
	g_pDMouse->Acquire();

	g_bExclusive = bExclusive;
	memset(&g_mouseLoc, 0, sizeof(g_mouseLoc));

	INPMouseSetBound(pBound);

	return RETCODE_SUCCESS;
}
Example #6
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;
}
Example #7
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
Example #8
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;
}
Example #9
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
Example #10
0
//------------------------------------------------------
//		コントローラー初期化
//------------------------------------------------------
LPDIRECTINPUTDEVICE8 iexInputManager::GetDevice( int n )
{
	HRESULT	hr;
	LPDIRECTINPUTDEVICE8	lpDevice;

	//	デバイス生成
	hr = pDI->CreateDevice( didi[n].guidInstance, &lpDevice, NULL);
	if( FAILED(hr) ) return NULL;

	if( lpDevice->SetDataFormat( &c_dfDIJoystick2 ) != DI_OK ) return FALSE;
	if( lpDevice->SetCooperativeLevel( iexSystem::Window, DISCL_EXCLUSIVE | DISCL_FOREGROUND ) != DI_OK ) return FALSE;

	//	自動センタリング無効
	DIPROPDWORD	dipdw;
    dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    dipdw.diph.dwObj        = 0;
    dipdw.diph.dwHow        = DIPH_DEVICE;
    dipdw.dwData            = DIPROPAUTOCENTER_OFF;
    lpDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph );

	// 各軸設定
	lpDevice->EnumObjects(EnumAxes, lpDevice, DIDFT_AXIS);

	// 入力制御開始
	lpDevice->Acquire();

	return lpDevice;
}
Example #11
0
//DirectInputデバイスの初期化
bool Application::InitDinputDevice()
{
	//DirectInputデバイスを作成
	if (FAILED(directInput->CreateDevice(GUID_SysMouse, &dinputDevice, nullptr)))
		return false;

	//データフォーマットを設定
	if (FAILED(dinputDevice->SetDataFormat(&c_dfDIMouse2)))
		return false;

	//協調モードを設定
	if (FAILED(dinputDevice->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
		return false;

	//	軸モードを設定
	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_REL;

	if (FAILED(dinputDevice->SetProperty(DIPROP_AXISMODE, &diprop.diph)))
	{
		MessageBox(NULL, "設定に失敗", "Direct Input Error", MB_OK);
		return false;
	}

	// 入力制御開始
	dinputDevice->Acquire();

	return true;
}
Example #12
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 );
}
Example #13
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 
}
Example #14
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;
}
Example #15
0
static int Mouse_Win32_Init()
{
    if(CommandLine_Check("-nomouse") || novideo) return false;

    // We'll need a window handle for this.
    HWND hWnd = (HWND) ClientWindow::main().nativeHandle();

    HRESULT hr = E_FAIL;
    // Prefer the newer version 8 interface if available.
    if(LPDIRECTINPUT8 dInput = DirectInput_IVersion8())
    {
        hr = dInput->CreateDevice(GUID_SysMouse, &didMouse, 0);
    }
    else if(LPDIRECTINPUT dInput = DirectInput_IVersion3())
    {
        hr = dInput->CreateDevice(GUID_SysMouse, (LPDIRECTINPUTDEVICE*) &didMouse, 0);
    }

    if(FAILED(hr))
    {
        LOGDEV_INPUT_ERROR("Failed to create device (0x%x: %s)")
                << hr << DirectInput_ErrorMsg(hr);
        return false;
    }

    // Set data format.
    hr = didMouse->SetDataFormat(&c_dfDIMouse2);
    if(FAILED(hr))
    {
        LOGDEV_INPUT_ERROR("Failed to set data format (0x%x: %s)")
                << hr << DirectInput_ErrorMsg(hr);
        goto kill_mouse;
    }

    // Set behavior.
    hr = didMouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
    if(FAILED(hr))
    {
        LOGDEV_INPUT_ERROR("Failed to set co-op level (0x%x: %s)")
                << hr << DirectInput_ErrorMsg(hr);
        goto kill_mouse;
    }

    // Acquire the device.
    //didMouse->Acquire();
    //mouseTrapped = true;

    // We will be told when to trap the mouse.
    mouseTrapped = false;

    // Init was successful.
    return true;

  kill_mouse:
    I_SAFE_RELEASE(didMouse);
    return false;
}
Example #16
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();
    }
Example #17
0
int Init_Mouse(HWND hwnd)
{
    HRESULT result = dimouse->SetDataFormat(&c_dfDIMouse);

    result = dimouse->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);

    result = dimouse->Acquire();

    return 1;
}
Example #18
0
bool initDirect3D(HINSTANCE hInstance)
{
    pD3D = NULL;
    pd3dDevice = NULL;

    bool result = false;

    if (NULL != (pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
    {
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory(&d3dpp, sizeof(d3dpp));
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
        d3dpp.BackBufferCount = 1;
        d3dpp.BackBufferHeight = windowHeight;
        d3dpp.BackBufferWidth = windowWidth;
        d3dpp.hDeviceWindow = hWin;
        d3dpp.EnableAutoDepthStencil = TRUE;
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
        result = ! FAILED(pD3D->CreateDevice(
                                    D3DADAPTER_DEFAULT,
                                    D3DDEVTYPE_HAL,
                                    hWin,
                                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                    &d3dpp,
                                    &pd3dDevice));

        pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );

        // Create the DirectInput object. 
        HRESULT hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, 
                                IID_IDirectInput8, (void**)&g_lpDI, NULL); 

	    if FAILED(hr) return FALSE; 

        // Retrieve a pointer to an IDirectInputDevice8 interface 
        hr = g_lpDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL); 

	    hr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard); 

	    if FAILED(hr) return FALSE; 
	    

	    // Set the cooperative level 
        hr = g_lpDIDevice->SetCooperativeLevel(hWin, 
                                 DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); 
        if FAILED(hr) return FALSE; 
   

        // Get access to the input device. 
        hr = g_lpDIDevice->Acquire(); 
        if FAILED(hr) 
            return FALSE; 
        }
Example #19
0
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hDlg )
{
    HRESULT hr;

    // Setup the g_EffectsList circular linked list
    ZeroMemory( &g_EffectsList, sizeof( EFFECTS_NODE ) );
    g_EffectsList.pNext = &g_EffectsList;

    // Create a DInput object
    if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, 
                                         IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) )
        return hr;

    // Get the first enumerated force feedback device
    if( FAILED( hr = g_pDI->EnumDevices( 0, EnumFFDevicesCallback, 0, 
                                         DIEDFL_ATTACHEDONLY | 
                                         DIEDFL_FORCEFEEDBACK ) ) )
        return hr;
    
    if( g_pFFDevice == NULL )
    {
        MessageBox( hDlg, _T("No force feedback device found.  ")
                          _T("The sample will now exit."), 
                          _T("ReadFFE"), MB_ICONERROR | MB_OK );
        EndDialog( hDlg, 0 );
        return S_OK;
    }

    // Set the data format
    if( FAILED( hr = g_pFFDevice->SetDataFormat( &c_dfDIJoystick ) ) )
        return hr;

    // Set the coop level
    if( FAILED( hr = g_pFFDevice->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE | 
                                                             DISCL_BACKGROUND ) ) )
        return hr;

    // Disable auto-centering spring
    DIPROPDWORD dipdw;
    dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    dipdw.diph.dwObj        = 0;
    dipdw.diph.dwHow        = DIPH_DEVICE;
    dipdw.dwData            = FALSE;

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

    // Acquire the device
    if( FAILED( hr = g_pFFDevice->Acquire() ) )
        return hr;

    return S_OK;
}
Example #20
0
void ColoredCubeApp::initInput()
{
	DirectInput8Create(
		mhAppInst,
		DIRECTINPUT_VERSION,
		IID_IDirectInput8,
		(void**)&lpdi,
		NULL);

	lpdi->CreateDevice(GUID_SysMouseEm, &lpdiMouse, NULL);
	lpdiMouse->SetDataFormat(&c_dfDIMouse);
	lpdiMouse->SetCooperativeLevel(mhMainWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
}
Example #21
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;
		}
//=============================================================================
// マウスの初期化
//=============================================================================
HRESULT InitMouse(HINSTANCE hInst, HWND hWnd)
{
	HRESULT hr;

	// デバイスオブジェクトを作成
	hr = g_pDInput->CreateDevice(GUID_SysMouse, &g_pDIDevMouse, NULL);
	if(FAILED(hr))
	{
		MessageBox(hWnd, "マウスがねぇ!", "警告!", MB_ICONWARNING);
		return hr;
	}

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

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

	// デバイスのプロパティを設定
	{
		DIPROPDWORD dipdw;

		dipdw.diph.dwSize = sizeof(dipdw);
		dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
		dipdw.diph.dwObj = 0;
		dipdw.diph.dwHow = DIPH_DEVICE;
		dipdw.dwData = DIPROPAXISMODE_REL;

		hr = g_pDIDevMouse->SetProperty(DIPROP_AXISMODE, &dipdw.diph);
		if(FAILED(hr))
		{
			MessageBox(hWnd, "マウスのデバイスのプロパティを設定できませんでした。", "警告!", MB_ICONWARNING);
			return hr;
		}
	}

	// マウスへのアクセス権を獲得(入力制御開始)
	g_pDIDevMouse->Acquire();

	return S_OK;
}
Example #23
0
int Init_Keyboard(HWND hwnd)
{
    HRESULT result = dikeyboard->SetDataFormat(&c_dfDIKeyboard);

    result = dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    if (result != DI_OK)
        return 0;

    result = dikeyboard->Acquire();
    if (result != DI_OK)
        return 0;

    return 1;
}
Example #24
0
bool CG27::InitializeG27()  
{  
    HRESULT hr;  
  
    // Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use.  
    // Create a DInput object  
  
    //initialize directinput library  
    if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,  
        IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )  
        return false;  
  
  
    LPDIRECTINPUTDEVICE8 joystick;  
  
    // Look for the first simple joystick we can find.  
    if (FAILED(hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback,  
        NULL, DIEDFL_ATTACHEDONLY))) {  
            return false;  
    }  
  
    if (g_pJoystick == NULL)    
    {  
//        ShowMessageBox("g27 not found, please check the connection, exiting........");  
		qDebug() << "fucklrl";
        return false;  
    }  
  
    if (FAILED(hr = g_pJoystick->SetDataFormat(&c_dfDIJoystick2)))  
    {  
//        ShowMessageBox(" set g27 data format error, exiting.......");  
		qDebug() << "fuckld";
        return false;  
    }  
  
    g_pJoystick->SetCooperativeLevel(NULL, DISCL_EXCLUSIVE|DISCL_FOREGROUND);  
  
    DIDEVCAPS capabilities;  
    capabilities.dwSize = sizeof(DIDEVCAPS);  
  
    g_pJoystick->GetCapabilities(&capabilities);  
  
    if (FAILED(hr=g_pJoystick->EnumObjects(enumAxesCallback, NULL, DIDFT_AXIS)))  
    {  
  
    }  
	qDebug() << "initializing succeeded";
    return true;  
}  
int InitKeyboard (HWND hWnd) {
    HRESULT hr = diKeyboard->SetDataFormat(&c_dfDIKeyboard);
    if (hr != DI_OK)
        return 0;

    hr = diKeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    if (hr != DI_OK)
        return 0;

    hr = diKeyboard->Acquire();
    if (hr != DI_OK)
        return 0;

    return 1;
}
int InitMouse (HWND hWnd) {
    HRESULT hr = diMouse->SetDataFormat(&c_dfDIMouse);
    if (hr != DI_OK)
        return 0;

    hr = diMouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
    if (hr != DI_OK)
        return 0;

    hr = diMouse->Acquire();
    if (hr != DI_OK)
        return 0;

    return 1;
}
Example #27
0
//-----------------------------------------------------------------------------
// Name: AddDevice()
// Desc: Add the provided device to the list and perform initialization
//-----------------------------------------------------------------------------
HRESULT CInputDeviceManager::AddDevice( const DIDEVICEINSTANCE* pdidi, 
                                        const LPDIRECTINPUTDEVICE8 pdidDevice )
{
    HRESULT hr;
    DWORD   dwDeviceType = pdidi->dwDevType;

    pdidDevice->Unacquire();

    // Set the device's coop level
    hr = pdidDevice->SetCooperativeLevel( m_hWnd, DISCL_NONEXCLUSIVE|DISCL_FOREGROUND );
    if( FAILED(hr) )
        return hr;

    // Add new DeviceInfo struct to list, and resize array if needed
    m_dwNumDevices++;
    if( m_dwNumDevices > m_dwMaxDevices )
    {
        m_dwMaxDevices += 10;
        m_pDevices = (DeviceInfo*) realloc( m_pDevices, m_dwMaxDevices*sizeof(DeviceInfo) );
        ZeroMemory( m_pDevices + m_dwMaxDevices - 10, 10*sizeof(DeviceInfo) );
    }

    DWORD dwCurrentDevice = m_dwNumDevices-1;
    m_pDevices[dwCurrentDevice].pdidDevice = pdidDevice;
    m_pDevices[dwCurrentDevice].pdidDevice->AddRef();

    // Callback into the app so it can adjust the device and set
    // the m_pDevices[dwCurrentDevice].pParam field with a device state struct
    if( m_AddDeviceCallback )
    {
        hr = m_AddDeviceCallback( &m_pDevices[dwCurrentDevice], pdidi, m_AddDeviceCallbackParam ); 
        if( FAILED(hr) )    
            return hr;
    }

    // Build the action map
    hr = m_pDevices[dwCurrentDevice].pdidDevice->BuildActionMap( &m_diaf, m_strUserName, 0 );
    if( FAILED(hr) )
        return hr;

    // Set the action map for the current device
    hr = m_pDevices[dwCurrentDevice].pdidDevice->SetActionMap( &m_diaf, m_strUserName, 0 );
    if( FAILED(hr) )
        return hr;

    // Continue enumerating suitable devices
    return S_OK;
}
Example #28
0
//=============================================================================
// キーボードの初期化
//=============================================================================
HRESULT InitKeyboard(HINSTANCE hInstance, HWND hWnd)
{
	HRESULT hr;

	// 入力処理の初期化
	hr = InitInput(hInstance, hWnd);
	if(FAILED(hr))
	{
		MessageBox(hWnd, "DirectInputオブジェクトが作れねぇ!", "警告!", MB_ICONWARNING);
		return hr;
	}

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

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

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

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

	// 各ワークのクリア
	ZeroMemory(g_aKeyState, sizeof g_aKeyState);
	ZeroMemory(g_aKeyStateTrigger, sizeof g_aKeyStateTrigger);
	ZeroMemory(g_aKeyStateRelease, sizeof g_aKeyStateRelease);
	ZeroMemory(g_aKeyStateRepeat, sizeof g_aKeyStateRepeat);
	ZeroMemory(g_aKeyStateRepeatCnt, sizeof g_aKeyStateRepeatCnt);

	return S_OK;
}
Example #29
0
// ウィンドウモードでD3D初期化
HRESULT InitD3DWindow(LPCTSTR wintitle, int w, int h) {
	ZeroMemory(&g_models, sizeof(Model)*MAXMODEL);
	// ウィンドウクラス作成
	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("D3D Window Class"), NULL};
	RegisterClassEx(&wc);

	// ウィンドウ作成
	HWND hWnd = CreateWindow( _T("D3D Window Class"), wintitle, WS_OVERLAPPED | WS_SYSMENU, 100, 100, w, h, NULL, NULL, wc.hInstance, NULL);

	// ビューポートアスペクトの記録
	g_aspect = (float)w / (float)h;

	// D3D9の作成
	if (NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
		return E_FAIL;

	// D3Dデバイスの作成(可能ならば固定頂点機能パイプラインを使用)
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
	d3dpp.Windowed               = TRUE;
	d3dpp.BackBufferFormat       = D3DFMT_UNKNOWN;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice))) 
	{
		if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
		{
			return E_FAIL;
		}
	}

	// Zバッファをオン
	g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
	ShowWindow(hWnd, SW_SHOWDEFAULT);

	// DirectInputの初期化
	if (FAILED(DirectInput8Create(wc.hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_pDI, NULL)))
		return E_FAIL;
	if (FAILED(g_pDI->CreateDevice(GUID_SysKeyboard, &g_pDIDevice, NULL)))
		return E_FAIL;
	g_pDIDevice->SetDataFormat(&c_dfDIKeyboard);
	g_pDIDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE);

	return S_OK;
}
BOOL CALLBACK CJoystickInterfaceDirectInput::EnumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
{
    // Skip verified XInput devices
    if (IsXInputDevice(&pdidInstance->guidProduct))
        return DIENUM_CONTINUE;

    CJoystickInterfaceDirectInput* context = static_cast<CJoystickInterfaceDirectInput*>(pContext);

    LPDIRECTINPUTDEVICE8 pJoystick = NULL;

    // Obtain an interface to the enumerated joystick.
    HRESULT hr = context->m_pDirectInput->CreateDevice(pdidInstance->guidInstance, &pJoystick, NULL);
    if (FAILED(hr) || pJoystick == NULL)
    {
        esyslog("%s: Failed to CreateDevice: %s", __FUNCTION__, pdidInstance->tszProductName);
        return DIENUM_CONTINUE;
    }

    // Set the data format to "simple joystick" - 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 DInput that we will be
    // passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
    hr = pJoystick->SetDataFormat(&c_dfDIJoystick2);
    if (FAILED(hr))
    {
        esyslog("%s: Failed to SetDataFormat on: %s", __FUNCTION__, pdidInstance->tszProductName);
        return DIENUM_CONTINUE;
    }

    if (!context->m_hWnd)
        return DIENUM_CONTINUE;

    // Set the cooperative level to let DInput know how this device should
    // interact with the system and with other DInput applications.
    hr = pJoystick->SetCooperativeLevel(context->m_hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    if (FAILED(hr))
    {
        esyslog("%s: Failed to SetCooperativeLevel on: %s", __FUNCTION__, pdidInstance->tszProductName);
        return DIENUM_CONTINUE;
    }

    const std::string strName = pdidInstance->tszProductName ? pdidInstance->tszProductName : "";

    context->AddScanResult(JoystickPtr(new CJoystickDirectInput(pdidInstance->guidInstance, pJoystick, strName)));

    return DIENUM_CONTINUE;
}