Reputation: 35
In MAUI, using KeyUp I can capture all the key pressing, but not pressing Enter key. Here is the code:
window.Content.KeyUp += (s,e){
//do something
}
If I press the Enter key of keyboard, nothing will happen. If I press other keys, the KeyUp handler will be triggered.
What caused the issue? How can I fix this? Any suggestion?
Thanks!
Upvotes: 0
Views: 65
Reputation: 4332
You can try the following code, it can capture pressing Enter key.
public partial class NewPage1 : ContentPage
{
public NewPage1()
{
InitializeComponent();
}
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
#if WINDOWS
Microsoft.UI.Xaml.Window window = (Microsoft.UI.Xaml.Window)App.Current.Windows.First<Window>().Handler.PlatformView;
window.Content.KeyUp += Content_KeyUp;
#endif
}
#if WINDOWS
private void Content_KeyUp(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
var a = e.Key.ToString();
}
#endif
}
Here is the effect.
Upvotes: 0