android - onKeyDown mFlags variable
I have a log that came back from onKeyDown event and the flag resulted in the number 520. How do I find out what the flag is? I assume its 520 = 512 + 8 = FLAG_TRACKING + FLAG_FROM_SYSTEM
I need to know for sure and I hear it has something to do with hex开发者_JAVA百科 code. How to I convert and find out?
FROM LOG:
onKeyUp - keycode: 118 | info: KeyEvent{action=ACTION_UP code=118 repeat=0 meta=0 scancode=766 mFlags=520}
I need to know what the mFlags names are.
Thank you.
Here is the full code:
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | isCanceled: " + event.isCanceled() + " | info: " + event.toString());
if ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == KeyEvent.FLAG_FROM_SYSTEM)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_FROM_SYSTEM");
}else {}
if ((event.getFlags() & KeyEvent.FLAG_TRACKING) == KeyEvent.FLAG_TRACKING)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_TRACKING");
}else {}
///FLAG_WOKE_HERE
if ((event.getFlags() & KeyEvent.FLAG_WOKE_HERE) == KeyEvent.FLAG_WOKE_HERE)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_WOKE_HERE");
}else {}
//FLAG_SOFT_KEYBOARD
if ((event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_SOFT_KEYBOARD");
}else {}
//FLAG_KEEP_TOUCH_MODE
if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) == KeyEvent.FLAG_KEEP_TOUCH_MODE)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_KEEP_TOUCH_MODE");
}else {}
//FLAG_EDITOR_ACTION
if ((event.getFlags() & KeyEvent.FLAG_EDITOR_ACTION) == KeyEvent.FLAG_EDITOR_ACTION)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_EDITOR_ACTION");
}else {}
//FLAG_CANCELED
if ((event.getFlags() & KeyEvent.FLAG_CANCELED) == KeyEvent.FLAG_CANCELED)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_CANCELED");
}else {}
//FLAG_VIRTUAL_HARD_KEY
if ((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == KeyEvent.FLAG_VIRTUAL_HARD_KEY)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_VIRTUAL_HARD_KEY");
}else {}
//FLAG_LONG_PRESS
if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) == KeyEvent.FLAG_LONG_PRESS)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_LONG_PRESS");
}else {}
//FLAG_CANCELED_LONG_PRESS
if ((event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == KeyEvent.FLAG_CANCELED_LONG_PRESS)
{
Log.i("==BCR==", "onKeyDown - keycode: " + keyCode + " | FLAG: FLAG_CANCELED_LONG_PRESS");
}else {}
You can do this to check
if (mFlags & FLAG_TRACKING == FLAG_TRACKING)
// it contains FLAG_TRACKING
if (mFlags & FLAG_FROM_SYSTEM == FLAG_FROM_SYSTEM)
// its contains FLAG_FROM_SYSTEM flag.
if ... etc...
Why don't you simply print the constant values when a key down event occurs.
http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_NUMPAD_DOT
精彩评论