C# KeyCode for { and } [closed]

半腔热情 提交于 2019-12-11 19:43:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!