Jump to content
  • Advertisement
Sign in to follow this  
MTclip

keyup and down

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

what is the best way to limit key presses.. for instance.. ..using direct input... lets say the programm is running at 300 fps.. and the "w" DIK_W key is held down .. that is 300 keypresses per second.. if you are doing text input WHAM!! you have 300 "w" printed out on screen.. so like if i just want the key to register 1 per key press... ..or.. once per given an elapsed time..
bool keysDown[256] = false;

if(!keysDown['w'])
{
 if(keyIsDown(DIK_W))
 {
  //HANDLE KEY PRESSED
  keysDown['w'] = true;
 }
}
else
{
 if(!keyIsDown(DIK_W))
 {
  //HANDLE KEY RELEASED
  keysDown['w'] = false;
 }
}

..well i just came up with that.. it may solve my problem... we'll see none the less.. if any one knows a better solution.. do tell ;P

Share this post


Link to post
Share on other sites
Advertisement
That solution will work just fine. Remember that DirectInput was meant for gameplay use. You can make it work for text entry, but that's not what it was deisigned for in the first place. Regular Windows messages will work just fine for text input and you'll avoid the hassels of trying to use DirectInput for things it wasn't meant to be used.

neneboricua

Share this post


Link to post
Share on other sites
so its perfectly fine to mix windows messages and directinput...
..that sounds like a dumb question... i mean to use both of them for input..

do most games do that for text input... that is certainly much simpler..


thanks ;P

Share this post


Link to post
Share on other sites
Yes, it is perfectly fine to mix DirectInput and windows messages without any problems at all. I can tell you from personal experience that commercial games do in fact use windows messages for text input instead of relying on DirectInput.

neneboricua

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.

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!