The console Read
command does not recognize VK_ESCAPE
. When using ReadConsoleInput
, it is case insensitive. Is there something adequate to Read
/Readln
, which reports an abort?
Asked
Active
Viewed 227 times
0
-
See https://stackoverflow.com/a/16023313/576719. – LU RD Sep 21 '21 at 10:18
-
VK_ESCAPCE? ATypo? – Dsm Sep 21 '21 at 12:07
-
@Dsm see unit `Winapi.Windows.VK_ESCAPE` – USauter Sep 21 '21 at 12:19
-
@USauter: Which is indeed very different from your original `VK_ESCAPCE`! – Andreas Rejbrand Sep 21 '21 at 22:23
1 Answers
2
- The docs on
Read()
tell you it's for characters, not keys in general. It will also not help you to i.e. recognize PgUp or Print. That's also why it is so similar toReadln()
, which unsurprisingly is for text, too, not separate keys being pressed. - A console process does not know by default what "abort" means. Common knowledge (even unbound to Windows) is that Ctrl+C and/or Ctrl+Break terminate the process.
- Neither a
ReadConsoleInput()
nor is its KEY_EVENT record case insensitive: again you get keys, not characters. Which means you have to check if.dwControlKeyState
has eitherSHIFT_PRESSED
orCAPSLOCK_ON
set to translate all the keys into an appropriate character (i.e. only Shift+S makes it an uppercase S).
It's up to you to decide when to interpret keys and when treating input as text/characters. Yes: recognizing Esc while using Readln()
will never work - you'd have to reinvent your own Readln()
, i.e. dealing with all the input, including your favorite keys, such as Esc. This will also help you discover which keys (that you type) lead to which VK constants.

AmigoJack
- 5,234
- 1
- 15
- 31