macos - Flutter RawKeyboardListener triggering system sounds on MacOS
问题描述
I have a MacOS desktop application built with flutter. In it I have a RawKeyboardListener widget. it is functioning as expected. It is capturing keyboard input which I could process as normal.
However whenever I press a key the OS level key input rejection sound plays. That sound that comes up when you press a key in a place where the key specifically won't work.
I haven't encountered this otherwise when using the listener so I'm not even sure where to begin.
解决方案
如果您想避免按键发出哔哔声,您应该使用FocusNode
's onKey
, 来实际处理事件(即返回 true),而不仅仅是监听事件的存在(如 in RawKeyboardListener
)
FocusNode.onKey
使用小部件完成时,使用 最容易处理密钥Focus
:
Widget build(BuildContext context) {
return Focus(
onKey: (FocusNode node, RawKeyEvent event) => true,
child: ...
);
}
这将为您管理焦点节点(根据需要插入和删除它)。
推荐阅读
- ruby-on-rails - 如何在一页上呈现两次条纹元素形式
- typescript - TypeScript 共享项目
- python - 为什么我的 pygame 窗口冻结并崩溃?
- angular - NG8002:无法绑定到“ngModel”,因为它不是“输入”的已知属性。角 10
- python - 如何使用 Python 在 Lambda 中为 CloudFront 生成 SignedUrls?
- javascript - 在 JavaScript 中重写 Element 接口的构造函数
- javascript - 如何在 Leaflet 弹出窗口中添加链接?
- spring - 接收由 HTTP.POST 发布的对象
- python - TypeError,使用 Sci-Kit Learn Regression 进行机器学习
- react-native - 如何在本机反应中设置数组并从键中获取值