当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Multiple keyboard presses

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: