سؤال

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

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

Check if it is useful: http://www.w3.org/2002/09/tests/keys.html

Best regards

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top