| rohan misra032 (3) | |
|
hi everyone this is my first time that i m wriring in this forum....... presetly i m persuing a B.Tech degree ( 1st year ) and thus i m in to a lot of programming ....... due to which i hv encountered alot of problems that i would like to be solved as i was not able to find the solutions of these........ for instance.....in a normal c++ program i was required to take a chracter as an input and process the input without carriage return i.e. as soon as the the character is pressed from the keyboard the required processes take place..... in complete reference c++ i read that in the header file conio.h the function getch() does the same function as required by me ......... but when i used it then it showed that no such header file exists... so now if anyone can solve my dilemma then he is of course welcome........ | |
|
|
|
| Duoas (6333) | |
|
You have to play with the OS to do that. The NCurses (Unix/Linux/OS X) or the equivalent PDCurses (DOS, Win, OS/2) libraries make it very easy to write cross-platform code that will do this. If you want to get into the nitty gritty, play with SetConsoleMode on Windows. It is a little more involved on POSIX platforms. Let me know if you want to do that. (I still recommend you use Curses, because it has nice facilities to translate function key code sequences into a single value using wgetch().) Hope this helps. | |
|
|
|
| rohan misra032 (3) | |
|
i exactly do not understand as what do u mean by curses as i hv never come across such a word....so please if u can elaborate on this than it might be of help.... thanx for ur reply... | |
|
|
|
| Duoas (6333) | |
| Google "ncurses" and see what you'll find... | |
|
Last edited on
|
|
| Airam (1) | |
|
Hello!! I've got the answer to do that in that web page: (WITHOUT USING NCURSES!!!) http://airamrguez.blogspot.com/2008/02/cmo-implementar-la-funcion-getch.html | |
|
Last edited on
|
|
| Duoas (6333) | |
|
I hate to burst your bubble, but that only works on Unix, it cheats, it is chock-full of dangerous security holes, it creates extra files wherever it is used (kind of like having a dog that poops all over your house) without cleaning up after itself, and it will fail if the file already exists (or, fixing that, it could destroy a legitimate file). It is easy, though. If you are not doing this just for a homework assignment, then be aware that you are doing something that could get you fired for the security problems alone, if not the others mentioned. NCurses really isn't that hard to use, and it will allow you to get non-buffered input while properly translating function key sequences into a single keycode, and it is very portable. Type "man initscr" at the terminal to get started. If you want a simple example, let me know. | |
|
|
|
| Duoas (6333) | |||
OK, I decided to post a simple example anyway. Since this is a C++ forum, I've used a std::string to highlight some steps necessary to pass them to the curses routines.
To compile this code on Windows, I assume that you have PDCurses installed. g++ example.cpp -lpdcurses On Linux and many if not most Unices: g++ example.cpp -lcurses If it makes a difference on your version of Unix (because it is linking with the old Curses library instead of the desired NCurses library): g++ example.cpp -lncurses If you are linking on Solaris or some other system where NCurses was installed with the --disable-overwrite option, you'll need to tell your compiler where to find the correct "curses.h" header file: g++ example.cpp -I/usr/local/include/ncurses -lncurses Hope this helps. | |||
|
Last edited on
|
|||