Sendkeys and multi-purpose keys

By | July 19, 2018

I’m making a software that can save consenting user’s keyboard and mouse inputs to reproduce them exactly as they did in order to track bugs. I’m to the point where most of this works but I have some details to workout when I’m reproducing some keys.

I’m currently using .NET’s famous SendKeys to do so and it works quite well.


The key string that I’m passing also handle multi-inputs with special keys, things like Shift+Ctrl+Left. For this example key = "+^{LEFT}";

But the way I’m saving the user’s input is starting to make things wierd when it comes to keys that can take multiple values depending on the control keys that are pushed. Typically, all of the non-alphanumerical characters.

For example if the user type the first numerical key. (The one that can give “1” or “!” on a QWERTY keyboard) I register the “D1” string that I generated from this line e.KeyCode.ToString() on a private async void OnKeyUp(object sender, KeyEventArgs e) event. Along with this, I registered the combined keys, like caplock, shift, alt and control so I can reproduce exactly the character the user typed. These data are stored as strings in a json file.

But here I’m stuck, how can I tell SendKeys that the user typed “D1” and with it, maybe some control keys? As far as I know, there are a very limited number of special keys in the SendKeys documentation (keys that doesn’t produce a character actually). I could just do a big switch and add a lot of conditions but it sounds like a lot of dirty work and could also be a problem with different types of keyboards. Is there a better solution?

Category: C#

Leave a Reply

Your email address will not be published. Required fields are marked *