国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#隱藏控制臺鍵盤輸入的方法

2020-01-24 01:58:21
字體:
來源:轉載
供稿:網友

本文實例講述了C#隱藏控制臺鍵盤輸入的方法。分享給大家供大家參考。具體如下:

using System;namespace RobvanderWoude{ class HideInput {  static int Main( string[] args )  {   try   {    bool clearscreen = false;    if ( args.Length > 1 )    {     return WriteError( "Too many command line arguments" );    }    if ( args.Length == 1 )    {     switch ( args[0].ToUpper( ) )     {      case "/C":       clearscreen = true;       break;      case "/?":       return WriteError( );      default:       return WriteError( "Invalid command line argument /"" + args[0] + "/"" );     }    }    // Set console foreground color to background color to hide what's being typed    ConsoleColor color = Console.ForegroundColor;    Console.ForegroundColor = Console.BackgroundColor;    // Read 1 line of input from the console    string input = Console.ReadLine( );    // Restore the original console foreground color    Console.ForegroundColor = color;    // Clear the screen id specified on the command line    if ( clearscreen )    {     Console.Clear( );    }    // Display the input - which should be redirected for this program to be of any use    Console.WriteLine( input );    // Returncode 0 for success, or 1 if the input was empty or whitespace only    if ( string.IsNullOrWhiteSpace( input ) )    {     return 1;    }    else    {     return 0;    }   }   catch ( Exception e )   {    return WriteError( e.Message );   }  }  public static int WriteError( string errorMessage = "" )  {   Console.ResetColor( );   if ( string.IsNullOrEmpty( errorMessage ) == false )   {    Console.Error.WriteLine( );    Console.ForegroundColor = ConsoleColor.Red;    Console.Error.Write( "ERROR: " );    Console.ForegroundColor = ConsoleColor.White;    Console.Error.WriteLine( errorMessage );    Console.ResetColor( );   }   Console.Error.WriteLine( );   Console.Error.WriteLine( "HideInput, Version 1.10" );   Console.Error.WriteLine( "Batch utility to read 1 line of input while hiding what's being typed, by" );   Console.Error.WriteLine( "temporarily setting the console foreground color equal to its background color" );   Console.Error.WriteLine( );   Console.Error.Write( "Usage: FOR /F /"tokens=*/" %%A IN ('" );   Console.ForegroundColor = ConsoleColor.White;   Console.Error.Write( "HIDEINPUT" );   Console.ResetColor( );   Console.Error.WriteLine( "') DO SET password=%%A" );   Console.Error.Write( "  or: FOR /F /"tokens=*/" %%A IN ('" );   Console.ForegroundColor = ConsoleColor.White;   Console.Error.Write( "HIDEINPUT /C" );   Console.ResetColor( );   Console.Error.WriteLine( "') DO SET password=%%A" );   Console.Error.WriteLine( );   Console.Error.Write( "Where: " );   Console.ForegroundColor = ConsoleColor.White;   Console.Error.Write( "/C" );   Console.ResetColor( );   Console.Error.WriteLine( " clears the screen to remove what's typed from the screen buffer" );   Console.Error.WriteLine( );   Console.Error.WriteLine( "Written by Rob van der Woude" );   return 1;  } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阜新市| 辛集市| 齐河县| 东辽县| 西城区| 溧水县| 巴中市| 林州市| 二连浩特市| 华容县| 包头市| 仁寿县| 日喀则市| 周口市| 米林县| 北碚区| 临西县| 长丰县| 砀山县| 广平县| 桂阳县| 健康| 长顺县| 营山县| 历史| 松江区| 涪陵区| 永吉县| 苗栗市| 赤城县| 靖安县| 杂多县| 龙泉市| 黄冈市| 商城县| 乐清市| 亚东县| 罗源县| 治县。| 日土县| 宁明县|