Console.KeyAvailable プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)



KeyAvailable プロパティは、押されたキーが入力ストリームに現れるのを待機することなく直ちに値を返します。
KeyAvailable プロパティは、Read メソッドや ReadLine メソッドではなく、必ず、ReadKey メソッドとの組み合わせで使用してください。

' 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. */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からConsole.KeyAvailable プロパティを検索する場合は、下記のリンクをクリックしてください。

- Console.KeyAvailable プロパティのページへのリンク