Anyone ever been able to do this in raw C++ ? I tried and never got it. I can do it in assembly block wrapped up in c++, but not anything clean. I suspect however ncurses did it is not pure c++ either? I tried to do it with peeks and clears and all, and it may be doable, I just lost focus on it as I was playing around.
"raw C++" meaning no OS API calls? Probably not. As I'm sure you know, C++ doesn't know what "enter" or a key press means, that's the job of the terminal. C++ just receives the data it's given.
./doc/hackguide.doc: All ncurses input funnels through the function wgetch(), defined in ...
./doc/html/hackguide.html: <code>wgetch()</code>, defined in <code>lib_getch.c</code>. This
lib_getch.c shows wgetch as defined, located at: ncurses\base\lib_getch.c
wgetch calls _nc_wgetch... which calls other functions, include PTHREADS-related calls. I'd imagine at some point it will make an OS-specific API call.
# The getch method can determine which key has been pressed
# by the user on the keyboard by accessing the system files
# It will then return the pressed key as a variable
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
I would take something off color that was portable too, but no OS or CPU specifics.
Maybe I will pick that up again... or at least see where I left it and such.
looks like readsome can do it for some compilers, but not all.
and I found a 3 page threaded one that was exceedingly complicated.
no joy in Cygwin/g++ yet. changing stdin params or setting it to be used by cin didn't help. readsome didn't work. Peeks didn't work. Simplest thing is a royal pain if your compiler (or is it the OS) doesn't want you to do it.