Archived

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

r3alityc0d3r

DirectInput Any Key

Recommended Posts

I need some help with directx''s directinput. I know how test to see if a particular key has been pressed, but how do I check to see if any key has been pressed? r3alityc0d3r icq: 252463839 r3alityc0d3r@hotmail.com "I am the Architect. I created the Matrix...Your life is the sum of a remainder of an unbalanced equation inherent to the programming of the Matrix. Which has led you, inexorably... here." Great Architect - Matrix Reloaded

Share this post


Link to post
Share on other sites
/* Get keyboard data */
UCHAR Key[256]; /* Used to get data from Direct Input */
LPDIRECTINPUTDEVICE8 KEYBOARD; /* ALREADY SET UP */
hr=(KEYBOARD->GetDeviceState(sizeof(Key),(LPVOID)&Key));
if(FAILED(hr))
{
if(hr==DIERR_INPUTLOST)
{
hr = (KEYBOARD->Acquire());
if(FAILED(hr))
{
Log("! ERROR : Keyboard has been lost !");
Input_Shutdown();
}
}
}

/* pressed */
bool anykey=false; /* any key pressed?? */
for (int i=0;i<256;i++)
{
if (Key && 0x80) anykey = true;
}



/* edit : just realized what you were asking... */


[edited by - chxfryer on October 15, 2003 2:11:24 PM]

Share this post


Link to post
Share on other sites
so the only way to do it is to check through the whole array?

r3alityc0d3r
icq: 252463839
r3alityc0d3r@hotmail.com
"I am the Architect. I created the Matrix...Your life is the sum of a remainder of an unbalanced equation inherent to the programming of the Matrix. Which has led you, inexorably... here." Great Architect - Matrix Reloaded

Share this post


Link to post
Share on other sites
Is that what the SysRq key is? Damn, the mystery is solved!

And yes, r3alityc0d3r, scanning the array is one way to do it. The best way? Maybe not.

If you wrap your DInput stuff in any sort of class that has a "keydown" or "keyup" concept, you could just set a flag whenever a key is pressed. Before you do the "any key" you reset it to zero. Loop to see if the flag is false.

Really, it depends a lot on how your app is designed.

Coming up with anything more clever is usually a waste of time.

Oh, and I'd change that:


bool anykey=false; /* any key pressed?? */
for (int i=0;i<256;i++)
{
if (Key && 0x80) { anykey = true; break ; } // Why waste cycles?
}


---
http://www.gapingwolf.com

[edited by - FenrirWolf on October 15, 2003 3:03:56 PM]

Share this post


Link to post
Share on other sites