Overlapped keyboard input from console?
Posted on 1998-07-21
Is it possible to do some overlapped keyboard input from a console window in Windows NT?
What I am trying to accomplish here is a little like the terminal principle. I have one handle for a communications port, opened for OVERLAPPED operations. Then I'd like to create another OVERLAPPED handle to the keyboard. With both OVERLAPPED structures set with manual reset events, this would allow me to perform a WaitForMultipleObject, which would block until either the user input a keystroke or a byte arrived on the port. I would then be able to act accordingly (i.e. send the keystroke to the port if it's a keyboard event, or output the byte received from the port to the console). Essentially, it's the terminal principle, but SINGLE threaded. I know this could easily be done multi-threaded (and I've done it) but now I am trying to also do a single threaded program which would be the equivalent.
When you use GetStdHandle to get a handle to stdin, there is no OVERLAPPED struct initialization, so every read from the keyboard will block. Also, when you do a CreateFile on CONIN$, the Microsoft Win32 Reference says the dwFlagsAndAttributes parameter is ignored, keeping me from using FILE_FLAG_OVERLAPPED to enable overlapping operations.
Am I the first one to try this? I would be grateful if somebody could point out a working solution, without polling if possible.