Question About Keyboard Hits

Started by
1 comment, last by hop 18 years, 8 months ago
Hello Everyone, I recently created my first game using C++, a very simple Pong Game. The only problem with the game is the paddle you control doesn't stop moving when you release the key (although it does when you press another key, which makes sense to me but is not ideal). When I fix this, the program returns that the key is being pressed as if it were typing (so you press the key and it registers once then you wait a bit and it starts repeating at a low rate). The code that tests whether you are pressing the key is as follows (in the version where it keeps moving): if (kbhit() == TRUE) c = getch(); There must be a better way to do this. Is there some function I should be using? And here is the enitre code (this is the version where it stops moving)(and sorry I don't know how to do links yet for these forums): http://www.sitesled.com/members/fusiongames/Pong.txt And if anyone wants to test the .exe, here it is: http://www.sitesled.com/members/fusiongames/Pong.exe (1st vers) http://www.sitesled.com/members/fusiongames/Pong2.exe (2nd vers) Thanks for helping this noob! // edit - added title
Advertisement
Try using GetAsyncKeyState()
example:

if(GetAsyncKeyState(VK_LEFT))
//Left arrow is down!

Here's the list of VK Key Codes:
Click

Also, for next time, it might be a good idea to give your thread a title :P
Wow, thanks a lot! Those are extemely useful.

This topic is closed to new replies.

Advertisement