Jump to content
  • Advertisement
Sign in to follow this  
goku21060

C++ Coding

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

Advertisement
C++ doesn't provide a way of doing this on its own. Functionality like keyboard handling, aside from console style text input, is generally operating system and/or API dependent. What operating system and API are you using?

Share this post


Link to post
Share on other sites
There's many ways of handling keyboard inputs. It all depends on which OS you are on, and what type of program you are writing.

Pure C++ is console based and read input from the standard input stream. You can use cin to read from it. You can also use functions from <stdio.h> like getchar() to stop and wait for a key to be pressed.

Of course, that's probably not what you want. If you are in Windows and want to read the state of a key at any time, GetAsyncKeyState() is useful. Another better way is to make a Windows application with a message loop and intercept keypress messages. Or, you could use another external library for more control, like DirectInput and XInput.

Share this post


Link to post
Share on other sites
thanks Dunge what you post is really helpful i have one more question say for example i didn't this is this valid or should i use GETAsyncKeyState

If ( getchar == W){
..... code goes here....
}

or should i do i make it a windows application because there will me at least maybe 15 key agruments that i was to produce... and writing it all in the .cpp would make it really long or should i just create a seperate .header of this...

Share this post


Link to post
Share on other sites
Proceed with caution. Do not confuse characters with buttons (I'm not even sure you're doing this but better safe than sorry). I'll quote myself once again and say that you should be aware of the differences:
Quote:
From an older post
Check out http://msdn.microsoft.com/en-us/library/dd458622(VS.85).aspx

In particular: GetKeyNameText, MapVirtualKeyEx, ToUnicode, VkKeyScan.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!