C++ single character input
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
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.
Different platforms have different methods of doing this. For instance on Windows you can use _getch()
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.
Quote:Original post by SpidyOpenGL 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.
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.
-Extrarius
If you're using windows, use this:
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.
#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.
Quote:Original post by Anonymous PosterQuote:Original post by SpidyOpenGL 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.
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.
-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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement