Skip to main content
gamedev.net
🔒 Locked

DirectInput Any Key

Started by r3alityc0d3r 3 replies 1.1k views
Original Post
r3alityc0d3r
r3alityc0d3r
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
r3alityc0d3ricq: 252463839r3alityc0d3r@hotmail.comwww.realitycoder.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
chxfryer
chxfryer
/* 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]
::fart::
r3alityc0d3r
r3alityc0d3r
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
r3alityc0d3ricq: 252463839r3alityc0d3r@hotmail.comwww.realitycoder.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
FenrirWolf
FenrirWolf
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.