本文整理汇总了Java中java.awt.event.KeyEvent.VK_KP_LEFT属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.VK_KP_LEFT属性的具体用法?Java KeyEvent.VK_KP_LEFT怎么用?Java KeyEvent.VK_KP_LEFT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.VK_KP_LEFT属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKeyText
/** @return slight modification of what KeyEvent.getKeyText() returns.
* The numpad Left, Right, Down, Up get extra result.
*/
private static String getKeyText(int keyCode) {
String ret = KeyEvent.getKeyText(keyCode);
if (ret != null) {
switch (keyCode) {
case KeyEvent.VK_KP_DOWN:
ret = prefixNumpad(ret, KeyEvent.VK_DOWN);
break;
case KeyEvent.VK_KP_LEFT:
ret = prefixNumpad(ret, KeyEvent.VK_LEFT);
break;
case KeyEvent.VK_KP_RIGHT:
ret = prefixNumpad(ret, KeyEvent.VK_RIGHT);
break;
case KeyEvent.VK_KP_UP:
ret = prefixNumpad(ret, KeyEvent.VK_UP);
break;
}
}
return ret;
}
示例2: keyPressed
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
//System.out.println("human pressed " + key);
if (key == KeyEvent.VK_UP || key == KeyEvent.VK_KP_UP) {
// UP means accelerate forward
lastKeyPressed = HumanKeyPressed.UP;
//System.out.println("human pressed UP ");
} else if (key == KeyEvent.VK_DOWN || key == KeyEvent.VK_KP_DOWN) {
// DOWN means decelerate
lastKeyPressed = HumanKeyPressed.DOWN;
} else if (key == KeyEvent.VK_RIGHT || key == KeyEvent.VK_KP_RIGHT) {
// turn RIGHT
lastKeyPressed = HumanKeyPressed.RIGHT;
} else if (key == KeyEvent.VK_LEFT || key == KeyEvent.VK_KP_LEFT) {
// turn LEFT
lastKeyPressed = HumanKeyPressed.LEFT;
} else if (key == KeyEvent.VK_SPACE) {
// fire
lastKeyPressed = HumanKeyPressed.FIRE;
}
if (lastKeyPressed != null) {
lastMouseClick = null;
}
}
示例3: dispatchKeyEvent
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if(!Menu.menu.isVisible()){
if(e.getID() == KeyEvent.KEY_PRESSED){
int d = e.isShiftDown() ? 3 : e.isControlDown() ? 2 : 1;
switch(e.getKeyCode()){
case KeyEvent.VK_LEFT:
case KeyEvent.VK_KP_LEFT:
e.getComponent().getLocation(tmp);
e.getComponent().setLocation(tmp.x - d, tmp.y);
break;
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_KP_RIGHT:
e.getComponent().getLocation(tmp);
e.getComponent().setLocation(tmp.x + d, tmp.y);
break;
case KeyEvent.VK_UP:
case KeyEvent.VK_KP_UP:
e.getComponent().getLocation(tmp);
e.getComponent().setLocation(tmp.x, tmp.y - d);
break;
case KeyEvent.VK_DOWN:
case KeyEvent.VK_KP_DOWN:
e.getComponent().getLocation(tmp);
e.getComponent().setLocation(tmp.x, tmp.y + d);
break;
}
}
}
return false;
}
示例4: keyPressed
@Override
public void keyPressed(KeyEvent e) {
int ign = InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK;
if ((e.getModifiersEx() & ign) != 0)
return;
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
case KeyEvent.VK_KP_LEFT:
if (pos > 0)
--pos;
break;
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_KP_RIGHT:
if (pos < curText.length())
++pos;
break;
case KeyEvent.VK_HOME:
pos = 0;
break;
case KeyEvent.VK_END:
pos = curText.length();
break;
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_CANCEL:
cancelEditing();
break;
case KeyEvent.VK_CLEAR:
curText = "";
pos = 0;
break;
case KeyEvent.VK_ENTER:
stopEditing();
break;
case KeyEvent.VK_BACK_SPACE:
if (pos > 0) {
curText = curText.substring(0, pos - 1) + curText.substring(pos);
--pos;
field.setText(curText);
}
break;
case KeyEvent.VK_DELETE:
if (pos < curText.length()) {
curText = curText.substring(0, pos) + curText.substring(pos + 1);
field.setText(curText);
}
break;
case KeyEvent.VK_INSERT:
case KeyEvent.VK_COPY:
case KeyEvent.VK_CUT:
case KeyEvent.VK_PASTE:
// TODO: enhance label editing
break;
default:
; // ignore
}
}