问题
What is the C# key code for '{' and '}', so I can use it in a KeyDown event
if(e.KeyCode == Keys.CurlyBracket1)
{
//Do stuff
}
Sorry it's a bit vague but I don't know what else to put
回答1:
On a Standard U.S. keyboard layout, the keys for { and } are OemOpenBrackets (or Oem4) and OemCloseBrackets (or Oem6), respectively. However, since these glyphs share a key with the square brackets ([, ]), you would need to test for the presence of one of the shift modifiers.
I would not assume this would work on all non-"Standard U.S." keyboard configurations; it would be better to handle the KeyPress event and check the KeyChar property.
回答2:
Curley braces are not a Key on all keyboards, for example they require you to hold shift on a UK Qwerty keyboard therefore KeyDown will not work. You need to use the KeyPress event instead.
回答3:
Check if it is useful: http://www.w3.org/2002/09/tests/keys.html
Best regards
来源:https://stackoverflow.com/questions/19937122/c-sharp-keycode-for-and