Mac catalyst 检测不带修改器的按键

Mac catalyst 检测不带修改器的按键,mac-catalyst,uikeycommand,Mac Catalyst,Uikeycommand,我想在我的Catalyst应用程序中捕获按键 UIKeyCommand(input: "", modifierFlags: nil, action: #selector(singleShift)) 不幸的是,modifierFlags不能为零,并且Catalyst上不支持NSEvent。有没有办法检测单个按键?e、 g.对于键盘应用程序或游戏?字段modifierFlags不是可选的,因此您不能通过nil。它属于UIKeyModifierFlags类型,是一个OptionSet,因此如果不想传

我想在我的Catalyst应用程序中捕获按键

UIKeyCommand(input: "", modifierFlags: nil, action: #selector(singleShift))

不幸的是,modifierFlags不能为零,并且Catalyst上不支持NSEvent。有没有办法检测单个按键?e、 g.对于键盘应用程序或游戏?

字段
modifierFlags
不是可选的,因此您不能通过
nil
。它属于
UIKeyModifierFlags
类型,是一个
OptionSet
,因此如果不想传递修饰符,只需传递一个空数组即可

类ViewController:UIViewController{
覆盖var keyCommands:[UIKeyCommand]{
[UIKeyCommand(输入:UIKeyCommand.inputPageUp,
modifierFlags:[],
操作:#选择器(页面已升级(#:))]
}
}
查看的结果,了解创建不带修改器的UIKeyCommand的几个示例。