问题描述
像电源按钮和音量减小键的组合 - 采用手机的截图......同样,我试图访问音量和电源按钮长$ P $在我的应用程序pssed键,给一个快捷方式。这可能吗?
Like the combination of Power button and Volume down button - takes a screenshot of the phone... similarly I am trying to access volume up and power button long pressed keys in my app and give a shortcut. Is this possible?
我知道如何让两个按钮分别,但不能合并在同一时间的访问。
I know how to get the access of both buttons individually but not combined at the same time.
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_POWER){
Log.w("LongPress", "power LONG PRESS");
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
Log.w("LongPress", "Volume Up LONG PRESS");
}
return super.onKeyLongPress(keyCode, event);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
event.startTracking();
return true;
}
return super.onKeyDown(keyCode, event);
}
如何获得组合在这里做'和;&功放;不工作?
How to get the combination done here '&&' doesn't work?
推荐答案
我不明白,在机器人编程,但我看到它使用的Java类,那么试试这个
I don't understand programming under android, but I see it uses Java classes, so try this
public class BitKeys implements KeyListener {
private BitSet keyBits = new BitSet(256);
@Override
public void keyPressed(final KeyEvent event) {
int keyCode = event.getKeyCode();
keyBits.set(keyCode);
}
@Override
public void keyReleased(final KeyEvent event) {
int keyCode = event.getKeyCode();
keyBits.clear(keyCode);
}
@Override
public void keyTyped(final KeyEvent event) {
// don't care
}
public boolean isKeyPressed(final int keyCode) {
return keyBits.get(keyCode);
}
}
我发现这个在这里:<一href="http://stackoverflow.com/questions/11851155/handle-multiple-key-$p$psses-ignoring-repeated-key">handle多键presses忽略重复键
I found this here :handle multiple key presses ignoring repeated key
这篇关于电源按钮,在Android的音量按钮组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!