本文整理汇总了C++中LPDIRECTINPUTDEVICE::GetDeviceData方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE::GetDeviceData方法的具体用法?C++ LPDIRECTINPUTDEVICE::GetDeviceData怎么用?C++ LPDIRECTINPUTDEVICE::GetDeviceData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE::GetDeviceData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Purge
void Input::Purge ()
{
// Purge queued keyboard items
if (pdiKeyboard && SUCCEEDED(pdiKeyboard->Acquire()))
{
DWORD dwItems = ULONG_MAX;
if (SUCCEEDED(pdiKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), NULL, &dwItems, 0)) && dwItems)
TRACE("%lu keyboard items purged\n", dwItems);
}
Keyboard::Purge();
}
示例2: ReadKeyboard
void ReadKeyboard ()
{
if (pdiKeyboard && SUCCEEDED(pdiKeyboard->Acquire()))
{
DIDEVICEOBJECTDATA abEvents[EVENT_BUFFER_SIZE];
DWORD dwItems = EVENT_BUFFER_SIZE;
if (SUCCEEDED(pdiKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), abEvents, &dwItems, 0)))
{
for (DWORD i = 0 ; i < dwItems ; i++)
{
int nScanCode = abEvents[i].dwOfs;
bool fPressed = !!(abEvents[i].dwData & 0x80);
Keyboard::SetKey(nScanCode, fPressed);
TRACE("%d %s\n", nScanCode, fPressed ? "pressed" : "released");
}
}
}
}
示例3: DirectReadMouse
void DirectReadMouse(void)
{
DIDEVICEOBJECTDATA od[DMouse_RetrieveSize];
DWORD dwElements = DMouse_RetrieveSize;
HRESULT hres;
int OldMouseX, OldMouseY, OldMouseZ;
GotMouse = No;
MouseVelX = 0;
MouseVelY = 0;
MouseVelZ = 0;
hres = lpdiMouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),&od[0],&dwElements, 0);
if (hres == DIERR_INPUTLOST || hres==DIERR_NOTACQUIRED)
{
// We had acquisition, but lost it. Try to reacquire it.
hres = lpdiMouse->Acquire();
// No data this time
return;
}
// Unable to read data
if (hres != DI_OK) return;
// Check for any data being picked up
GotMouse = Yes;
if (dwElements == 0) return;
// Save mouse x and y for velocity determination
OldMouseX = MouseX;
OldMouseY = MouseY;
OldMouseZ = MouseZ;
// Process all recovered elements and
// make appropriate modifications to mouse
// status variables.
int i;
for (i=0; i<dwElements; i++)
{
// Look at the element to see what happened
switch (od[i].dwOfs)
{
// DIMOFS_X: Mouse horizontal motion
case DIMouseXOffset:
MouseX += od[i].dwData;
break;
// DIMOFS_Y: Mouse vertical motion
case DIMouseYOffset:
MouseY += od[i].dwData;
break;
case DIMouseZOffset:
MouseZ += od[i].dwData;
textprint("z info received %d\n",MouseZ);
break;
// DIMOFS_BUTTON0: Button 0 pressed or released
case DIMouseButton0Offset:
if (od[i].dwData & DikOn)
// Button pressed
MouseButton |= LeftButton;
else
// Button released
MouseButton &= ~LeftButton;
break;
// DIMOFS_BUTTON1: Button 1 pressed or released
case DIMouseButton1Offset:
if (od[i].dwData & DikOn)
// Button pressed
MouseButton |= RightButton;
else
// Button released
MouseButton &= ~RightButton;
break;
case DIMouseButton2Offset:
case DIMouseButton3Offset:
if (od[i].dwData & DikOn)
// Button pressed
MouseButton |= MiddleButton;
else
// Button released
MouseButton &= ~MiddleButton;
break;
default:
break;
}
}
MouseVelX = DIV_FIXED(MouseX-OldMouseX,NormalFrameTime);
MouseVelY = DIV_FIXED(MouseY-OldMouseY,NormalFrameTime);
//MouseVelZ = DIV_FIXED(MouseZ-OldMouseZ,NormalFrameTime);
//.........这里部分代码省略.........
示例4: di_process
DWORD di_process(DWORD lparam)
{
while (1) {
if ( WaitForSingleObject( Di_event, INFINITE )==WAIT_OBJECT_0 ) {
//mprintf(( "Got event!\n" ));
HRESULT hr;
DIDEVICEOBJECTDATA rgdod[10];
DWORD dwItems = MAX_BUFFERED_KEYBOARD_EVENTS;
again:;
hr = Di_keyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), rgdod, &dwItems, 0);
if (hr == DIERR_INPUTLOST) {
/*
* DirectInput is 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.
*/
Sleep(1000); // Pause a second...
hr = Di_keyboard->Acquire();
if (SUCCEEDED(hr)) {
goto again;
}
}
if (SUCCEEDED(hr)) {
// dwItems = number of elements read (could be zero)
if (hr == DI_BUFFEROVERFLOW) {
// Buffer had overflowed.
mprintf(( "Buffer overflowed!\n" ));
}
int i;
//mprintf(( "Got %d events\n", dwItems ));
for (i=0; i<(int)dwItems; i++ ) {
int key = rgdod[i].dwOfs;
int state = rgdod[i].dwData;
int stamp = rgdod[i].dwTimeStamp;
int latency;
latency = timeGetTime() - stamp;
if ( latency < 0 )
latency=0;
// if ( key == KEY_PRINT_SCRN ) {
// key_mark( key, 1, latency );
// }
// key_mark( key, (state&0x80?1:0), latency );
mprintf(( "Key=%x, State=%x, Time=%d, Latency=%d\n", key, state, stamp, latency ));
}
}
}
}
return 0;
}