For gettin input without the user hitting enter in a console application.
Thanks in advance.
Printable View
For gettin input without the user hitting enter in a console application.
Thanks in advance.
Console.Read() or Console.ReadLine()
Then how do I do it so they dont wait for the user to press enter?
How about _getch()?
Code:using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("msvcrt")]
static extern int _getch();
static void Main(string[] args)
{
Console.WriteLine("Hello world");
Console.WriteLine("Press any key to end..");
_getch();
}
}
}
Thanks, Im going to try that.
[edit]
Yep, that did it. Thanks a lot.
Not a problem.Quote:
Originally Posted by Marcos
I think it will be better to use Console.ReadKey(true) insteed of
Quote:
[DllImport("msvcrt")]
static extern int _getch();
Yeah Console.Readkey(true/false) works best.
AHHH! Zombie Thread!
Actually I think this one is quite desirable. He did provide new and meaningful information. ReadKey() is indeed the best option. PInvoke is a last resort solution and rarely advisable. The thread just got richer with his post.
Could still be closed at this point though, I guess. But for creating an account just to correct a thread you probably got from a search engine... my hat to you, Kirow. And thanks.
While the info was useful this thread still is considered an old thread and therefore I am going to close it. If anyone would like to discuss the new information feel free to start a new thread about the topic.
Closed.