onKeyLongPress不适用于KeyboardKey

时间:2015-06-28 19:59:50

标签: android android-softkeyboard onkeydown onkeyup android-input-method

如何在KeyboardKey上捕获onKeyLongPress。下面的代码只有在我输入“KEYCODE_VOLUME_DOWN”或“KEYCODE_VOLUME_UP”而不是“KEYCODE_Q”时才有效。如果您需要XML,请询问。我试着写“113”而不是“KeyEvent.KEYCODE_Q”,但我没有帮忙。

value = {'time':['9599','MS'],'What is your birth place?':['USA']}

import json

value = (json.dumps(value),)
print value
>> ('{"What is your birth place?": ["USA"], "time": ["9599", "MS"]}', )

1 个答案:

答案 0 :(得分:0)

我长按空格键的解决方案。

private long ms_press;
...
@Override
public void onPress( int i ){
    ms_press = System.currentTimeMillis();
}
...
@Override
public void onKey( int primaryCode, int[] keyCodes) {
    if( primaryCode == 32 && (System.currentTimeMillis()-ms_press) >= 1000  ){ 
        //long press on Space key
    }else{
        //...
    }
}