如何检测硬件按键? [英] How to detect hardware key taps?
问题描述
我正要检测当flutter应用程序处于前台或打开状态时是否按下了任何硬件按钮.*
I am at a point where I need to detect if any of the hardware buttons was presses when the flutter app is in foreground or when it is open.*
例如,当有人按下某个音量或另一个按钮(即使是关闭电源的按钮)时,我想在我的应用中执行一些操作.
For example, when someone presses a volume or another button (even if it is the power off one) I want to perform some action in my app.
我知道当一个flutter应用程序打开并且正在查看应用程序日志时,我点击了任何硬件按钮,则与该水龙头相关的活字印在了日志中.
I know that when a flutter app is open and I am looking at the app logs and I tap any hardware button is tapped the lops related to that tap is printed in the logs.
就像我按下音量下调"键时一样,检测到的相关日志会打印在日志中.
Like when I press Vol down Key Down Tap Detected related logs are printed in logs.
执行以上任何指定的操作时如何执行功能?
How do can I perform a function when any of the above specified action is performed?
推荐答案
名为硬件按钮的新插件原为几天前发布了.
New plugin called Hardware Buttons was released just a few days ago.
它支持音量按钮事件和电源按钮事件,这似乎很适合您的需求.
It supports volume button events and power button events, which seems like fits your need.
也许可以试试吗?
这篇关于如何检测硬件按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!