Java Code Examples for java.awt.event.KeyEvent#VK_KP_UP

The following examples show how to use java.awt.event.KeyEvent#VK_KP_UP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** @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;
}
 
Example 2
Source File: GameKeyHandler.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void keyReleased(final KeyEvent e) {
	final int keyCode = e.getKeyCode();

	/* Ignore if the key is not found in the pressedStateKeys list. */
	if (client.keyIsPressed(keyCode)) {
		/* Remove keyCode from pressedStateKeys list. */
		client.onKeyReleased(keyCode);

		switch (keyCode) {
		case KeyEvent.VK_LEFT:
		case KeyEvent.VK_RIGHT:
		case KeyEvent.VK_UP:
		case KeyEvent.VK_DOWN:
		case KeyEvent.VK_KP_LEFT:
		case KeyEvent.VK_KP_RIGHT:
		case KeyEvent.VK_KP_UP:
		case KeyEvent.VK_KP_DOWN:
			/*
			 * Ctrl means face, otherwise move
			 */
			processDirectionRelease(keyCodeToDirection(e.getKeyCode()),
					e.isControlDown());
		}
	}
}
 
Example 3
Source File: GameKeyHandler.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert a keycode to the corresponding direction.
 *
 * @param keyCode The keycode.
 *
 * @return The direction, or <code>null</code>.
 */
private Direction keyCodeToDirection(final int keyCode) {
	switch (keyCode) {
	case KeyEvent.VK_LEFT:
	case KeyEvent.VK_KP_LEFT:
		return Direction.LEFT;
	case KeyEvent.VK_RIGHT:
	case KeyEvent.VK_KP_RIGHT:
		return Direction.RIGHT;
	case KeyEvent.VK_KP_UP:
	case KeyEvent.VK_UP:
		return Direction.UP;
	case KeyEvent.VK_KP_DOWN:
	case KeyEvent.VK_DOWN:
		return Direction.DOWN;

	default:
		return null;
	}
}
 
Example 4
Source File: ConstructionWizard.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the new x and y location and facing of the site
 * @param c
 */
public void processKeyRelease(int c) {

    if (c == KeyEvent.VK_UP // 38
	    	|| c == KeyEvent.VK_KP_UP
	    	|| c == KeyEvent.VK_W
	    	|| c == KeyEvent.VK_NUMPAD8) {
	    	upKeyPressed = false;
	    } else if(c == KeyEvent.VK_DOWN // 40
	    	|| c == KeyEvent.VK_KP_DOWN
	    	|| c == KeyEvent.VK_S
	    	|| c == KeyEvent.VK_NUMPAD2) {
	    	downKeyPressed = false;
	    } else if(c == KeyEvent.VK_LEFT // 37
	    	|| c == KeyEvent.VK_KP_LEFT
	    	|| c == KeyEvent.VK_A
	    	|| c == KeyEvent.VK_NUMPAD4) {
	    	leftKeyPressed = false;
	    } else if(c == KeyEvent.VK_RIGHT // 39
	    	|| c == KeyEvent.VK_KP_RIGHT
	    	|| c == KeyEvent.VK_D
	    	|| c == KeyEvent.VK_NUMPAD6) {
	    	rightKeyPressed = false;
	    } else if(c == KeyEvent.VK_R
	    	|| c == KeyEvent.VK_F) {
	    	turnKeyPressed = false;
	    }

}
 
Example 5
Source File: WalletListPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public final void selectAdjacentWallet(KeyEvent e, String keyStatus) {
    int keyCode = e.getKeyCode();
    int modifiersEx = e.getModifiersEx();

    boolean moveToNextWallet = ((keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_KP_DOWN) && modifiersEx == KeyEvent.SHIFT_DOWN_MASK);
    boolean moveToPreviousWallet = ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_KP_UP) && modifiersEx == KeyEvent.SHIFT_DOWN_MASK);

    if (walletPanels != null) {
        synchronized (walletPanels) {
            int currentlySelectedWalletIndex = 0;
            int nextSelectedWalletIndex = -1;
            for (IAddressForm loopSingleWalletPanel : walletPanels) {

                // Found the currently selected panel.
                if (moveToNextWallet && currentlySelectedWalletIndex < walletPanels.size() - 1) {
                    nextSelectedWalletIndex = currentlySelectedWalletIndex + 1;
                    break;

                } else {
                    if (moveToPreviousWallet && currentlySelectedWalletIndex > 0) {
                        nextSelectedWalletIndex = currentlySelectedWalletIndex - 1;
                        break;
                    }
                }


                currentlySelectedWalletIndex++;
            }
            if (nextSelectedWalletIndex > -1) {
                Bither.getCoreController().fireDataChangedUpdateNow();
            }
        }
    }
}
 
