Jump to content
  • Advertisement
Sign in to follow this  
hop

Question About Keyboard Hits

This topic is 4773 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): 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

Share this post


Link to post
Share on other sites
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

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!