compile both in Linux and DOS, I need to be able to just enter one charac from the keyboard to issue a command without hitting the enter key or a carriage return. How would I code the input portion after a menu of commands has been displayed on the console?
http://msdn.microsoft.com/en-us/library/ms684958%28VS.85%29.aspx http://www.mkssoftware.com/docs/man3/curs_getch.3.asp
Re: Input without Carriage Return (Enter)
By: Nightfox to Jon Justvig on Thu Aug 06 2009 06:28 pm
http://msdn.microsoft.com/en-us/library/ms684958%28VS.85%29.aspx http://www.mkssoftware.com/docs/man3/curs_getch.3.asp
Thank you for the links. I will look into these when I get more time. I will most certainly bookmark them now.
No problem. Come to think of it, though, nCurses might not be the best answer for Linux. I've worked with nCurses before, and I know it has functions that input a single character from the user without the user havin to press Enter, but nCurses is a full-blown character interface library dealing with "screen" structures; you need to initialize nCurses before you use any of its functions, and then de-initialize it when you're done, and th process of doing that will clear the screen.
I imagine there must be some C or C++ function in Linux that does what you want to do.
Hmmm...you don't suppose nCurses also includes normal color ANSi as well? Right now my code does not have any color in it. If so, I could tolerate clear screens as long as it doesn't interfere with game play.
I imagine there must be some C or C++ function in Linux that does what want to do.
I'm hoping there is. I used the header, windows.h, I believe, but, it wo not work with linux obviously and I wanted the code to be portable to bot dos and linux. So, I've been looking around. I'll be glad when I start
Hmmm...you don't suppose nCurses also includes normal color ANSi as well?
Hi all, I've been dealing with a problem for quite some time and was wondering if someone could help me with this. I have written a program that is currently under development and has not been released because it's far from a public beta release. Anyway, I use std::cin to ask for input from a menu of different option. My question is this. Dealing with portability to compile both in Linux and DOS, I need to be able to just enter one character from the keyboard to issue a command without hitting the enter key or a carriage return. How would I code the input portion after a menu of commands has been displayed on the console?
Hi all, I've been dealing with a problem for quite some time and was wondering if someone could help me with this. I have written a program that is currently under development and has not been released because it's far from a public beta release. Anyway, I use std::cin to ask for input from a menu of different option. My question is this. Dealing with portability to compile both in Linux and DOS, I need to be able to just enter one character from the keyboard to issue a command without hitting the enter key or a carriage return. How would I code the input portion after a menu of commands has been displayed on the console?
I don't think such a function exists in standard C++ or C.
One thing you could do is to write your own function for inputting a character from the user and implement it differently, depending on which platform you're compiling on. You'd have the function decleared in a header file, and you can have the implementation in separate .cpp files (one for each platform), or a single .cpp file with pre-processor diretives around th implementations so you can give the pre-processor the appropriate flag, and it would compile the appropriate code in the .cpp file.
In Win32, there may be functions provided that do this. This page on Microsoft's MSDN site describes ReadConsole() - I haven't used this, but it may do what you want (although it looks a bit more complicated to use than cin):
http://msdn.microsoft.com/en-us/library/ms684958%28VS.85%29.aspx
The Linux implementation could use the nCurses library. nCurses has functions for getting a single character, such as getch(), wgetch(), etc.: http://www.mkssoftware.com/docs/man3/curs_getch.3.asp
I hope this helps.
...I think in Visual Studio, i'm a little foggy, but conio useta be present as of 6.0.. so you can #include <conio.h> i think in more recent version
then just calling getch() would get a hotkey.
That may work in Windows, but I believe Jon Justvig is working in Linux and wants his door to at least work in Linux. For a multi-platform solution, th are ways to use the appropriate function depending on which platform you're using.
used the DevC++, and sorta riped out their conio.h and included it in my own
used the DevC++, and sorta riped out their conio.h and included it in my
I love Bloodshed Dev++, works great for me.
Mercyful Fate wrote to Jon Justvig <=-
Re: Input without Carriage Return (Enter)
By: Jon Justvig to Mercyful Fate on Sat Nov 14 2009 12:08:07
used the DevC++, and sorta riped out their conio.h and included it in my
I love Bloodshed Dev++, works great for me.
i agree, in windows it's one of the best free compilers there is,
although i haven't touch in a long time since 2002 when i made to
switch to full linux on my home systems. The last i saw though the compiler wasn't being updated as ofthen as i would have liked, not sure how current it is anymore, but defently very nice.
If you want a great IDE though, you should check out eclipse, i found that recently and it's pretty dam sweet.
If you want a great IDE though, you should check out eclipse, i found th recently and it's pretty dam sweet.
I thought Eclipse was mainly for Java, but it has been several years since I tried it. I'd be curious to try it for C++.
Nightfox wrote to Mercyful Fate <=-
Re: Input without Carriage Return (Enter)
By: Jon Justvig to Mercyful Fate on Wed Dec 02 2009 10:36:22
If you want a great IDE though, you should check out eclipse, i found th recently and it's pretty dam sweet.
I thought Eclipse was mainly for Java, but it has been several years
since I tried it. I'd be curious to try it for C++.
If you want a great IDE though, you should check out eclipse, i found recently and it's pretty dam sweet.
I thought Eclipse was mainly for Java, but it has been several years since I tried it. I'd be curious to try it for C++.
Sysop: | Darkmage |
---|---|
Location: | Tucson, Arizona USA |
Users: | 3 |
Nodes: | 4 (0 / 4) |
Uptime: | 72:50:03 |
Calls: | 2 |
Calls today: | 2 |
Files: | 19 |
U/L today: |
1 files (4K bytes) |
D/L today: |
136 files (6,106K bytes) |
Messages: | 35,389 |
Posted today: | 12 |