Ignoring shift key while counting characters C# winforms

99 Views Asked by At

I'm working on a function in a C# winforms application that will count characters entered into a richtextbox, but needs to ignore the backspace and shift keys.

Here is the code I've got for this part:

private void inputBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Back || e.KeyCode == Keys.LShiftKey || e.KeyCode == Keys.RShiftKey || e.KeyCode == Keys.Shift)
        characterCount += 0;
    else
        characterCount++;
}

Regardless of this being included, it will still count any instance of the Shift Key. Can someone tell me where I'm going wrong? Please let me know if you need anymore information/code!

Update: Solved my own question. Keys.ShiftKey was what I needed. Posted it as an answer too.

1

There are 1 best solutions below

0
Conrad37 On BEST ANSWER

To anybody who looks, my own dumb ass solved the problem. I needed to use Keys.ShiftKey. Apparently I missed that when it worked earlier (because I had it but it didn't give me my results, or I missed it.