Sending keystrokes to the console

Posted on

One of the ways Console Wrapper is currently lacking, is that it doesn’t have a full set of features that one would expect from a regular console. Some are being built in (such as command history), but TAB completion, Ctrl-C process kill etc are still missing. These could be solved (in theory) by directly passing advanced keystrokes through to the console process.

ConsoleWrapper currently communicates with the console process via input and output streams. These allow for sending and receiving of string data, but not specific keystrokes (such as Ctrl-C). Unfortunately I’m still working on exactly how I can pass a key to the console. Because it doesn’t run in its own window (in order to capture input/output streams and hide the real console from the user) normal WinAPI methods for sending keystrokes do not work, as they target a window handle. In fact the regular console may not even have a message queue. So for now I’m stuck experimenting with SendMessage and WM_KEYDOWN, WM_KEYUP, etc. Not a nice clean .NET solution as I would have liked!