Example 6
Source File: SelectCommand.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent event) {
  int code = event.getKeyCode();
  boolean setFromHistory = false;
  if (sqlHistory != null && !sqlHistory.isEmpty()) {
    if (historyIndex == -1) {
      historyIndex = sqlHistory.size() + 1;
    }
    if (code == KeyEvent.VK_KP_UP ||
        code == KeyEvent.VK_UP) {
      if (historyIndex > 0) {
        historyIndex -= 1;
      }
      setFromHistory = true;
    }
    else if (code == KeyEvent.VK_KP_DOWN ||
        code == KeyEvent.VK_DOWN) {
      if (historyIndex < sqlHistory.size() - 1) {
        historyIndex += 1;
        setFromHistory = true;
      }
    }
    if (setFromHistory) {
      sqlField.setText(sqlHistory.get(historyIndex));
      sqlField.invalidate();
    }
  }
}
 
Example 7
Source File: WalletListPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public final void selectAdjacentWallet(KeyEvent e, String keyStatus) {
    int keyCode = e.getKeyCode();
    int modifiersEx = e.getModifiersEx();

    boolean moveToNextWallet = ((keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_KP_DOWN) && modifiersEx == KeyEvent.SHIFT_DOWN_MASK);
    boolean moveToPreviousWallet = ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_KP_UP) && modifiersEx == KeyEvent.SHIFT_DOWN_MASK);

    if (walletPanels != null) {
        synchronized (walletPanels) {
            int currentlySelectedWalletIndex = 0;
            int nextSelectedWalletIndex = -1;
            for (IAddressForm loopSingleWalletPanel : walletPanels) {

                // Found the currently selected panel.
                if (moveToNextWallet && currentlySelectedWalletIndex < walletPanels.size() - 1) {
                    nextSelectedWalletIndex = currentlySelectedWalletIndex + 1;
                    break;

                } else {
                    if (moveToPreviousWallet && currentlySelectedWalletIndex > 0) {
                        nextSelectedWalletIndex = currentlySelectedWalletIndex - 1;
                        break;
                    }
                }


                currentlySelectedWalletIndex++;
            }
            if (nextSelectedWalletIndex > -1) {
                Bither.getCoreController().fireDataChangedUpdateNow();
            }
        }
    }
}
 
Example 8
Source File: ConstructionWizard.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sets the new x and y location and facing of the site
 * @param s
 * @param c
 */
