这些字符的键码是什么? - WPF
What is the keycode of these characters? - WPF
我正在开发一个基于 Windows Presentation Foundation (WPF) 的代码编辑器。我想在用户添加开括号时自动添加右括号。但是在 System.Windows.Input.Key
中,我找不到括号的键码。我还需要下面代码部分提到的几个字符代码。
// Brackets, square brackets and curly brackets "(" ")" "[" "]" "{" "}"
// Lower/Greater: "<" ">"
// Equal, quote and single quote " ' =
private void htmlcode_KeyDown(object sender, KeyEventArgs e)
{
if(e.Key = /* the keycode that I need */)
{
htmlcode.Text = htmlcode.Text + "<close variant of key>";
}
}
我需要 System.Windows.Input.Key
枚举中这些字符的名称。
System.Windows.Input.Key
枚举没有这些字符的值。
但是您可以处理 PreviewTextInput
事件而不是 KeyDown
:
private void htmlcode_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
switch (e.Text)
{
case "{":
// add "}"
break;
// etc
}
}
我正在开发一个基于 Windows Presentation Foundation (WPF) 的代码编辑器。我想在用户添加开括号时自动添加右括号。但是在 System.Windows.Input.Key
中,我找不到括号的键码。我还需要下面代码部分提到的几个字符代码。
// Brackets, square brackets and curly brackets "(" ")" "[" "]" "{" "}"
// Lower/Greater: "<" ">"
// Equal, quote and single quote " ' =
private void htmlcode_KeyDown(object sender, KeyEventArgs e)
{
if(e.Key = /* the keycode that I need */)
{
htmlcode.Text = htmlcode.Text + "<close variant of key>";
}
}
我需要 System.Windows.Input.Key
枚举中这些字符的名称。
System.Windows.Input.Key
枚举没有这些字符的值。
但是您可以处理 PreviewTextInput
事件而不是 KeyDown
:
private void htmlcode_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
switch (e.Text)
{
case "{":
// add "}"
break;
// etc
}
}