I am looking for a c# function that do the same as getch()

  • Thread starter Thread starter oketz1
  • Start date Start date
O

oketz1

is there any function like this?

Console.Read is not good for me because I dont want to click Enter
after reading an input.


thanks ,

Okets

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
There might be something but I couldn't find it when I went looking either.
I ended up using _getch(), this worked for me:

using System;
using System.Runtime.InteropServices;

[DllImport("msvcr71.dll")]
static extern int _kbhit();

[DllImport("msvcr71.dll")]
static extern int _getwch();

[DllImport("msvcr71.dll")]
static extern int _getwche();

--Richard
 
Hey,
I do it in the way similar to the way Richard did,
but I use "EntryPoint" so I can name my methods anything
I want:
<code>
using System;
using System.Runtime.InteropServices;

namespace SomeTest_CS_Console
{
/// <summary>
/// Summary description for GetChInterop.
/// </summary>
public class GetChInterop
{
[DllImport("msvcr71.dll", EntryPoint="_kbhit")]
public static extern int KbHit();

[DllImport("msvcr71.dll", EntryPoint="_getwch")]
public static extern int GetCh();

[DllImport("msvcr71.dll", EntryPoint="_getwche")]
public static extern int GetChe();
}
}
</code>

Make a managed dll once, and forget the pain in the neck...
 
Back
Top