Jump to content
  • Advertisement

Archived

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

Hadi Rezaie

Running only once !!!

This topic is 6184 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

Hi all, I wrote function for indicating hited keys, but this function will run only once, i mean, when you hit key twice or more won''t work, only once !!! bool MyKeyboardTemplate::GetKey() { int i; bool bHit = false; TCHAR strResult[256 * 5 + 1] = TEXT(""), strElement[10]; BYTE KeyBuffer[256]; ZeroMemory(&KeyBuffer, sizeof(KeyBuffer)); lpDIDevice->GetDeviceState(sizeof(KeyBuffer), (LPVOID)&KeyBuffer); for(i = 0; i < 256; i++) { if(KeyBuffer & 0x80) { bHit = true; wsprintf(strElement,"0x%02x", i); strcat(strResult, strElement); } } if(!bHit) return false; MessageBox(NULL, strResult, "Hiya", MB_ICONERROR | MB_OK); return true; } Where is my wrong ? Hadi Rezaie

Share this post


Link to post
Share on other sites
Advertisement
Lalala --- the forum makes strange things to my messages

Anyway, as jwalker said above, you have probably lost keyboard focus. Since you spawn a message box when you detect a keypress, windows will let that messagebox get the keyboard input. Then, when you close the box, your program will get the focus again... The problem is that you might have lost DirectInput's access to the keyboard. To solve this you need to reacquire the keybord:


HRESULT h = lpDIDevice->GetDeviceState(sizeof(KeyBuffer), (LPVOID)&KeyBuffer);

if(h != HR_OK)
{
if(h == DIERR_INPUTLOST || h == DIERR_NOTACQUIRED )
{
m_lpDIDevice->Acquire();
}
}



Edited by - Khaile on September 9, 2001 12:00:33 PM

Edited by - Khaile on September 9, 2001 12:02:14 PM

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!