June 2017

Retaining (and altering) key functions when using Console.ReadKey()

Because of the success of my earlier article about autocompletion in Windows Console, I decided to write another article dedicated to using the ReadKey while retaining key functionality.

When working on a console application, I wanted to implement a custom action when the tab key was pressed.

After doing some research, this turned out not to be as straightforward as I first thought. A lot of solutions offered for this problem included using the Console.ReadKey method. The problem with using this method is that it will disable a lot of other functionality like using the arrow up/down keys to scroll through the history of typed commands. Functionality I wanted to keep.

Obviously, when I want to implement functionality for a single key, I do not want the other functions that the console has to offer to be lost.

After some more Googling, I didn’t find any solution to this problem and I decided to write my own. I want to share my solution with the community.

I’ve tried a lot of different approaches, even intercepting keys directly from the operating system. None had the desired effect.

Eventually, I decided to reverse engineer the console functions that are being lost by using the ReadKey method. I’m not sure if the benefits outweigh the cost. But it was a nice project to work on and a good learning experience.

The article can be found here: https://www.codeproject.com/Articles/1189696/Retaining-and-altering-key-functions-when-using-Co

UGears Sponsorship

In the past I’ve created some UGears models. One of which I created a youtube movie for:

As it turns out, this video did not go unnoticed, as some time ago I received a message from the official UGears channel asking me if I’m interested to make some more video’s. The deal: Free UGears models for me!

Sounds like a win-win to me 🙂