i assume by what you are saying that there are better ways of detecting and handling keyboard input though? |
When it comes to C++, what I am most familiar with is
standard input. C++ takes input in as streams. This includes standard input ("stdin", AKA std::cin), and files (std::fstream).
The most basic way to send input is to type it into the terminal or console window (command-line input). And the usual way to then trigger this information to be sent to the program is to hit Enter/Return. You can do the vast majority of, and very useful, things with just this.
For example, this is how you would ask for the user to enter an integer in C++:
1 2 3 4
|
int n;
cout << "Enter an integer: ";
cin >> n;
cout << "You entered: " << n << '\n';
|
Line-delimited input can be obtained through getline, see example at:
http://www.cplusplus.com/reference/string/string/getline/
That is how you get user input in C++: through standard input. (Sorry if you consider this really basic and already knew that, I just wanted to make sure we were on the same page)
But this is not "real-time"; the program waits for input and the processes it. Once you start trying to get fancy things like real-time keyboard input, you're going beyond what basic input streams in C++ were meant for, because handling input in this way requires system-specific commands (like getch()) to interact with your terminal/console.
There are three main types of user interfaces: Command-Line Interface (CLI), Text-based User Interface (TUI), and Graphical User Interface (GUI). [I guess "voice-based interfaces" are getting popular these days, with all those "virtual assistant" products out there]
If you want to use TUIs, more effort is going to be needed to ensure it can work on multiple platforms. I don't often use TUIs, so I can't give much advice here. <conio.h> is a way to make some basic TUI-like stuff in Windows (originally for DOS), but it's not cross platform and is really old.
There is a well-known library called
ncurses which "allows the programmer to write text-based user interfaces in a terminal-independent manner."
If you do a search for "ncurses android" or "tui android", you'll get results for what looks like how to make mobile-compatible TUIs. But again, I don't know much about that. To me, using a mobile device as a TUI sounds really painful.
If you want to eventually make GUI applications on Android (as in, fully fledged graphical interface with touchscreen, swiping, buttons, other widgets), developer.android.com has a lot of resources on this, and there's plenty of information to search for on the web. Most of the examples are Java-based, but I think there are ways to program in C++ as well.