Demand: Press the Enter key to trigger the event.
When I searched MSDN, the keyboard events I saw were in System.Windows.Forms, which was not useful in WPF:
https://msdn.microsoft.com/zh-tw/library/system.windows.forms.control.keydown (v = vs.110) .aspx
The usage of keyboard events in WPF is as follows:
- Register the keyboard down event KeyDown = "LoginWindow_KeyDown" in the interface XAML that needs to monitor keyboard events.
- The background code handles the response to different keyboards:
private void LoginWindow_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Message.Show("按下回车键");
}
}
It should be noted that the parameter is System.Windows.Input.KeyEventArgs, not System.Windows.Forms.KeyEventArgs!