Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

InFerN0

DirectInput Help

This topic is 6127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whenever I try to acquire the keyboard it returns an E_ACCESSDENIED. I have no idea what to do. it does with both 7 and 8. Thanks. InFerN0 Not all who wander are lost...

Share this post


Link to post
Share on other sites
Advertisement
mmm you have problems with DI ....
if you are thinking in how to integrate direct input that mean taht you finally have bit of control with direct draw or something similar if that is your case

Congratulations !!!!

(the other case is you are something weird because all people i know initialices whit Direct Draw first)

ok try this ...


//fist we create a device supose you have a funcion that quit
// the aplication named Quit()
////////////////////////////////////////////////////
//GLOBALS!!!!!!!!!!
////////////////////////////////////////////////////
HRESULT myhr=NULL;
LPDIRECTINPUT8 g_lpDI=NULL;
LPDIRECTINPUTDEVICE8 g_lpDIDevice=NULL ;


//in the part of your initialisation put this ...

myhr = g_lpDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL);
if FAILED(myhr) {

MessageBox(g_hWndMain, "FUCK!", TITLE, MB_OK | MB_ICONEXCLAMATION );



Quit();
}

//then we grab it
myhr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard);

if FAILED(myhr)
{
Quit();
}

// Set the cooperative level
myhr = g_lpDIDevice->SetCooperativeLevel(g_hWndMain,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if FAILED(myhr)
{
Quit();
}

// Get access to the input device.
myhr = g_lpDIDevice->Acquire();
if FAILED(myhr)
{
Quit();
}




///then write some mesage handler for DI like this



void WINAPI ProcessKBInput()
{
#define KEYDOWN(name, key) (name[key] & 0x80)

char buffer[256];
HRESULT hr;

hr = g_lpDIDevice->GetDeviceState(sizeof(buffer),(LPVOID)&buffer);
if FAILED(hr)
{
// If it failed, the device has probably been lost.
// Check for (hr == DIERR_INPUTLOST)
// and attempt to reacquire it here.
myhr = g_lpDIDevice->Acquire();
return;
}

if (KEYDOWN(buffer, DIK_ESCAPE))PostQuitMessage( 0 );


if (KEYDOWN(buffer, DIK_RIGHT)); //Do something


else if(KEYDOWN(buffer, DIK_LEFT));//Do something


if (KEYDOWN(buffer, DIK_UP)) ; //Do something


else if (KEYDOWN(buffer, DIK_DOWN)); //Do something


}



//and for the clean up of direct imput try this

void WINAPI DI_Term()
{
if (g_lpDI)
{
if (g_lpDIDevice)
{
// Always unacquire device before calling Release().
g_lpDIDevice->Unacquire();
g_lpDIDevice->Release();
g_lpDIDevice = NULL;
}
g_lpDI->Release();
g_lpDI = NULL;
}
}


taraaaaaaaaaan!!!
is all
(i hope i dont miss anything .........)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!