public void processKeyPress(ConstructionSite s, int c) {
	int facing = (int) s.getFacing();
	double x = s.getXLocation();
	double y = s.getYLocation();

    if (c == KeyEvent.VK_UP // 38
    	|| c == KeyEvent.VK_KP_UP
    	|| c == KeyEvent.VK_W
    	|| c == KeyEvent.VK_NUMPAD8) {
    	upKeyPressed = true;
    } else if(c == KeyEvent.VK_DOWN // 40
    	|| c == KeyEvent.VK_KP_DOWN
    	|| c == KeyEvent.VK_S
    	|| c == KeyEvent.VK_NUMPAD2) {
    	downKeyPressed = true;
    } else if(c == KeyEvent.VK_LEFT // 37
    	|| c == KeyEvent.VK_KP_LEFT
    	|| c == KeyEvent.VK_A
    	|| c == KeyEvent.VK_NUMPAD4) {
    	leftKeyPressed = true;
    } else if(c == KeyEvent.VK_RIGHT // 39
    	|| c == KeyEvent.VK_KP_RIGHT
    	|| c == KeyEvent.VK_D
    	|| c == KeyEvent.VK_NUMPAD6) {
    	rightKeyPressed = true;
    } else if(c == KeyEvent.VK_R
    	|| c == KeyEvent.VK_F) {
    	turnKeyPressed = true;
    }
    	
   	double w0 = s.getWidth();
	double l0 = s.getLength();
	double f0 = s.getFacing();
	
	BoundedObject b0 = null;
	
    if (upKeyPressed) {
    	b0 = new BoundedObject(s.getXLocation(), s.getYLocation() + 3, w0, l0, f0);
    	if (!isCollided(b0))
    		s.setYLocation(y + 1);	
    }
    
    if (downKeyPressed) {
    	b0 = new BoundedObject(s.getXLocation(), s.getYLocation() - 3, w0, l0, f0);
    	if (!isCollided(b0)) 
    		s.setYLocation(y - 1);
    }
    
    if (leftKeyPressed) {
    	b0 = new BoundedObject(s.getXLocation() + 3, s.getYLocation(), w0, l0, f0);
    	if (!isCollided(b0)) 
    		s.setXLocation(x + 1);
    }
    
    if (rightKeyPressed) {
    	b0 = new BoundedObject(s.getXLocation() - 3, s.getYLocation(), w0, l0, f0);
    	if (!isCollided(b0)) 
    		s.setXLocation(x - 1);
    }
    
   	if (turnKeyPressed) {
    	facing = facing + 45;
    	if (facing >= 360)
    		facing = facing - 360;
    	b0 = new BoundedObject(s.getXLocation(), s.getYLocation(), w0, l0, facing);
   		if (!isCollided(b0)) {    	
	    	s.setFacing(facing);
   		}
    }
    
}
 
Example 9
Source File: GameKeyHandler.java    From stendhal with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent e) {
	final int keyCode = e.getKeyCode();
	final boolean doublePress = isDoublePress(keyCode);

	/* Ignore if the key is already pressed down. */
	if (!client.keyIsPressed(keyCode)) {
		/* Add keyCode to pressedStateKeys list. */
		client.onKeyPressed(keyCode);

		if (e.isShiftDown()) {
			/*
			 * We are going to use shift to move to previous/next line of text
			 * with arrows so we just ignore the keys if shift is pressed.
			 */
			return;
		}

		switch (keyCode) {
		case KeyEvent.VK_R:
			if (e.isControlDown()) {
				/*
				 * Ctrl+R Remove text bubbles
				 */
				screen.clearTexts();
			}
			break;

		case KeyEvent.VK_LEFT:
		case KeyEvent.VK_RIGHT:
		case KeyEvent.VK_UP:
		case KeyEvent.VK_DOWN:
		case KeyEvent.VK_KP_LEFT:
		case KeyEvent.VK_KP_RIGHT:
		case KeyEvent.VK_KP_UP:
		case KeyEvent.VK_KP_DOWN:
			/*
			 * Ctrl means face, otherwise move. Alt turns on auto-walk.
			 */
			final Direction direction = keyCodeToDirection(e.getKeyCode());

			/* Check if the player is currently using auto-walk or the Alt
			 * key is pressed.
			 */
			User user = User.get();
			if ((user.getRPObject().has(AUTOWALK) ||
					("true".equals(WtWindowManager.getInstance().getProperty(DOUBLE_TAP_AUTOWALK_PROPERTY, "false"))
					&& doublePress))) {
				/* Face direction pressed and toggle auto-walk. */
				this.processAutoWalk(direction, user);
			} else {
				if (e.isAltGraphDown()) {
					if (System.currentTimeMillis() - lastAction > 1000) {
						final EntityView<?> view = screen.getEntityViewAt(
								user.getX()
										+ direction.getdx(), user.getY()
										+ direction.getdy());

						if (view != null) {
							final IEntity entity = view.getEntity();
							if (!entity.equals(user)) {
								view.onAction();
								lastAction = System.currentTimeMillis();
							}
						}
					}
				}

				this.processDirectionPress(direction, e.isControlDown());
			}
			break;
		case KeyEvent.VK_0:
		case KeyEvent.VK_1:
		case KeyEvent.VK_2:
		case KeyEvent.VK_3:
		case KeyEvent.VK_4:
		case KeyEvent.VK_5:
		case KeyEvent.VK_6:
		case KeyEvent.VK_7:
		case KeyEvent.VK_8:
		case KeyEvent.VK_9:
			switchToSpellCastingState(e);
			break;
		}
	}
}
 
