本文整理汇总了Java中java.awt.event.KeyEvent.getKeyCode方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getKeyCode方法的具体用法?Java KeyEvent.getKeyCode怎么用?Java KeyEvent.getKeyCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.getKeyCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override
public void keyPressed(KeyEvent ke) {
int key = ke.getKeyCode();
if (key == KeyEvent.VK_UP) {
// projectionModificationBegin();
bDragging = true;
dragAnim.animWithVelocity(0, DragAnim.MAX_VELOCITY*.7);
} else if (key == KeyEvent.VK_DOWN) {
// projectionModificationBegin();
bDragging = true;
dragAnim.animWithVelocity(0, -DragAnim.MAX_VELOCITY*.7);
} else if (key == KeyEvent.VK_LEFT) {
// projectionModificationBegin();
bDragging = true;
dragAnim.animWithVelocity(DragAnim.MAX_VELOCITY*.7,0);
} else if (key == KeyEvent.VK_RIGHT) {
// projectionModificationBegin();
dragAnim.animWithVelocity(-DragAnim.MAX_VELOCITY*.7,0);
}
}
示例2: processKeyEvent
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override
public void processKeyEvent(ExecutionUnit process, KeyEventType type, KeyEvent e) {
// ignore if not active
if (!isActive()) {
return;
}
if (type == KeyEventType.KEY_PRESSED) {
if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
SHOW_ORDER_TOGGLEBUTTON.doClick();
}
}
// no matter what, while flow visualizer is active we consume all events
e.consume();
}
示例3: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
* Notification from AWT that a key has been pressed. Note that
* a key being pressed is equal to being pushed down but *NOT*
* released. Thats where keyTyped() comes in.
*
* @param e
* The details of the key that was pressed
*/
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
// Jump
case KeyEvent.VK_W:
// climb e jump
case KeyEvent.VK_SPACE:
game.player.startClimb();
break;
// move left
case KeyEvent.VK_A:
game.player.startLeft(e.isShiftDown());
break;
// move right
case KeyEvent.VK_D:
game.player.startRight(e.isShiftDown());
break;
}
}
示例4: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void keyPressed(KeyEvent event) {
synchronized (lock) {
tempPress = true;
lock.notifyAll();
if (! startTest) {
return;
}
for (int x = 0; x < inputMasks.length; x++) {
if ((event.getModifiers() & inputMasks[x]) != 0) {
System.out.println("Modifier set: " +
event.getKeyModifiersText(inputMasks[x]));
modifierStatus[x] = true;
}
}
for (int x = 0; x < textKeys.length; x++) {
if (event.getKeyCode() == textKeys[x]) {
System.out.println("Text set: " +
event.getKeyText(textKeys[x]));
textStatus[x] = true;
}
}
}
}
示例5: postProcessKeyEvent
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public boolean postProcessKeyEvent(KeyEvent ev) {
if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) {
// mnemonic combination, it's consumed, but we need
// set altKeyPressed to false, otherwise after selection
// component by mnemonic combination a menu will be open
altKeyPressed = false;
return false;
}
if (ev.getKeyCode() == KeyEvent.VK_ALT) {
root = SwingUtilities.getRootPane(ev.getComponent());
winAncestor = (root == null ? null :
SwingUtilities.getWindowAncestor(root));
if (ev.getID() == KeyEvent.KEY_PRESSED) {
if (!altKeyPressed) {
altPressed(ev);
}
altKeyPressed = true;
return true;
} else if (ev.getID() == KeyEvent.KEY_RELEASED) {
if (altKeyPressed) {
altReleased(ev);
} else {
MenuSelectionManager msm =
MenuSelectionManager.defaultManager();
MenuElement[] path = msm.getSelectedPath();
if (path.length <= 0) {
WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
}
altKeyPressed = false;
}
root = null;
winAncestor = null;
} else {
altKeyPressed = false;
}
return false;
}
示例6: keyTyped
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override
public void keyTyped(KeyEvent ke) {
if(ke.getKeyCode() == KeyEvent.VK_LEFT ||
ke.getKeyCode() == KeyEvent.VK_RIGHT ||
ke.getKeyCode() == KeyEvent.VK_UP ||
ke.getKeyCode() == KeyEvent.VK_DOWN) {
return;
}
if(pane.getSelectedText() != null ||
ke.getKeyChar()== KeyEvent.VK_DELETE ||
ke.getKeyChar()== KeyEvent.VK_BACK_SPACE ||
(ke.isShiftDown() && ke.getKeyChar() == KeyEvent.VK_TAB)) {
try {
prevText = pane.getStyledDocument().getText(0, pane.getStyledDocument().getLength());
} catch (BadLocationException ex) {
Logger.getLogger(SaveTextBeforeRemove.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
示例7: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
KeyStroke keyStroke = createKeyStroke(e);
boolean add = e.getKeyCode() != e.VK_SHIFT &&
e.getKeyCode() != e.VK_CONTROL &&
e.getKeyCode() != e.VK_ALT &&
e.getKeyCode() != e.VK_META &&
e.getKeyCode() != e.VK_ALT_GRAPH;
if (keyStroke.equals(backspaceKS) && !key.equals("")) {
// delete last key
int i = key.lastIndexOf(' ');
if (i < 0)
key = "";
else
key = key.substring(0, i);
tfShortcut.setText(key);
} else
// add key
addKeyStroke(keyStroke, add);
e.consume();
}
示例8: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_F5) {
proj.getSimulator().requestReset();
proj.getSimulator().setIsRunning(true);
} else if ((e.getKeyCode() == KeyEvent.VK_0 || e.getKeyCode() == KeyEvent.VK_NUMPAD0)
&& e.isControlDown()) {
autoZoomCenter();
} else {
Tool tool = proj.getTool();
if (tool != null)
tool.keyPressed(Canvas.this, e);
}
}
示例9: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
TreePath[] paths = getSelectionPaths();
if ((paths != null) && (paths.length > 0)) {
Collection changedNodes = new ArrayList();
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
if ((path != null) && (path.getPathCount() > 0) && path.getLastPathComponent() instanceof CheckTreeNode
&& (((CheckTreeNode) path.getLastPathComponent()).isLeaf() || (i == (paths.length - 1)))) {
fireNodeToggled(path, true);
}
changedNodes.addAll(togglePathState(path));
fireNodeToggled(path, false);
}
treeDidChange();
fireCheckTreeChanged(changedNodes);
}
}
}
示例10: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override
public void keyPressed(KeyEvent event) {
enterFlag = false;
if ((event.getKeyCode() == KeyEvent.VK_ENTER)
&& (event.getModifiers() == 0)) {
if (getSelectionStart() == getSelectionEnd()) {
enterFlag = true;
event.consume();
}
}
}
示例11: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override
public void keyPressed(Canvas canvas, KeyEvent e) {
int code = e.getKeyCode();
if (mouseDown && (code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_CONTROL || code == KeyEvent.VK_ALT)) {
updateMouse(canvas, lastMouseX, lastMouseY, e.getModifiersEx());
repaintArea(canvas);
}
}
示例12: handleSpecialKey
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void handleSpecialKey(KeyEvent ke) {
if(ke.getKeyCode() == KeyEvent.VK_END) {
insertToCode.moveToEndOfCurrentLine();
} else if(ke.getKeyCode() == KeyEvent.VK_HOME) {
insertToCode.moveToStartOfCurrentLine();
}
}
示例13: letTextPaneHandleKey
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private boolean letTextPaneHandleKey(KeyEvent ke) {
return ke.getKeyCode() == KeyEvent.VK_LEFT ||
ke.getKeyCode() == KeyEvent.VK_RIGHT ||
ke.getKeyCode() == KeyEvent.VK_UP ||
ke.getKeyCode() == KeyEvent.VK_DOWN ||
ke.getKeyChar()== KeyEvent.VK_ESCAPE;
}
示例14: keyReleased
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void keyReleased(KeyEvent e)
{
int key = e.getKeyCode();
if(key == KeyEvent.VK_B && pressed)
{
pressed = false;
QuestionHandler.backCard();
}
}
示例15: keyPressed
import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
if ( e.getSource() instanceof JTree ) {
JTree tree = (JTree) e.getSource();
TreePath path = tree.getSelectionPath();
if ( toggle( path )) {
e.consume();
}
}
}
}