Bali C
Bali C

Reputation: 31231

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

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.

Upvotes: 6

Views: 2151

Answers (3)

CodesInChaos
CodesInChaos

Reputation: 108810

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.

Upvotes: 2

Heinzi
Heinzi

Reputation: 172320

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.

Upvotes: 3

Steve Wellens
Steve Wellens

Reputation: 20640

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.

Upvotes: 8

Related Questions