没有 EditText 的软键盘检测按键

发布于 2024-10-04 03:44:29 字数 661 浏览 7 评论 0原文

如何使用硬键盘或软键盘可靠地检测按键?

我的应用程序通过 WiFi 远程控制另一台设备,我需要检测软键盘或硬键盘上的每个按键。我实际上并不需要 EditText,因为我只需要在按下字符时一次发送一个字符,不需要最终的文本字符串。

我尝试过将 EditText 与 OnKeyPress 一起使用,但遇到了问题此处 无法使用软键盘按下按键。并且 TextWatcher 不是一个好的选择因为我需要每次按键。

如果必须的话,我会使用 EditText,但我宁愿不这样做。我真正想要的是:

  • 当用户点击“搜索”按钮时调出软键盘
  • 用户按下按键,然后我将代码传输到远程设备。实际上不需要在 EditText 中看到屏幕上的任何内容,因为它将显示在远程设备上
  • 用户按软键盘上的自定义“完成”按钮将其关闭

有什么建议吗?

How can I detect key presses reliably with a hard or soft keyboard?

My app remotely controls another device over wifi, and I need to detect every key press on either a soft or hard keyboard. I don't really need an EditText because I just need to send the characters one at a time as they are pressed and don't need the final text string.

I have tried using an EditText with OnKeyPress, but ran into the problems here with not getting key presses with soft keyboards. And TextWatcher isn't a good option because I need each key press.

I'll use an EditText if I have to, but would prefer not to. What I really want is to:

  • Bring up a soft keyboard when the user hits a Search button
  • User presses keys and I transmit the codes to remote device. Don't really need to see anything on screen in an EditText since it will be shown on the remote device
  • User presses the custom Done button on the soft keyboard to close it

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2024-10-11 03:44:29

那么您可以覆盖 [onKeyDown(int keyCode, KeyEvent event)][1] 和(或)[onKeyUp(int keyCode, KeyEvent event)][2]
应用程序活动类中的方法,这将允许您获得有关后退键和其他硬件键等键的通知...

注意:您可以获得有关轨迹球移动等的通知...

[1]: http://developer.android.com/reference/android/view/View .html#onKeyDown(int, android.view.KeyEvent)
[2]: http://developer.android.com/reference /android/view/View.html#onKeyUp(int, android.view.KeyEvent)

Well you could override the [onKeyDown(int keyCode, KeyEvent event)][1] and(or) [onKeyUp(int keyCode, KeyEvent event)][2]
methods in the applications activity class, this would allow you to get notification even about such keys as the back key and other hardware keys...

Note: you can get notification about trackball movement and so on...

[1]: http://developer.android.com/reference/android/view/View.html#onKeyDown(int, android.view.KeyEvent)
[2]: http://developer.android.com/reference/android/view/View.html#onKeyUp(int, android.view.KeyEvent)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文