Example 10
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("Duplicates")
protected synchronized void doHandleKeyPress(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key pressed: " + e.paramString());

    // Get code of the pressed key.
    // Keypad arrows are translated to regular arrow keys.
    final int keyCode;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_KP_DOWN:
            keyCode = KeyEvent.VK_DOWN;
            break;
        case KeyEvent.VK_KP_LEFT:
            keyCode = KeyEvent.VK_LEFT;
            break;
        case KeyEvent.VK_KP_RIGHT:
            keyCode = KeyEvent.VK_RIGHT;
            break;
        case KeyEvent.VK_KP_UP:
            keyCode = KeyEvent.VK_UP;
            break;
        default:
            keyCode = e.getKeyCode();
            break;
    }

    // Never press undefined key codes.
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return;
    }

    // Never send caps lock, num lock and scroll lock key.
    if (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || keyCode == KeyEvent.VK_SCROLL_LOCK) {
        return;
    }

    // Detect, if a control key was pressed.
    final boolean isControlKey = e.isActionKey() ||
            keyCode == KeyEvent.VK_BACK_SPACE ||
            keyCode == KeyEvent.VK_DELETE ||
            keyCode == KeyEvent.VK_ENTER ||
            keyCode == KeyEvent.VK_SPACE ||
            keyCode == KeyEvent.VK_TAB ||
            keyCode == KeyEvent.VK_ESCAPE ||
            keyCode == KeyEvent.VK_ALT ||
            keyCode == KeyEvent.VK_ALT_GRAPH ||
            keyCode == KeyEvent.VK_CONTROL ||
            keyCode == KeyEvent.VK_SHIFT ||
            keyCode == KeyEvent.VK_META;

    // Press control keys.
    if (isControlKey) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        e.consume();
    }

    // Press other keys, if they are pressed together with a modifier key.
    else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown())) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        if (!pressedKeys.contains(keyCode))
            pressedKeys.add(keyCode);
        e.consume();
    }

    // Remember, that the Windows key was pressed.
    if (keyCode == KeyEvent.VK_WINDOWS) {
        synchronized (Frame.this) {
            windowsKeyDown = true;
        }
    }
}
 
Example 11
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("Duplicates")
protected synchronized void doHandleKeyRelease(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key released: " + e.paramString());

    // Get code of the released key.
    // Keypad arrows are translated to regular arrow keys.
    final int keyCode;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_KP_DOWN:
            keyCode = KeyEvent.VK_DOWN;
            break;
        case KeyEvent.VK_KP_LEFT:
            keyCode = KeyEvent.VK_LEFT;
            break;
        case KeyEvent.VK_KP_RIGHT:
            keyCode = KeyEvent.VK_RIGHT;
            break;
        case KeyEvent.VK_KP_UP:
            keyCode = KeyEvent.VK_UP;
            break;
        default:
            keyCode = e.getKeyCode();
            break;
    }

    // Never press undefined key codes.
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return;
    }

    // Never send caps lock, num lock and scroll lock key.
    if (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || keyCode == KeyEvent.VK_SCROLL_LOCK) {
        return;
    }

    // Detect, if a control key was pressed.
    final boolean isControlKey = e.isActionKey() ||
            keyCode == KeyEvent.VK_BACK_SPACE ||
            keyCode == KeyEvent.VK_DELETE ||
            keyCode == KeyEvent.VK_ENTER ||
            keyCode == KeyEvent.VK_SPACE ||
            keyCode == KeyEvent.VK_TAB ||
            keyCode == KeyEvent.VK_ESCAPE ||
            keyCode == KeyEvent.VK_ALT ||
            keyCode == KeyEvent.VK_ALT_GRAPH ||
            keyCode == KeyEvent.VK_CONTROL ||
            keyCode == KeyEvent.VK_SHIFT ||
            keyCode == KeyEvent.VK_META;

    // Release control keys.
    if (isControlKey) {
        //LOGGER.debug("release key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyRelease(keyCode);
        e.consume();
    }

    // Release other keys, if they are pressed together with a modifier key.
    else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown()) || pressedKeys.contains(keyCode)) {
        //LOGGER.debug("release key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyRelease(keyCode);
        pressedKeys.remove((Integer) keyCode);
        e.consume();
    }

    // Forget, that the Windows key is pressed.
    if (keyCode == KeyEvent.VK_WINDOWS) {
        synchronized (Frame.this) {
            windowsKeyDown = false;
        }
    }
}
 
