xtd 0.2.0
Loading...
Searching...
No Matches
console_key_available.cpp

Shows how to use xtd::console::key_available and xtd::console::read_key methods.

#include <xtd/threading/thread>
#include <xtd/console>
using namespace xtd;
using namespace xtd::threading;
auto main() -> int {
auto cki = console_key_info {};
do {
console::write_line("\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::key_available() == false)
thread::sleep(250_ms); // Loop until input is entered.
cki = console::read_key(true);
console::write_line("You pressed the '{0}' key.", cki.key());
} while (cki.key() != console_key::x);
}
// This example produces results if user stroke 'h', 'e', pagge_up, down_arrow, and 'x' keys
//
// 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 'page_up' key.
//
// Press a key to display; press the 'x' key to quit.
// You pressed the 'down_arrow' key.
//
// Press a key to display; press the 'x' key to quit.
// You pressed the 'x' key.
Specifies the standard keys on a console.
Definition console_key_info.h:24
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10