that is the thing, a thread dedicated only to wait for user input sounds like a waste
(not necessarily a big one, but it feels like it should have an
implementation for this).
I wouldn't be concerned about this for a console app that expects user input.
Anyhow, it might be possible to achieve what you're after by using some underlying Win32 APIs. The docs for ReadConsoleInput
say:
A process can specify a console input buffer handle in one of the wait
functions to determine when there is unread console input. When the
input buffer is not empty, the state of a console input buffer handle
is signaled. To determine the number of unread input records in a
console's input buffer, use the GetNumberOfConsoleInputEvents
function. To read input records from a console input buffer without
affecting the number of unread records, use the PeekConsoleInput
function. To discard all unread records in a console's input buffer,
use the FlushConsoleInputBuffer
function.
So, in theory, you could use a handle returned by GetStdHandle
and pass it to
RegisterWaitForSingleObject
. Then you could convert it to an awaitable task using TaskCompletionSource
, e.g. as described here.
I haven't verified this in practice. It shoudn't be blocking a thread, but IMO, again, the game isn't worth the candle.