Jump to content
  • Advertisement
Sign in to follow this  
becklighter

keypress speed issues...

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

I'm currently working on my first game with genuine DirectX enabled graphics. My Tetris type game is coming along well, but I've encountered a problem that I can't seem to correct. Button presses appear to occur extremely fast. I use the space bar to rotate the falling shape, but when I press it, I get a whirling blur as it draws out every different rotation in succession until I let off the key. The same problem occurs when I press down, or left and right. It makes it difficult to line up the pieces correctly. Does anyone have a clue what I might be doing wrong?

Here are what I believe to be the most pertinent pieces of code:
[source]
...
#define KeyDown(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KeyUp(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
...

...
MSG msg;
while(TRUE){
DWORD start = GetTickCount();
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if(msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}

RenderFrame();

#pragma region Move Block
if(KeyDown(VK_SPACE) && !fall.Move(0, 0, 1))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_RIGHT) && !fall.Move(0, 1, 0))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_LEFT) && !fall.Move(0, -1, 0))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_DOWN) && !fall.Move(1, 0, 0))
if(fall.SetPiece())
SendMessage(hWnd, WM_DESTROY, 0, 0);
#pragma endregion

if(KeyDown(VK_ESCAPE))
SendMessage(hWnd, WM_DESTROY, 0, 0);

while((start - GetTickCount()) < 25);
}
...
[/source]

Share this post


Link to post
Share on other sites
Advertisement
It's because it's executing that code hundreds, if not, thousands of times per second.

For something like this you would want to use the key down messages.

Share this post


Link to post
Share on other sites

It's because it's executing that code hundreds, if not, thousands of times per second.

For something like this you would want to use the key down messages.


Thank you for your reply, but, isn't that what I'm doing? Am I missing something?

Share this post


Link to post
Share on other sites

Thank you for your reply, but, isn't that what I'm doing? Am I missing something?


What your doing is checking if the key is down. You want to check for key down events, which have a built in delay. So where you have your


if (msg.message == WM_QUIT)


you will want to add a


else if(msg.message == WM_KEYDOWN)


and if that's true check which key is down and move your tetris pieces.

Share this post


Link to post
Share on other sites

[quote name='becklighter' timestamp='1313542464' post='4850096']
Thank you for your reply, but, isn't that what I'm doing? Am I missing something?


What your doing is checking if the key is down. You want to check for key down events, which have a built in delay. So where you have your


if (msg.message == WM_QUIT)


you will want to add a


else if(msg.message == WM_KEYDOWN)


and if that's true check which key is down and move your tetris pieces.
[/quote]

Thank you, that is exactly what I needed.

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!