Jump to content
  • Advertisement
Sign in to follow this  
moose517

one last question about directinput

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

ok so basically i have everything working perfectly in my game except one little problem, i cannot use the arrow keys what gives? that is the only thing stopping me from finishing my game, Please i hope somebody has an answer that doesn't involve the windows loop, my game is created to hide that and i don't wanna try and come up with a hack to get it to work with standard message loop

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by moose517
ok so basically i have everything working perfectly in my game except one little problem, i cannot use the arrow keys what gives? that is the only thing stopping me from finishing my game, Please i hope somebody has an answer that doesn't involve the windows loop, my game is created to hide that and i don't wanna try and come up with a hack to get it to work with standard message loop
What do you mean you "cannot use the arrow keys"? Are you using buffered or immediate input? Are you checking the right key constants (DIK_UP, DIK_DOWN, DIK_LEFT, DIK_RIGHT)? Are you trying to press multiple keys at once? Can we see some code?

Share this post


Link to post
Share on other sites
I have the game check to see if the user is pressing any of the arrow keys but it will not respond

Here is the code in that section


gDInput->poll();

// see if the user is pressing the button
if (gDInput->keyDown(DIK_RETURN) && !m_keyEnterPressed)
{
m_keyEnterPressed = true;
}
if (gDInput->keyDown(DIK_ESCAPE) && !m_keyEscPressed)
{
m_keyEscPressed = true;
}
if (gDInput->keyDown(DIK_W) && !m_keyWPressed)
{
m_keyWPressed = true;
}
if (gDInput->keyDown(DIK_S) && !m_keySPressed)
{
m_keySPressed = true;
}

// now see if the release the button if so, then change the state
if (!gDInput->keyDown(DIK_RETURN) && m_keyEnterPressed)
{
m_keyEnterPressed = false;
switch(m_currentSelected)
{
case PLAY:
pGame->changeState(PlayState::Instance());
break;
case OPTIONS:
pGame->changeState(OptionsState::Instance());
break;
case CREDITS:
pGame->changeState(CreditsState::Instance());
break;
case QUIT:
PostQuitMessage(0);
break;
default:
break;
}
}
if (!gDInput->keyDown(DIK_ESCAPE) && m_keyEscPressed)
{
m_keyEscPressed = false;
PostQuitMessage(0);
}
if (!gDInput->keyDown(DIK_W) && m_keyWPressed)
{
// see if we are already at top, if so jump to bottom
m_keyWPressed = false;
if (m_currentSelected == PLAY)
{
m_currentSelected = QUIT;
}
else
{
m_currentSelected --;
}
}
if (!gDInput->keyDown(DIK_S) && m_keySPressed)
{
m_keySPressed = false;
if (m_currentSelected == QUIT)
{
m_currentSelected = PLAY;
}
else
{
m_currentSelected ++;
}
}
}



where keydown is defined as


bool DirectInput::keyDown(char key)
{
return (mKeyboardState[key] & 0x80) != 0;
}



and in place of the DIK_W should be DIK_UP and DIK_S would be DIK_DOWN, but nothing happens when i press them.

Share this post


Link to post
Share on other sites
Did you do a global search of your project to ensure that you've replaced DIK_W with DIK_UP everywhere it needs to be changed?

Share this post


Link to post
Share on other sites
A good debugging trick with DI that I liked was to step into, in your case, the keyDown() function and inspect the entire mKeyboardState[] state.

If you press nothing but the key that doesn't work and you register a change in that array then you know you're just looking for the wrong thing. That's quite unlikely, but some exotic keyboards have done strange key mappings. More likely is that the data is there but through some obscure logic bug your higher level code is not detecting it properly - simple step-through debugging solves this.

Alternatively, you can find that maybe nothing is being registered - a much bigger problem, but at least you can temporarily consider your code to be correct and the problem to lie elsewhere.


hth
Jack

Share this post


Link to post
Share on other sites
well someone on the directx forums over at xna community said to try and change it to unsigned char and it worked, so all is good now

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!