Advertisement Jump to content
Sign in to follow this  

Question About Keyboard Hits

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

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): And if anyone wants to test the .exe, here it is: (1st vers) (2nd vers) Thanks for helping this noob! // edit - added title

Share this post

Link to post
Share on other sites
Try using GetAsyncKeyState()

//Left arrow is down!

Here's the list of VK Key Codes:

Also, for next time, it might be a good idea to give your thread a title :P

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!