Example 12
Source File: GlobalEvents.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
private static void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();
    switch (keyCode) {
        case KeyEvent.VK_SPACE:
            // Alt-space is not treated as space-down because on Windows
            // this opens the system menu, and we get the space-pressed
            // event, but not the space released-event, and the app gets
            // stuck in Hand mode, which looks like a freeze when there
            // are no scrollbars. See issue #29
            if (numNestedDialogs == 0 && !e.isAltDown()) {
                keyListener.spacePressed();
                spaceDown = true;
                e.consume();
            }

            break;
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_KP_RIGHT:
            if (numNestedDialogs == 0 && keyListener.arrowKeyPressed(ArrowKey.right(e.isShiftDown()))) {
                e.consume();
            }
            break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_KP_LEFT:
            if (numNestedDialogs == 0 && keyListener.arrowKeyPressed(ArrowKey.left(e.isShiftDown()))) {
                e.consume();
            }
            break;
        case KeyEvent.VK_UP:
        case KeyEvent.VK_KP_UP:
            if (numNestedDialogs == 0 && keyListener.arrowKeyPressed(ArrowKey.up(e.isShiftDown()))) {
                e.consume();
            }
            break;
        case KeyEvent.VK_DOWN:
        case KeyEvent.VK_KP_DOWN:
            if (numNestedDialogs == 0 && keyListener.arrowKeyPressed(ArrowKey.down(e.isShiftDown()))) {
                e.consume();
            }
            break;
        case KeyEvent.VK_ESCAPE:
            if (numNestedDialogs == 0) {
                keyListener.escPressed();
            }
            break;
        case KeyEvent.VK_ALT:
            if (numNestedDialogs == 0) {
                keyListener.altPressed();
            }
            break;
        default:
            keyListener.otherKeyPressed(e);
    }
}
 
Example 13
Source File: Spectrum.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
private int key(KeyEvent e) {
    int c = e.getKeyCode();
    int a = e.getKeyChar();
    int i = "[AQ10P\n ZSW29OL]XDE38IKMCFR47UJNVGT56YHB".indexOf((char) c);
    if (i >= 0) {
        simple:
        {
            int s = 0;
            if (c >= KeyEvent.VK_0 && c <= KeyEvent.VK_9) {
                if (c != (int) a) {
                    break simple;
                }
                if (e.isAltDown()) {
                    s = 0100;
                }
            }
            return i | s;
        }
    }
    if (a != '\0') {
        i = "\t\0\0!_\"\0\0:\0\0@);=\0\0\0\0#(\0+.?\0<$'\0-,/\0>%&\0^*".indexOf(a);
        if (i >= 0) {
            return i | 0200;
        }
    }
    switch (c) {
        case KeyEvent.VK_INSERT:
        case KeyEvent.VK_ESCAPE:
            return 0103;
        case KeyEvent.VK_KP_LEFT:
        case KeyEvent.VK_LEFT:
            i = 0;
            break;
        case KeyEvent.VK_KP_DOWN:
        case KeyEvent.VK_DOWN:
            i = 3;
            break;
        case KeyEvent.VK_KP_UP:
        case KeyEvent.VK_UP:
            i = 2;
            break;
        case KeyEvent.VK_KP_RIGHT:
        case KeyEvent.VK_RIGHT:
            i = 1;
            break;
        case KeyEvent.VK_BACK_SPACE:
            return 0104;
        case KeyEvent.VK_SHIFT:
            return 01000;
        case KeyEvent.VK_CONTROL:
            kempston |= 0x10; /* fall */

        case KeyEvent.VK_ALT:
            return 02000;
        default:
            return -1;
    }
    kempston |= 1 << (i ^ 1);
    return e.isAltDown() ? arrowsDefault[i] : arrows[i];
}