ReadConsole may not be sufficient for INKEY$, but...by Anonymous (no login)
ReadConsoleInput requires a lot of work in C alone, nevermind ASM. It can read keyboard events (both key down AND key up, so you'd end up with two events), mouse events (movement, click/"unclick", scrolling, etc.) and window events (resizing, moving, etc.).
I'll try to explain the steps, but it is difficult to explain in a comprehensible manner and still get low-level with all of the data structures being used.
The first thing to know is which data structures are relevant. ReadConsoleInput takes the address of an INPUT_RECORD structure as one of its parameters.
The INPUT_RECORD structure has two members:
EventType - can be a number of events, but you want KEY_EVENT, which is 1
Event - the actual event, which is really just a union of all possible event records; you want Event.KeyEvent
After determining that the EventType is KEY_EVENT, you'll want to figure out what the key was, right? You use the KeyEvent item in the Event union for that. KeyEvent is a KEY_EVENT_RECORD structure. It has six members, but the important ones are the following:
bKeyDown - nonzero if the key is currently down
uChar - a union of UnicodeChar and AsciiChar
dwControlKeyState - ctrl, shift, numlock, numpad keys, arrow keys, page up/down, home/end, etc. (multimedia keys as well?)
wVirtualKeyCode - F1-F12 events need captured, too
Now for the functionality...
If you press a key down, you must release it, right? That's two events. bKeyDown will be nonzero the first time and then zero the second time.
dwControlKeyState and uChar.UnicodeChar must be checked. After all, who said you wanted ONLY the Ctrl key to be considered input?
uChar.UnicodeChar is what you'd most likely want, but don't forget that the Ctrl key, the Shift key and others are not actually characters. Likewise, F1-F12 apparently aren't control keys. They are, however, still defined and recognized as virtual keys.
wVirtualKeyCode is mainly for miscellaneous key events. dwControlKeyState can handle a lot of non-character keys, but F1-F12 still need a way to be recognized. That's what wVirtualKeyCode is for. It can also be used to determine whether something like backspace and other non-printable characters were pressed.
The basic idea:
1. Was it a keypress or something else?
2. Is it an actual character?
3. Is it considered a control character?
4a. Do we do something with this control key, perhaps read another input record to capture something like Ctrl-V?
4b. Is the key a function key?
5. What is this key/combination...? (Silently ignore it and try reading again)
It's not easy in C, and it probably won't be terribly easy in ASM. I'd advise starting with characters, then adding stuff for control sequences.
|Response Title||Author and Date|
|Re: ReadConsole may not be sufficient for INKEY$, but...||on Feb 12, 7:12 PM|