HRESULT DirectXInput::InitializeKeyboard(HINSTANCE g_hinst, HWND hWnd)
{
// Creating the DirextX input Object
hr = DirectInput8Create(g_hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_pDI, NULL);
if (hr != DI_OK)
{
// DirectInput not available; take appropriate action
MessageBox(hWnd,"DirectInput8Create FAILED","InitializeKeyboard()",MB_OK);
return FALSE;
}
// Creating the DirextX input keyboard
hr = g_pDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL);
if (hr != DI_OK)
{
DI_Term();
MessageBox(hWnd,"CreateDevice FAILED","InitializeKeyboard()",MB_OK);
return FALSE;
}
// Setting the keyboard data format
hr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard);
if (hr != DI_OK)
{
DI_Term();
MessageBox(hWnd,"SetDataFormat FAILED","InitializeKeyboard()",MB_OK);
return FALSE;
}
// Setting the Keyboard Behavior
hr = g_lpDIDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (hr != DI_OK)
{
DI_Term();
MessageBox(hWnd,"SetCooperativeLevel FAILED","InitializeKeyboard()",MB_OK);
return FALSE;
}
// Gaining Access to the Keyboard
if (g_lpDIDevice)
{
hr = g_lpDIDevice->Acquire();
if FAILED(hr)
{
switch(hr)
{
case DIERR_INVALIDPARAM : MessageBox(hWnd,"Acquire FAILED : Invalid parameter ","InitializeKeyboard()",MB_OK); break;
case DIERR_NOTINITIALIZED : MessageBox(hWnd,"Acquire FAILED : The object has not been initialized","InitializeKeyboard()",MB_OK); break;
case DIERR_OTHERAPPHASPRIO : MessageBox(hWnd,"Acquire FAILED : Access Denied","InitializeKeyboard()",MB_OK); break;
default : MessageBox(hWnd,"Acquire FAILED : Unknow Error","InitializeKeyboard()",MB_OK);
}
}
}
return hr;
}
[edited by - D3DXVECTOR3 on October 6, 2003 8:03:33 PM]
[edited by - D3DXVECTOR3 on October 6, 2003 8:04:14 PM]
[edited by - D3DXVECTOR3 on October 6, 2003 8:06:00 PM]
DirectInput Acquire fails
I cant seem to acquire the keyboard, I followed the DirectX 9 SDK tutorial.Cant be that hard right!?
DIERR_OTHERAPPHASPRIO is the result i get from
Im working on this problem 3 days now and i have no clue
Every step goes fine until i have to require it.
I once had the same error. It is some sort of missnamed by MS.
You have to assure of some things before you call aquire:
- The Window you created and which HWND you fed to your DInputDevice create calls has to be VISIBLE and needs to be on top and activated. This is the most common problem. I myself wanted to aquire the mouse BEFORE i called ShowWindow() and UpdateWindow(). This is not good, the window has to be shown.
- If your Window goes in background (Intercept the WM_Activate)
you need to unaquire the devices and later reaquire them. This is only needed if you plan to send your app to background and use it later again.
So i suggest you look after Point1 first. Make sure the window is presented before aquireing.
Hope this helps.
----------------------------
By CommanderXXL
Commander@bloomm.de
----------------------------
You have to assure of some things before you call aquire:
- The Window you created and which HWND you fed to your DInputDevice create calls has to be VISIBLE and needs to be on top and activated. This is the most common problem. I myself wanted to aquire the mouse BEFORE i called ShowWindow() and UpdateWindow(). This is not good, the window has to be shown.
- If your Window goes in background (Intercept the WM_Activate)
you need to unaquire the devices and later reaquire them. This is only needed if you plan to send your app to background and use it later again.
So i suggest you look after Point1 first. Make sure the window is presented before aquireing.
Hope this helps.
----------------------------
By CommanderXXL
Commander@bloomm.de
----------------------------
From the SDK Documentation:
DIERR_OTHERAPPHASPRIO
Another application has a higher priority level, preventing this call from succeeding. This value is equal to the E_ACCESSDENIED standard DirectInput return value. This error can be returned when an application has only foreground access to a device but is attempting to acquire the device while in the background.
Try setting the cooperative level as follows and see if that helps:
hr = g_lpDIDevice->SetCooperativeLevel(hWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
Chris.
DIERR_OTHERAPPHASPRIO
Another application has a higher priority level, preventing this call from succeeding. This value is equal to the E_ACCESSDENIED standard DirectInput return value. This error can be returned when an application has only foreground access to a device but is attempting to acquire the device while in the background.
Try setting the cooperative level as follows and see if that helps:
hr = g_lpDIDevice->SetCooperativeLevel(hWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
Chris.
Oke i fixed the acquire thx to CommanderXXL
But i cant read any input from the kb
DXInput is my input class with all DirectInput variables in it.
dXFont is is the font and code to show any messages on screen.
DXInput.GetDeviceStateKB();
looks likes this
the buffer s a unsigned char buffer[256]
The if statements to check what key are pressed seem to be always true. I used the MS keydown macro from the tutorial
#define KEYDOWN(name, key) (name[key] & 0x80)
[edited by - D3DXVECTOR3 on October 11, 2003 10:17:42 PM]
But i cant read any input from the kb
void DXCamera::UpdateCamera(DirectXInput DXInput, DXFont dXFont){ D3DXVECTOR3 vCross; D3DXVec3Cross(&vCross, &(vLookatPt - vEyePt), &vUpVec); D3DXVec3Normalize(&vStrafe,&vCross); // Normalize the strafe vector FLOAT fElapsedTime = 0.05f; FLOAT fSpeed = 5.0f*fElapsedTime; FLOAT fAngularSpeed = 2.0f*fElapsedTime; hr = DXInput.GetDeviceStateKB(); if FAILED(hr) { switch(hr) { case DIERR_INPUTLOST : dXFont.DXPrintText("Access to the input device has been lost",2,400); break; case DIERR_INVALIDPARAM : dXFont.DXPrintText("An invalid parameter was passed", 2,400); break; case DIERR_NOTACQUIRED : dXFont.DXPrintText("The device is not acquired", 2,400); break; case DIERR_NOTINITIALIZED : dXFont.DXPrintText("The device is not initialized", 2,400); break; case E_PENDING : dXFont.DXPrintText("Data is not yet available", 2,400); break; default : dXFont.DXPrintText("Oh help me God!!!", 2,400); } DXInput.AcquireKB(); } else { // Strafe LEFT/RIGHT if (KEYDOWN(DXInput.buffer, DIK_RIGHT) || KEYDOWN(DXInput.buffer, DIK_D)); DXStrafeCam(fSpeed); // Strafe Right if (KEYDOWN(DXInput.buffer, DIK_LEFT) || KEYDOWN(DXInput.buffer, DIK_A)); DXStrafeCam(-fSpeed); // Strafe Left // Move FORWARD/BACKWARDS if (KEYDOWN(DXInput.buffer, DIK_UP) || KEYDOWN(DXInput.buffer, DIK_W)); DXUpDown(fSpeed); // Slide Up if (KEYDOWN(DXInput.buffer, DIK_DOWN) || KEYDOWN(DXInput.buffer, DIK_S)); DXUpDown(-fSpeed); // Slide Down }}
DXInput is my input class with all DirectInput variables in it.
dXFont is is the font and code to show any messages on screen.
DXInput.GetDeviceStateKB();
looks likes this
HRESULT DirectXInput::GetDeviceStateKB(){ ZeroMemory(&buffer,256); // Zero the buffer hr = glpDIDevice->GetDeviceState(sizeof(buffer),(LPVOID)&buffer); return hr;}
the buffer s a unsigned char buffer[256]
The if statements to check what key are pressed seem to be always true. I used the MS keydown macro from the tutorial
#define KEYDOWN(name, key) (name[key] & 0x80)
[edited by - D3DXVECTOR3 on October 11, 2003 10:17:42 PM]
Maybe you try to remove the ";" at the end of the "if" statements, cause this means for the compiler to do NOTHING if the if evaluation is true and then always execute the line after the statement as it is not related to the if in any way.
This is a realy dumb error and should also produce a warning from the compiler like "empty if statement - is this intended?"
or something like this.
Hope i could help you.
This is a realy dumb error and should also produce a warning from the compiler like "empty if statement - is this intended?"
or something like this.
Hope i could help you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement