简体   繁体   English

检测是否在 Flutter 中连接了物理键盘

[英]Detect if a physical keyboard is connected in Flutter

Is there a way to detect if there is a PHYSICAL keyboard connected in Flutter?有没有办法检测Flutter中是否连接了物理键盘? I would like to detect if the user is using a physical keyboard, and alter the UI depending on if this is so.我想检测用户是否正在使用物理键盘,并根据是否是这样来更改 UI。

Has this changed?这改变了吗? I would also like to detect if a keyboard is connected/available.我还想检测键盘是否已连接/可用。 I'm currently reacting when a physical keyboard is used with a RawKeyboardListener but it would be a smoother experience for the end user if I could see if a keyboard was connected, before it's actually used.当物理键盘与 RawKeyboardListener 一起使用时,我目前正在做出反应,但如果我能在实际使用键盘之前查看键盘是否已连接,这对最终用户来说将是一种更流畅的体验。

Looks like this is available in Android native: https://developer.android.com/reference/android/content/res/Configuration.html#keyboard看起来这在 Android 本机中可用: https ://developer.android.com/reference/android/content/res/Configuration.html#keyboard

Not sure if it's available on iOS but we have the RawKeyboardListener approach that is OK on iOS.不确定它是否在 iOS 上可用,但我们有适用于 iOS 的 RawKeyboardListener 方法。 For Android we are supporting Chromebooks with physical keyboards and to provide the best experience we would like to react as early as possible to physical keyboards.对于 Android,我们支持配备物理键盘的 Chromebook,并且为了提供最佳体验,我们希望尽早对物理键盘作出反应。

If you want to know if the physical keyboard has been used (but not when it connects), you could listen to keyboard events by listening to RawKeyboard.instance.addListener , and switch modes if you see a key event: RawKeyboard only sends physical keyboard events.如果你想知道物理键盘是否被使用过(但连接时没有),你可以通过监听RawKeyboard.instance.addListener来监听键盘事件,如果你看到一个按键事件就切换模式: RawKeyboard only sends physical keyboard事件。

But to answer your question, no, there's no specific notification for when a physical keyboard is connected.但是要回答你的问题,不,没有关于何时连接物理键盘的具体通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM