Android 开发人员:从屏幕(软)键盘获取按键事件
我正在开发一个 Android 程序来分析用户的文本输入并测量打字速度、错误率、输入单个字符的平均按键次数。通过这样做,我可以比较不同输入法的特点。为此,我需要计算并记录用户在文本输入过程中按下的所有按键。
例如,使用基本 qwerty 键盘的用户必须为每个字母至少按下一个键。然而,使用具有单词完成功能的键盘的用户将需要按更少的键。但是(平均)按下了多少次按键?单词补全真的能提高打字速度吗?这些是我的程序将帮助回答的问题。
阅读其他帖子,我知道(默认情况下)屏幕键盘不会发送所有按键的按键事件。物理(硬件)键盘有,但大多数移动设备没有物理键盘。我还知道我可以实现 TextWatcher 来检测何时在 EditText 字段中键入字母。但是,某些 IME 可能要求用户按一系列按键来输入单个字母(或单词)。我需要处理中间按键事件(即,通过计数和记录按键次数)。
我的问题:如何在不修改 IME 的用户体验(例如,自动完成、单词预测、T9 消歧等)的情况下捕获 IME 中的每个按键事件(甚至不触发键入字符的事件)?这可能吗?
预先感谢您的宝贵时间。
I'm developing an Android program to analyze a user's text input and measure typing speed, error rate, average key presses to enter a single character. By doing so, I can compare characteristics of different input methods. To do this, I need to count and record all key presses made by the user during the text entry process.
For example, a user using a basic qwerty keyboard would have to press at least one key for each letter. However, a user using a keyboard with word completion would need to press fewer keys. But how many key presses are made (on average)? Does word completion actually improve typing speed? These are the questions my program will help answer.
Reading other posts, I know that (by default), onscreen keyboards don't send key events for all key presses. Physical (hardware) keyboards do, but most mobile devices don't have a physical keyboard. I also know that I can implement a TextWatcher to detect when a letter is typed in an EditText field. However, some IMEs might require the user to press a sequence of keys to enter a single letter (or word). I need to handle the intermediate key events (i.e., by counting and logging key presses).
My question: How would I capture every key press event from an IME (even events that don't trigger a typed character) without modifying the IME's user experience (e.g., auto completion, word prediction, T9 disambiguation, etc.)? Is this even possible?
Thanks in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试监听
TouchEvent
?您是否尝试使用 View 类中的
onKeyPreIme()
?有了这个,你可以在输入法消耗掉按键之前捕获它们did you try to listen for
TouchEvent
s?did you try to use
onKeyPreIme()
from View class? with this one you can catch key presses before they are consumed by the IME只能通过编写自己的 IME,据我所知,或者获取现有 IME 的源代码并对其进行检测。
Only by writing your own IME, AFAIK, or getting the source to an existing IME and instrumenting it.