Sign in to follow this  

C++ Coding

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

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

This topic is 2659 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this