mac-catalyst - 检测没有修饰符的按键
问题描述
我想在我的 Catalyst 应用程序中捕获按键。
UIKeyCommand(input: "", modifierFlags: nil, action: #selector(singleShift))
不幸的是,modifierFlags 不能为 nil,并且 Catalyst 不支持 NSEvent。有没有办法检测单键?例如键盘应用程序或游戏?
解决方案
该字段modifierFlags
不是可选的,因此您不能通过nil
. 它的类型UIKeyModifierFlags
是 an OptionSet
,所以如果你不想传递修饰符,你可以简单地传递一个空数组。
class ViewController: UIViewController {
override var keyCommands: [UIKeyCommand]? {
[UIKeyCommand(input: UIKeyCommand.inputPageUp,
modifierFlags: [],
action: #selector(pageUpPressed(_:)))]
}
}
推荐阅读
- python - SQLAlchemy:链接数据库中两个已经存在的对象
- apk - 如何使用 adb 在不通知的情况下运行应用程序
- excel - 是否有 VBA 代码在包含特定数字的列中查找单元格?
- linux - Xenomai 汞 3.1 vxworks 皮肤,运行应用程序时“线程序言失败”
- python - 将函数应用于特定的 numpy 数组
- css - 使用 ThemeProvider 时避免冲突
- python - 输入任何 IP 地址后,我的 portScanner 程序失败
- mysql - 注册方法在我的控制器类中抛出空指针异常
- android - Ionic & Angular - iOS 上的 Ion 日期时间设计
- amazon-web-services - HttpClient C# PutAsync 到 S3 存储桶与提供的签名不匹配