There is no api can detect keyup event in the .net maui. So you can use the platform native api to do that.
- For the Windows
Put the following code in the ContenPage.cs:
protected override void OnHandlerChanged() { base.OnHandlerChanged();#if WINDOWS var winview = this.Handler.PlatformView as Microsoft.Maui.Platform.ContentPanel; winview.PreviewKeyUp += (s, e) => { if(e.Key == Windows.System.VirtualKey.Enter) { (((BindingContext as TargetViewModel).EnterCommand) as RelayCommand).Execute(null); //excute the command } };#endif }
- For the MacCatalyst
Put the following code in the \Platforms\MacCatalyst\AppDelegate.cs
public override void PressesBegan(NSSet<UIPress> presses, UIPressesEvent evt) { if(App.Current.MainPage == TargetPage) { foreach (UIPress p in presses) { var key = p.Key; if (key.Characters == "\r") { ((((App.Current.MainPage as TargetPage).BindingContext as TargetViewModel).EnterCommand) as RelayCommand).Execute(null); } } } base.PressesBegan(presses, evt); }