打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
3. KeyEvent
用来记录键和按钮事件的对象。

Object used to report key and button events.

每一次按键的点击都会由按键事件的序列所描述。按键点击以事件ACTION_DOWN作为开始。如果一个按键按得时间足够长那么就记做重复,然后按键事件就会带有ACTION_DOWN和一个非零的getRepeatCount()方法。最后一个点击事件是ACTION_UP。如果按键取消,那么按键抬起事件将会有一个 FLAG_CANCELED标签。

Each key press is described by a sequence of key events. A key press starts with a key event with ACTION_DOWN. If the key is held sufficiently long that it repeats, then the initial down is followed additional key events withACTION_DOWN and a non-zero value for getRepeatCount(). The last key event is a ACTION_UP for the key up. If the key press is canceled, the key up event will have the FLAG_CANCELED flag set.

按键事件通常伴随着key code,scan code和meta state。key code的常量定义在本类中。scan code常量根据设备而定,是从系统中获得,一般对应用没有意义除非使用KeyCharacterMap解释他们。Meta states描述了一些修饰按键按下的状态,比如MTEA_SHIFT_ON或者META_ALT_ON。

Key events are generally accompanied by a key code (getKeyCode()), scan code (getScanCode()) and meta state (getMetaState()). Key code constants are defined in this class. Scan code constants are raw device-specific codes obtained from the OS and so are not generally meaningful to applications unless interpreted using the KeyCharacterMap. Meta states describe the pressed state of key modifiers such as META_SHIFT_ON or META_ALT_ON.

Key code通常与输入设备上的按键是一对一的关系。在不同的设备上,不同的按键以及按键组合有着完全不同的功能,所以当解释它们的时候需要特别注意。经常使用KeyCharacterMap来将按键与对应的字符相关联。注意,有可能有多个按键设备同时存在,每个设备都有自己的按键字符映射关系。

Key codes typically correspond one-to-one with individual keys on an input device. Many keys and key combinations serve quite different functions on different input devices so care must be taken when interpreting them. Always use the KeyCharacterMap associated with the input device when mapping keys to characters. Be aware that there may be multiple key input devices active at the same time and each will have its own key character map.

一个虚拟键盘可以通过各种不同的方式输入文本,所以无法保证点击任何一个按钮会触发一个key event,你不应该依赖任何从虚拟键盘获得的点击事件。

As soft input methods can use multiple and inventive ways of inputting text, there is no guarantee that any key press on a soft keyboard will generate a key event: this is left to the IME's discretion, and in fact sending such events is discouraged. You should never rely on receiving KeyEvents for any key on a soft input method. In particular, the default software keyboard will never send any key event to any application targetting Jelly Bean or later, and will only send events for some presses of the delete and return keys to applications targetting Ice Cream Sandwich or earlier. Be aware that other software input methods may never send key events regardless of the version. Consider using editor actions like IME_ACTION_DONE if you need specific interaction with the software keyboard, as it gives more visibility to the user as to how your application will react to key presses.

当与虚拟键盘交互时,系统会传递一些特别的事件。

When interacting with an IME, the framework may deliver key events with the special action ACTION_MULTIPLE that either specifies that single repeated key code or a sequence of characters to insert.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
keyCode in key events
在 Android 通过 get
android音量键底层上层
英飞凌OKT507如何捕获按键事件
Trail: Sound
ASP.NET: Selectively Enable Form Validation When Using ASP.NET Web Controls -- MSDN Magazine, April
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服