No support for this in .NET 1.1, however you always can use P/Invoke to
switch the console from line mode to character mode.
using System;
using System.Runtime.InteropServices;
public class Con {
const int STD_INPUT_HANDLE = -10;
const int ENABLE_LINE_INPUT = 0x0002;
const int ENABLE_ECHO_INPUT = 0x0004;
[DllImport("kernel32")]
public static extern IntPtr GetStdHandle( int nStdHandle);
[DllImport("kernel32")]
public static extern bool GetConsoleMode( IntPtr hConsoleHandle, ref int
pmode);
[DllImport("kernel32")]
public static extern bool SetConsoleMode( IntPtr hConsoleHandle, int mode);
public static void EnableCharMode() {
IntPtr hConsole;
int mode= 0;
hConsole = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hConsole, ref mode);
// must turn off echo mode when character input
mode &= ~ (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
SetConsoleMode(hConsole, mode)
}
public static void EnableLineMode() {
IntPtr hConsole;
int mode=0;
hConsole = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hConsole, ref mode);
mode |= (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
SetConsoleMode(hConsole, mode)
}
Create an instance of the class and call EnableCharMode when single char
input is required, dont forget to reset the console to
linemode before terminating the program.
--
Tamir Khason
You want dot.NET? Just ask:
"Please,
www.dotnet.us "
"Jay" <j@h.com> wrote in message news:aliGc.2937$r3.680@okepread03...
How do I get only one character from the keyboard without having to hit
return like in the C function getch();