Jump to content
  • Advertisement
Sign in to follow this  
Spidy

C++ single character input

This topic is 4415 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 am looking for a way to read a single character from the keyboard(a,s,e, etc.) and then act on it, without requiring the user to hit enter each time that they input a character. Does anyone know how I would accomplish this with C++? It's preferably that it be doable using only the standard libraries. Thanks, Spidy

Share this post


Link to post
Share on other sites
Advertisement
Can't be done within the standard library. As far as c++ and it's libraries are concerned your computer might not even have a keyboard.

Share this post


Link to post
Share on other sites
I'm on a Mac, although I'd like the code to be as cross-platform compatible as possible. The only solution I've come up with is to use OpenGL's keypress handling hooks, but that seems like a bit much.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Spidy
I'm on a Mac, although I'd like the code to be as cross-platform compatible as possible. The only solution I've come up with is to use OpenGL's keypress handling hooks, but that seems like a bit much.
OpenGL doesn't handle input - it's just an Open Graphics Library. Perhaps you mean SDL? If so, the way it works is by basically having a different version for each platform, with each version having the same functions implemented in platform-specific ways.

-Extrarius

Share this post


Link to post
Share on other sites
If you're using windows, use this:


#include <conio.h>

int main()
{
char test;
test = _getch();
}



if not I know there are some libraries for linux that support it, just google serach it

edit: sorry, just read you're on a mac. I have no experience there.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by Spidy
I'm on a Mac, although I'd like the code to be as cross-platform compatible as possible. The only solution I've come up with is to use OpenGL's keypress handling hooks, but that seems like a bit much.
OpenGL doesn't handle input - it's just an Open Graphics Library. Perhaps you mean SDL? If so, the way it works is by basically having a different version for each platform, with each version having the same functions implemented in platform-specific ways.

-Extrarius


I realized right after writing the post that I meant GLUT. Whoops.

Quote:
Original post by ChopperDave
Maybe try the get function?


get worked, thanks!

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!