Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Windows.Forms.Keys - Lower or Uppercase?

Tags:

c#

case

winforms

I have been searching around for an answer to this but I can't seem to find anything. Does anyone know if you can determine the letter casing in Keys?

For example:

if (System.Windows.Forms.Keys.A.ToString() == "A")
{
    // Upper or Lower?
}

Thanks.

like image 658
Bali C Avatar asked Jan 11 '12 16:01

Bali C


3 Answers

There is no casing, it represents a physical key on your keyboard. Do you see an 'a' and an 'A' on your keyboard?

You can check and see if a Shift key is depressed.

like image 81
Steve Wellens Avatar answered Oct 14 '22 07:10

Steve Wellens


System.Windows.Forms.Keys.A represents the physical key A on your keyboard. It does not have a case. Thus, your question does not make sense.

If you want to check whether the user holds the Shift key on the keybord, there's also System.Windows.Forms.Keys.Shift.

like image 35
Heinzi Avatar answered Oct 14 '22 08:10

Heinzi


There is no simple mapping between keys and characters. Keyboard layouts can work differently. One example are dead keys. And once you get to IMEs it gets even more complicated. Do not try to duplicate a keyboard layout manually in your application.

If you want to get what character a user entered, handle WM_CHAR, not WM_KEY_DOWN/UP. It's exposed as Control.KeyPress event in winforms.

like image 37
CodesInChaos Avatar answered Oct 14 '22 09:10

CodesInChaos