问题描述:

Does Java support multi key press and how to implement that? This solution is not working at all:

if (key == KeyEvent.VK_LEFT) {

if(key==KeyEvent.VK_S){

dx = -3;

}

}

网友答案:

There is no such built-in feature so you will have to deal with it yourself. For example make a collection of the last KEY_PRESSED KeyEvents and check that for your combinations. When a key is released, i.e. KEY_RELEASED, you can remove it from the collection.

If you're looking for shift, ctrl, alt or alt gr there is a simpler solution - the KeyEvent has the methods isShiftDown(), isControlDown(), isAltDown() and isAltGraphDown() that tells you if these were down on the event.

相关阅读:
Top