Reputation:
I'm working ona code editor based on Windows Presentation Foundation(WPF). I wanna automatically add close bracket when the user add an open brakcet. But in System.Windows.Input.Key
, I can't find a keycode for brackets. I also need a few more character codes mentioned below in the code section.
// 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>";
}
}
I need the names of these characters in System.Windows.Input.Key
enum.
Upvotes: 0
Views: 1617
Reputation: 128061
The System.Windows.Input.Key
enum has no values for these characters.
You may however handle the PreviewTextInput
event instead of KeyDown
:
private void htmlcode_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
switch (e.Text)
{
case "{":
// add "}"
break;
// etc
}
}
Upvotes: 0