keyup and down

Started by
2 comments, last by neneboricua19 18 years, 8 months ago
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
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
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
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

This topic is closed to new replies.

Advertisement