Yes I have seen other threads like this, but they do not really satisfy my need
Then please list your requirements. The threads you speak of usually result in something like this (using Windows since you mentioned WM_KEYDOWN):
char& raw_input(char& ch)
{
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD old_mode, n;
// Switch to raw input mode
GetConsoleMode(h, &old_mode);
SetConsoleMode(h, ENABLE_PROCESSED_INPUT);
if (WaitForSingleObject(h, INFINITE) == WAIT_OBJECT_0)
ReadConsole(h, &ch, 1, &n, 0);
// Switch back to the original input mode
SetConsoleMode(h, old_mode);
return ch;
}
This is a facsimile of getch(). If that doesn't satisfy your needs then neither does getch(), in which case you need to specify what you needs are.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
I need something that is the EXACT same as _getch(); but doable on all Operating Systems and all Compilers.
What part of non-portable is difficult to understand?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
What part of non-portable is difficult to understand?
I don't understand what your talking about.
I need something like _getch(); using just the standard libraries(or less). And no Operating System specific libraries/headers.
Clear and succinctly:
There isnothing, repeat nothing like getch() that is
1) portable
2) not O/S specific
3) not compiler specific
4) standard
in C++NOTHING. Period.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
I need something like _getch(); using just the standard libraries(or less). And no Operating System specific libraries/headers.
Well, that simplifies things greatly. What you want is impossible. Have a nice day.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
How is it impossible if the compiler has it. It is obvious that it can be written in Assembly. Well in that case I am in the wrong forum. Thanks!
If other forums explain how this can be done, please come back and explain it to us and we will apologize profusely. We will also learn something evenwe don't know.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
How is it impossible if the compiler has it.
The compiler is closely tied to its target system, it doesn't have to care about the implementation of getch() being portable. For example, you'll find that Visual Studio's implementation of getch() is very similar to the one I posted above because it's a Windows-targeted compiler.
Compilers that target multiple systems will havemultiple builds where the non-portable parts are rewritten for each target system.
What you're asking for is impossible because when it comes to operating system dependencies there's no single implementation that will work everywhere, and getch() has an operating system dependency of direct access to console input rather than the cooked input coming in from the standard input stream.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401