Console.KeyAvailable プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Console.KeyAvailable プロパティの意味・解説 

Console.KeyAvailable プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

キー押されたかどうか、つまり、押されキー入力ストリーム存在するかどうかを示す値を取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
解説解説
使用例使用例
' This example demonstrates the Console.KeyAvailable property.

Imports System
Imports System.Threading
Imports Microsoft.VisualBasic

Class Sample
   Public Shared Sub Main()
      Dim cki As New ConsoleKeyInfo()
      
      Do
         Console.WriteLine(vbCrLf & "Press a key to display;
 press the 'x' key to quit.")

' Your code could perform some useful task in the following loop. However,
 
' for the sake of this example we'll merely pause for a quarter second.

         While Console.KeyAvailable = False
            Thread.Sleep(250) ' Loop until input is entered.
         End While
         cki = Console.ReadKey(True)
         Console.WriteLine("You pressed the '{0}' key.", cki.Key)
      Loop While cki.Key <> ConsoleKey.X
   End Sub 'Main
End Class 'Sample

'This example produces results similar to the following text:
'
'Press a key to display; press the 'x' key to quit.
'You pressed the 'H' key.
'
'Press a key to display; press the 'x' key to quit.
'You pressed the 'E' key.
'
'Press a key to display; press the 'x' key to quit.
'You pressed the 'PageUp' key.
'
'Press a key to display; press the 'x' key to quit.
'You pressed the 'DownArrow' key.
'
'Press a key to display; press the 'x' key to quit.
'You pressed the 'X' key.
'
// This example demonstrates the Console.KeyAvailable property.
using System;
using System.Threading;

class Sample 
{
    public static void Main()
 
    {
    ConsoleKeyInfo cki = new ConsoleKeyInfo();

    do {
        Console.WriteLine("\nPress a key to display; press the 'x' key to quit.");

// Your code could perform some useful task in the following loop. However,
 
// for the sake of this example we'll merely pause for a quarter second.

        while (Console.KeyAvailable == false)
            Thread.Sleep(250); // Loop until input is entered.
        cki = Console.ReadKey(true);
        Console.WriteLine("You pressed the '{0}' key.", cki.Key);
        } while(cki.Key != ConsoleKey.X);
    }
}
/*
This example produces results similar to the following text:

Press a key to display; press the 'x' key to quit.
You pressed the 'H' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'E' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'PageUp' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'DownArrow' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'X' key.
*/
// This example demonstrates the Console.KeyAvailable property.
using namespace System;
using namespace System::Threading;
int main()
{
   ConsoleKeyInfo cki;
   do
   {
      Console::WriteLine( "\nPress a key to display; press the 'x' key to quit."
 );
      
      // Your code could perform some useful task in the following loop. However,
 
      // for the sake of this example we'll merely pause for a quarter
 second.
      while ( Console::KeyAvailable == false
 )
            Thread::Sleep( 250 );
      cki = Console::ReadKey( true );
      Console::WriteLine( "You pressed the '{0}' key.", cki.Key );
   }
   while ( cki.Key != ConsoleKey::X );
}

/*
This example produces results similar to the following text:

Press a key to display; press the 'x' key to quit.
You pressed the 'H' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'E' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'PageUp' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'DownArrow' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'X' key.
*/
// This example demonstrates the Console.KeyAvailable property.
import System.*;
import System.Threading.*;

class Sample
{
    public static void main(String[]
 args)
    {
        ConsoleKeyInfo cki = new ConsoleKeyInfo();
        do {
            Console.WriteLine("\nPress a key to display; press the 'x' key to"
                + " quit.");
            // Your code could perform some useful task in the following
 loop.
            // However,for the sake of this example we'll merely pause
 for a 
            // quarter second.
            while (Console.get_KeyAvailable() == false)
 {
                System.Threading.Thread.Sleep(250); // Loop until input
 is
                                                    // entered.
            }
            cki = Console.ReadKey(true);
            Console.WriteLine("You pressed the '{0}' key.", cki.get_Key());
        } while (!(cki.get_Key().Equals(ConsoleKey.X)));
    } //main
} //Sample
/*
This example produces results similar to the following text:

Press a key to display; press the 'x' key to quit.
You pressed the 'H' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'E' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'PageUp' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'DownArrow' key.

Press a key to display; press the 'x' key to quit.
You pressed the 'X' key.
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からConsole.KeyAvailable プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConsole.KeyAvailable プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConsole.KeyAvailable プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Console.KeyAvailable プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Console.KeyAvailable プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS