Jump to content
  • Advertisement
Sign in to follow this  
DarkSol

The Almighty C# Console Mode

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!