Coding STEM

How to change keyboard strokes (C/C++) Part 2/2

This is part 2. Please refer to the part 1 for context.

In the following simple C program, I’ll demonstrate how to capture keystrokes and turn them into something completely different…other than what the key labels read. This is the basic idea behind changing keyboards from English to another language; take the input from the key, read its character code (ordinal value) from the operating system, and change it to another code also stored in the operating system’s character tables, then display the changed character on display and editor.This is also a way some of the malware programs exploit this feature to confuse the user, and even extort ransom money.

Note that the programs are for education purposes only.  Do NOT use this for any malicious purpose! These programs will NOT permanently change your input system. They’ll only affect the console WHILE the programs are running and everything will return to normal after you quit them.

So, let’s get down to code!

Code and Explanation:

As before, I’ll use getch() function that prompts the user (and waits) for an input…but only for 1 key press (not function keys), and store it in a variable c. Great! But I’ll display something else! Other than what was entered. I do that by selecting a character from an array s[] in sequence. And using good trusty printf() function, we display a new character from the s[] array instead of what was entered.

In this version, I’ll use a funny typing exercise (it’s a great fun program to fool your non-techy family/friends, really). Once user starts the program, they’ll be asked to enter sentences to “test” their typing speed. However, SURPRISE! Nothing they type is showing up as expected 🙂

As before in previous blog part, I use getch() and a s[] array of strings. See the previous blog for context with link above.

So, as the user keeps typing the sentences, strange characters are being processed by the computer! It’s confusing, frustrating! Infuriating! Well, then you can explain how you wrote the code for fun and education.

This time, the variables are set as below:

char s[]=””This is a simple paragraph that is meant to be nice and easy to type and should help you get faster at typing. However, there’s a comma right there! And as I’m trying not to use too many difficult words in it although I think that I just might. I wish you the best of luck getting the best score.””;
printf(“Please start typing the following paragraph so we can assess your typing skills!\r\n\r\n”);

And use getch() as before. But in this version, I’m shifting the character code just by 1 ordinal value and showing it 🙂


Everything else is same as the part 1. To download this application, go here and download the zip file (for security). And then extract the FunnyKeyCapture2.exe to wherever you like and double-click to run it.

You’ll laugh!

One thought on “How to change keyboard strokes (C/C++) Part 2/2

Leave a Reply

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

Back To Top