Sign in to follow this  
DarkSol

The Almighty C# Console Mode

Recommended Posts

ErrrR grumble grumble.. C# has crapy console more classes. Is any good function that checks to see if there has been a key pressed? Or that checks to see if any keypresses are in the buffer? The function must not block if there is no keypresses. I don't thnik I can use windows.froms events to keypresses, becouse it's a console app there are no controls to capture it on. Any help? [Edited by - DarkSol on September 1, 2004 7:55:19 PM]

Share this post


Link to post
Share on other sites
Ahhh.. of couse. must be something I did to it.

thanks afterburn. not to find a what I did to make it block.



//got to be this thats caseing the problem.
[DllImport("kernel32.dll", EntryPoint="SetConsoleMode", SetLastError=true, CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int SetConsoleMode(IntPtr hConsoleHandle, int dwMode);

[DllImport("kernel32.dll", EntryPoint="GetConsoleMode", SetLastError=true, CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int GetConsoleMode(IntPtr hConsoleHandle, ref int dwMode);


const int ENABLE_LINE_INPUT = 2;
const int ENABLE_ECHO_INPUT = 4;
const int STD_INPUT = 3;

IntPtr hStdIn = new IntPtr(STD_INPUT);
int mode=0;

GetConsoleMode(hStdIn, ref mode);
mode = (mode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));
SetConsoleMode(hStdIn, mode);



int s="-this is the default blank";
//here is my read
s = Console.Read();

Share this post


Link to post
Share on other sites
I used Visual C# Express Beta on a friends computer(thus using C# 2.0 and the .NET Framework 2.0 beta). The 2.0 version of the .NET framework has a lot of nice functions for console support. Colors, etc. Although to use it you'll have to wait until 2.0 is release final before you distribute your app. I don't have the beta's install on my computer because I have visual studio 2003 and everything working good and I don't want to mess it up somehow.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this