在Android的关键preSS事件 [英] keypress event in android

查看:211
本文介绍了在Android的关键preSS事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我preSS唯一的字符按钮a到z执行android的一些动作是什么关键ASCII code为A到Z能有人告诉如何在Android的呢?

when i press the only character button a to z to perform some action in android what is key ascii code for a to z can anybody tell how to do in android?

推荐答案

这里的关键是codeS的Andr​​oid上的整个列表。不要使用int类型。使用的KeyEvent的静态值。 http://developer.android.com/reference/android/view/KeyEvent.html

here is the whole list of keycodes on android. Don't use the int. Use the static value of KeyEvent. http://developer.android.com/reference/android/view/KeyEvent.html

在活动中您可以覆盖以下(或者,如果您想了解更多)之一

in the activity you can overwrite one of the following (or more if you like)

boolean onKeyDown(int keyCode, KeyEvent event)
boolean onKeyLongPress(int keyCode, KeyEvent event)
boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean onKeyUp(int keyCode, KeyEvent event)

和在那里,你可以这样做:

and in there you can just do:

if (event.getKeyCode() == KeyEvent.KEYCODE_A) {
    // do whatever you want.
}

而不是任何你想要KeyEvent.KEY code_A使用。例如KeyEvent.KEY code_BACK为返回键。

instead of KeyEvent.KEYCODE_A use whatever you want. For example KeyEvent.KEYCODE_BACK for the back key.

这篇关于在Android的关键preSS事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