Here it is in text:
using System;
using System.IO;
using System.Threading;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections;
namespace ConsoleInput
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
[DllImport("kernel32", SetLastError=true)]
static extern IntPtr GetStdHandle(IntPtr whichHandle);
[DllImport("kernel32", SetLastError=true)]
static extern bool GetConsoleMode(IntPtr handle, out uint mode);
[DllImport("kernel32", SetLastError=true)]
static extern bool SetConsoleMode(IntPtr handle, uint mode);
[DllImport("kernel32", SetLastError=true)]
static extern bool FlushConsoleInputBuffer(IntPtr hConsoleInput);
static readonly IntPtr STD_INPUT_HANDLE = new IntPtr(-10);
const int ENABLE_LINE_INPUT = 2;
const uint ENABLE_ECHO_INPUT = 4;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Hit any key to input password:");
int key = GetChar();
Console.WriteLine("{0} was hit.", key);
Console.WriteLine();
Console.Write("Enter password:");
string password = null;
password = GetPassword();
Console.WriteLine("Password is:"+password);
Console.WriteLine("\nHit any key to continue.");
GetChar();
}
/// <summary>
/// Returns an int of the key pressed at the console.
/// This returns when key is hit, so does not require Enter as
Console.Read().
/// </summary>
/// <returns></returns>
static int GetChar()
{
// Turn off console echo.
IntPtr hConsole = GetStdHandle(STD_INPUT_HANDLE);
uint oldMode;
if ( ! GetConsoleMode(hConsole, out oldMode) )
throw new ApplicationException("GetConsoleMode failed");
uint newMode = oldMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
if ( ! SetConsoleMode(hConsole, newMode) )
throw new ApplicationException("SetConsoleMode failed");
int i;
try
{
i = Console.Read();
return i;
}
finally
{
// Restore console echo and line input mode.
if (!SetConsoleMode(hConsole, oldMode))
throw new ApplicationException("SetConsoleMode failed");
}
} // End GetChar
static string GetPassword()
{
// turn off console echo
IntPtr hConsole = GetStdHandle(STD_INPUT_HANDLE);
uint oldMode;
if (!GetConsoleMode(hConsole, out oldMode))
{
throw new ApplicationException("GetConsoleMode failed");
}
uint newMode = oldMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
if (!SetConsoleMode(hConsole, newMode))
{
throw new ApplicationException("SetConsoleMode failed");
}
int i;
StringBuilder secret = new StringBuilder();
while (true)
{
i = Console.Read ();
if ( i == 13 ) // break when <return>
break;
if ( i == 8 )
{
if ( secret.Length > 0 )
{
Console.Write("\b \b");
secret.Remove(secret.Length - 1, 1);
}
}
else
{
secret.Append((char) i);
Console.Write ("*");
}
}
Console.WriteLine();
// Restore console echo and line input mode.
if ( !SetConsoleMode(hConsole, oldMode) )
{
throw new ApplicationException("SetConsoleMode failed");
}
return secret.ToString();
} // End GetPassword
}
}
--
William Stacey, MVP
"Juank" <ju***@etb.net.co> wrote in message
news:1D**********************************@microsof t.com...
yes, this is my Q..
but if you see your own post..
you see that no code appear here...
i really waana see the code.. but i can`t see anything aniwhere in your
last post
tx anywhere.. but preffer post your code in a place taht i can see..
again sorry.. but my english is some poor...