本文整理汇总了C++中LPDIRECTINPUTDEVICE8::Acquire方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE8::Acquire方法的具体用法?C++ LPDIRECTINPUTDEVICE8::Acquire怎么用?C++ LPDIRECTINPUTDEVICE8::Acquire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE8
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE8::Acquire方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: KeyboardInit
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;
}
示例2: KeyboardUpdate
/* Update Keyboard status */
BOOL KeyboardUpdate (void)
{
/* Poll the Keyboard */
if (FAILED (m_lpkDKB->Poll ()) )
{
/* Acquire Keyboard */
HRESULT hRet = m_lpkDKB->Acquire ();
if ((FAILED (hRet)) && (hRet == DIERR_INPUTLOST))
{
m_lpkDKB->Acquire ();
}
else
{
return FALSE;
}
}
/* Get device data */
if (FAILED (m_lpkDIDevice->GetDeviceState (sizeof (DIJOYSTATE2),
&m_kDeviceData)) )
{
return FALSE;
}
return TRUE;
}
示例3: initDIDevice
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;
}
示例4: DirectInput_Init
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;
}
示例5: acquireDIDevice
void acquireDIDevice()
{
if(g_pKeyboardDevice)
g_pKeyboardDevice->Acquire();
if(g_pMouseDevice)
g_pMouseDevice->Acquire();
}
示例6: DirectInput_Update
void DirectInput_Update()
{
//update mouse
dimouse->Poll();
if (!SUCCEEDED(dimouse->GetDeviceState(sizeof(DIMOUSESTATE),&mouse_state)))
{
//mouse device lose, try to re-acquire
dimouse->Acquire();
}
//update keyboard
dikeyboard->Poll();
if (!SUCCEEDED(dikeyboard->GetDeviceState(256,(LPVOID)&keys)))
{
//keyboard device lost, try to re-acquire
dikeyboard->Acquire();
}
//update controllers
for (int i=0; i< 4; i++ )
{
ZeroMemory( &controllers[i], sizeof(XINPUT_STATE) );
//get the state of the controller
XINPUT_STATE state;
DWORD result = XInputGetState( i, &state );
//store state in global controllers array
if (result == 0) controllers[i] = state.Gamepad;
}
}
示例7: GutInputRestore
int GutInputRestore(void)
{
if ( g_pMouse ) g_pMouse->Acquire();
if ( g_pJoystick ) g_pJoystick->Acquire();
if ( g_pKeyboard ) g_pKeyboard->Acquire();
return 1;
}
示例8: ReadImmediateData
//-----------------------------------------------------------------------------
// Name: ReadImmediateData()
// Desc: Read the input device's state when in immediate mode and display it.
//-----------------------------------------------------------------------------
HRESULT ReadImmediateData( HWND hDlg )
{
HRESULT hr;
TCHAR strNewText[128] = TEXT(""); // Output string
DIMOUSESTATE2 dims2; // DirectInput mouse state structure
if( NULL == g_pMouse )
return S_OK;
// Get the input's device state, and put the state in dims
ZeroMemory( &dims2, sizeof(dims2) );
hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 );
if( FAILED(hr) )
{
// DirectInput may be telling us that the input stream has been
// interrupted. We aren't tracking any state between polls, so
// we don't have any special reset that needs to be done.
// We just re-acquire and try again.
// If input is lost then acquire and keep trying
hr = g_pMouse->Acquire();
while( hr == DIERR_INPUTLOST )
hr = g_pMouse->Acquire();
// Update the dialog text
if( hr == DIERR_OTHERAPPHASPRIO ||
hr == DIERR_NOTACQUIRED )
SetDlgItemText( hDlg, IDC_DATA, TEXT("Unacquired") );
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
// may occur when the app is minimized or in the process of
// switching, so just try again later
return S_OK;
}
// The dims structure now has the state of the mouse, so
// display mouse coordinates (x, y, z) and buttons.
_stprintf( strNewText, TEXT("(X=% 3.3d, Y=% 3.3d, Z=% 3.3d) B0=%c B1=%c B2=%c B3=%c B4=%c B5=%c B6=%c B7=%c"),
dims2.lX, dims2.lY, dims2.lZ,
(dims2.rgbButtons[0] & 0x80) ? '1' : '0',
(dims2.rgbButtons[1] & 0x80) ? '1' : '0',
(dims2.rgbButtons[2] & 0x80) ? '1' : '0',
(dims2.rgbButtons[3] & 0x80) ? '1' : '0',
(dims2.rgbButtons[4] & 0x80) ? '1' : '0',
(dims2.rgbButtons[5] & 0x80) ? '1' : '0',
(dims2.rgbButtons[6] & 0x80) ? '1' : '0',
(dims2.rgbButtons[7] & 0x80) ? '1' : '0');
// Get the old text in the text box
TCHAR strOldText[128];
GetDlgItemText( hDlg, IDC_DATA, strOldText, 127 );
// If nothing changed then don't repaint - avoid flicker
if( 0 != lstrcmp( strOldText, strNewText ) )
SetDlgItemText( hDlg, IDC_DATA, strNewText );
return S_OK;
}
示例9: AcquireDevice
// Acquire our device. Our device might get unacquired for many many reasons, and we need to be able to reacquire it to get input again.
// We use this a LOT.
inline HRESULT AcquireDevice( LPDIRECTINPUTDEVICE8 lpDirectInputDevice )
{
HRESULT hResult = lpDirectInputDevice->Acquire();
while( hResult == DIERR_INPUTLOST )
hResult = lpDirectInputDevice->Acquire();
if( SUCCEEDED( hResult ))
lpDirectInputDevice->Poll();
return hResult;
}
示例10: GutInputInit
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;
}
示例11: DIWindowActivate
void ENGINEAPI DIWindowActivate(BOOL bActive)
{
if(bDInputActive)
{
if(bActive)
{
if(diKeyboard)
diKeyboard->Acquire();
if(diMouse)
diMouse->Acquire();
}
}
}
示例12: getState
void getState()
{
if(mouseDevice->GetDeviceState(sizeof(mouseState), (LPVOID)&mouseState ) == DIERR_INPUTLOST)
{
mouseDevice->Acquire();
}
if(keyboardDevice->GetDeviceState(sizeof(keyState), (LPVOID)&keyState ) == DIERR_INPUTLOST)
{
mouseDevice->Acquire();
}
mousePosX += mouseState.lX;
mousePosY += mouseState.lY;
}
示例13: Read
bool OutDevice::Read(LPDIRECTINPUTDEVICE8 dev,void* pBuffer, long lSize)
{
HRESULT hr;
while(true)
{
dev->Poll(); //轮询
dev->Acquire(); //获取设备控制权
if(SUCCEEDED(hr=dev->GetDeviceState(lSize,pBuffer)))
break;
if(hr != DIERR_INPUTLOST || hr != DIERR_NOTACQUIRED)
return false;
if(FAILED(dev->Acquire()))
return false;
}
return true;
}
示例14: DInput_Init_Keyboard
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
示例15: DInput_Init_Mouse
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