int Create(HINSTANCE hinst);
int CreateKeyBoard(HWND hwnd,DWORD coop=DISCL_NONEXCLUSIVE|DISCL_FOREGROUND,int be_immediate=1);
int CreateMouse(DWORD coop);
if( !be_immediate ) {
// IMPORTANT STEP TO USE BUFFERED DEVICE DATA!
//
// DirectInput uses unbuffered I/O (buffer size = 0) by default.
// If you want to read buffered data, you need to set a nonzero
// buffer size.
//
// Set the buffer size to DINPUT_BUFFERSIZE (defined above) elements.
//
// The buffer size is a DWORD property associated with the device.
DIPROPDWORD dipdw;
int lwDirectInput::ReadBufferData()
{
if( _did_keyboard == 0 )
return 0;
BYTE buf[KEYBOARD_BUFFER_SIZE];
//hr = _did_keyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA),didod, &dwElements, 0 );
HRESULT hr = _did_keyboard->GetDeviceState( KEYBOARD_BUFFER_SIZE, &buf );
if( hr == DI_OK ) {
memcpy( _keyboard_buf, buf, sizeof(BYTE)*KEYBOARD_BUFFER_SIZE );
}
else {
// We got an error or we got DI_BUFFEROVERFLOW.
//
// Either way, it means that continuous contact with the
// device has been lost, either due to an external
// interruption, or because the buffer overflowed
// and some events were lost.
//
// Consequently, if a button was pressed at the time
// the buffer overflowed or the connection was broken,
// the corresponding "up" message might have been lost.
//
// But since our simple sample doesn't actually have
// any state associated with button up or down events,
// there is no state to reset. (In a real game, ignoring
// the buffer overflow would result in the game thinking
// a key was held down when in fact it isn't; it's just
// that the "up" event got lost because the buffer
// overflowed.)
//
// If we want to be cleverer, we could do a
// GetDeviceState() and compare the current state
// against the state we think the device is in,
// and process all the states that are currently
// different from our private state.
hr = _did_keyboard->Acquire();
while( hr == DIERR_INPUTLOST )
hr = _did_keyboard->Acquire();
}