key = ReadConsoleKey()
Delay option to False in SetConsoleOptions(). In that case,
ReadConsoleKey() will return #CONSOLEKEY_NONE in case no key has been pressed.
If ReadConsoleKey() is set to wait until a key is pressed, its behaviour is also influenced by
the CBreak setting of SetConsoleOptions(). If CBreak is set to True, which is also the
default, one key press is enough to make ReadConsoleKey() stop blocking and return. If CBreak is
set to False, however, it will block until a newline occurs.
By default, the key that the user presses is echoed in the console. If you don't want that,
set the Echo tag in SetConsoleOptions() to False.
Finally, ReadConsoleKey() can also read function keys like F1, F2, cursor keys, ESC and so on.
If you want ReadConsoleKey() to support function keys, you must put the console into keypad mode
by setting the Keypad tag in SetConsoleOptions() to True. If you have done that,
ReadConsoleKey() can also return the following function keys:
#CONSOLEKEY_ENTER #CONSOLEKEY_UP #CONSOLEKEY_DOWN #CONSOLEKEY_RIGHT #CONSOLEKEY_LEFT #CONSOLEKEY_BACKSPACE #CONSOLEKEY_DEL #CONSOLEKEY_F1 #CONSOLEKEY_F2 #CONSOLEKEY_F3 #CONSOLEKEY_F4 #CONSOLEKEY_F5 #CONSOLEKEY_F6 #CONSOLEKEY_F7 #CONSOLEKEY_F8 #CONSOLEKEY_F9 #CONSOLEKEY_F10 #CONSOLEKEY_F11 #CONSOLEKEY_F12 #CONSOLEKEY_F13 #CONSOLEKEY_F14 #CONSOLEKEY_F15 #CONSOLEKEY_F16 #CONSOLEKEY_INSERT #CONSOLEKEY_HOME #CONSOLEKEY_END #CONSOLEKEY_PRINT #CONSOLEKEY_PAGEUP #CONSOLEKEY_PAGEDOWN #CONSOLEKEY_IC #CONSOLEKEY_EIC |
As you can see, many SetConsoleOptions() options influence the behaviour of ReadConsoleKey().
See SetConsoleOptions for details.
You must enable advanced console mode using EnableAdvancedConsole() before you can use this function. See EnableAdvancedConsole for details.
#CONSOLEKEY_NONE if no key has been pressed and
the console is in NoDelay mode