Original Post
Hi,
I'm having some problems with DirectInput and the keyboard. It's very similiar to the code used in "Multiplayer Game Programming"
The main problems arise from this very function.
This problem arises when I exit the program...
The line m_bdiks[didKeyboardBuffer[index].dwOfs] = true; is causing some problems. When I exit the didKeyboardBuffer[index].dwOfs value has some insanely high number. So I had to put that if statement above to avoid from going out of bounds of the array. However, this still causes it to crash...
A dialogue box appears with the message that there was "DAMAGE: after Normal block (#21) at 0x00A00430".
Trying to debug that problem was a nightmare... all I saw was a lot of assembly... what could be going wrong?
Another problem is I can't seem to be able to check for capital letters for the ascii version of my "Keydown" functions... the lower case letters work, while the upper case don't. I tried searching the forums for help, but alas I found no sucess...
I tried going to www.LostLogic.com to see support for this problem in his book, but I found nothing as well.
Thanks in advance for any help,
Destroyer
//----------------------------
I'm almost never right,
and almost always left...
----------------------------
[edited by - Destroyer on April 16, 2002 11:00:40 PM]
[edited by - Destroyer on April 16, 2002 11:01:48 PM]
HRESULT CKeyboard::hrCheckForInput(void)
{
DIDEVICEOBJECTDATA didKeyboardBuffer[KEYBOARD_BUFFERSIZE];
DWORD dwItems = KEYBOARD_BUFFERSIZE;
WORD wAscii;
if(!m_lpdidKeyboard)
return E_FAIL;
m_lpdidKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), didKeyboardBuffer, &dwItems, 0);
if(dwItems)
{
for(UINT index = 0; index < dwItems; index++)
{
static UCHAR State[256];
if(GetKeyboardState(State) == false)
return E_FAIL;
UINT vk = MapVirtualKeyEx(didKeyboardBuffer[index].dwOfs, 1, m_hkllayout);
ToAsciiEx(vk, didKeyboardBuffer[index].dwOfs, State, &wAscii, 0, m_hkllayout);
if(didKeyboardBuffer[index].dwData & 0x80)
{
m_bascKeys[wAscii] = true;
if(didKeyboardBuffer[index].dwOfs >= 0 && didKeyboardBuffer[index].dwOfs < 256)
m_bdiks[didKeyboardBuffer[index].dwOfs] = true;
}
else
{
m_bascKeys[wAscii] = false;
if(didKeyboardBuffer[index].dwOfs >= 0 && didKeyboardBuffer[index].dwOfs < 256)
m_bdiks[didKeyboardBuffer[index].dwOfs] = false;
}
}
}
else
return E_FAIL;
return DI_OK;
}
In case you're wondering - this is how I check for input
[source]
bool CKeyboard::bisKeydowndik(UCHAR idik)
{
return m_bdiks[idik];
}
bool CKeyboard::bisKeydownch(char cascii)
{
return m_bascKeys[cascii];
}