我正在制作一个MAUI应用程序,我想在其中检测用户何时按下特定键。我创建了一个KeyDown事件,但KeyRoutedEventArgs不被识别,即使我有using System.Windows.Input;
public void KeyDown(object sender, KeyRoutedEventArgs e)
{
}
这是windows特有的代码。
#if WINDOWS
.. ..
#endif
在using和方法本身都需要。
或者将代码放在Windows文件夹中。https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/invoke-platform-code
注意:Maui还没有通用键盘支持跨平台:https://github.com/dotnet/maui/issues/3739.
跨平台,当Entry有焦点时,可以通过Entry的成员键入键。这允许在没有物理键盘的设备上出现屏幕上的键盘。