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

The following examples show how to use java.awt.event.KeyEvent#VK_1 . 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: CalculadoraTela.java    From dctb-utfpr-2018-1 with Apache License 2.0 6 votes vote down vote up
public void operarComTeclaDigitada(java.awt.event.KeyEvent evt) {
    // Se foi digitado uma das teclas a seguir
    if ((evt.getKeyCode() == KeyEvent.VK_0)
            || (evt.getKeyCode() == KeyEvent.VK_1)
            || (evt.getKeyCode() == KeyEvent.VK_2)
            || (evt.getKeyCode() == KeyEvent.VK_3)
            || (evt.getKeyCode() == KeyEvent.VK_4)
            || (evt.getKeyCode() == KeyEvent.VK_5)
            || (evt.getKeyCode() == KeyEvent.VK_6)
            || (evt.getKeyCode() == KeyEvent.VK_7)
            || (evt.getKeyCode() == KeyEvent.VK_8)
            || (evt.getKeyCode() == KeyEvent.VK_9)
            || (evt.getKeyCode() == KeyEvent.VK_ADD)
            || (evt.getKeyCode() == KeyEvent.VK_SUBTRACT)
            || (evt.getKeyCode() == KeyEvent.VK_DIVIDE)
            || (evt.getKeyCode() == KeyEvent.VK_MULTIPLY)
            || (evt.getKeyCode() == KeyEvent.VK_EQUALS)) {

        this.operarConformeEstado("" + evt.getKeyChar());

    } else if (evt.getKeyCode() == KeyEvent.VK_L) {
        this.operarConformeEstado("Limpar");
    }
}
 
Example 2
Source File: InsertRecordDialog.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void processKeyEvents(KeyEvent e) {
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);

    if (KeyStroke.getKeyStrokeForEvent(e).equals(copy)) {
        copy();
    } else if (KeyStroke.getKeyStrokeForEvent(e).equals(paste)) {
        paste();
    }
    if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_DELETE) {
        insertRecordTableUI.removeRows();
    } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        setFocusable(false);
    } else if (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_0) {
        control0Event();
        e.consume();
    } else if (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_1) {
        control1Event();
        e.consume();
    } else if (KeyStroke.getKeyStrokeForEvent(e).equals(tab)) {
    }
}
 
Example 3
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the mnemonic.
 *
 * @param i the i
 * @return the mnemonic
 */
private static final int getMnemonic(int i) {
  switch (i) {
  case 1:
    return KeyEvent.VK_1;
  case 2:
    return KeyEvent.VK_2;
  case 3:
    return KeyEvent.VK_3;
  case 4:
    return KeyEvent.VK_4;
  case 5:
    return KeyEvent.VK_5;
  case 6:
    return KeyEvent.VK_6;
  case 7:
    return KeyEvent.VK_7;
  case 8:
    return KeyEvent.VK_8;
  case 9:
    return KeyEvent.VK_9;
  default:
    return KeyEvent.VK_0;
  }
}
 
Example 4
Source File: KeyRemappingConfig.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@ConfigItem(
	position = 7,
	keyName = "f1",
	name = "F1",
	description = "The key which will replace {F1}."
)
default ModifierlessKeybind f1()
{
	return new ModifierlessKeybind(KeyEvent.VK_1, 0);
}
 
Example 5
Source File: QueryBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void handleKeyPress(KeyEvent e) {
    if( e.isAltDown() ) {
        int code = e.getKeyCode();
        switch(code) {
            // diagram pane
            case KeyEvent.VK_1:
                if ( DEBUG )
                    System.out.println(" Alt + 1 pressed. "); // NOI18N
  // ToDo: Decide whether this needs to be duplicated in the GraphLib version
  // _queryBuilderPane.getQueryBuilderGraphFrame().getFocus ();
                getGraphFrameCanvasFocus();
                break;
                // grid pane
            case KeyEvent.VK_2:
                if ( DEBUG )
                    System.out.println(" Alt + 2 pressed. "); // NOI18N
                if ( _queryBuilderPane.getQueryBuilderInputTable().getRowCount() > 0 ) {
                    _queryBuilderPane.getQueryBuilderInputTable().setRowSelectionInterval(0, 0);
                    _queryBuilderPane.getQueryBuilderInputTable().requestFocus( true );
                }
                break;
                // SQL text pane
            case KeyEvent.VK_3:
                if ( DEBUG )
                    System.out.println(" Alt + 3 pressed. "); // NOI18N
                _queryBuilderPane.getQueryBuilderSqlTextArea().requestFocus( true );
                break;
                // Result Pane
            case KeyEvent.VK_4:
                if ( DEBUG )
                    System.out.println(" Alt + 4 pressed. "); // NOI18N
                _queryBuilderPane.getQueryBuilderResultTable().requestFocus( true );
                break;
        }
    }
}
 
Example 6
Source File: JMenuItemRecentFile.java    From portecle with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the menu item's position in its recent file list (maintained by JMenuRecentFiles).
 *
 * @param iPosition Position
 */
void setPosition(int iPosition)
{
	m_iPosition = iPosition;
	setText(m_iPosition + " " + m_fRecentFile.getName());

	switch (m_iPosition)
	{
		case 1:
			super.setMnemonic(KeyEvent.VK_1);
			break;
		case 2:
			super.setMnemonic(KeyEvent.VK_2);
			break;
		case 3:
			super.setMnemonic(KeyEvent.VK_3);
			break;
		case 4:
			super.setMnemonic(KeyEvent.VK_4);
			break;
		case 5:
			super.setMnemonic(KeyEvent.VK_5);
			break;
		case 6:
			super.setMnemonic(KeyEvent.VK_6);
			break;
		case 7:
			super.setMnemonic(KeyEvent.VK_7);
			break;
		case 8:
			super.setMnemonic(KeyEvent.VK_8);
			break;
		case 9:
			super.setMnemonic(KeyEvent.VK_9);
			break;
	}
}
 
Example 7
Source File: KeyRemappingConfig.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@ConfigItem(
	position = 7,
	keyName = "f1",
	name = "F1",
	description = "The key which will replace {F1}.",
	section = fKeySection
)
default ModifierlessKeybind f1()
{
	return new ModifierlessKeybind(KeyEvent.VK_1, 0);
}
 
Example 8
Source File: SmoothMoves.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Toggles various rendering flags
 */
public void keyPressed(KeyEvent ke) {
    int keyCode = ke.getKeyCode();
    if (keyCode == KeyEvent.VK_B) {
        // B: Motion blur - displays trail of ghost images
        motionBlur = !motionBlur;
    } else if (keyCode == KeyEvent.VK_A) {
        // A: Antialiasing - Displays soft edges around graphics
        useAA = !useAA;
        createAnimationImage();
    } else if (keyCode == KeyEvent.VK_C) {
        // C: Color - Toggles rectangle color between dark and light colors
        alterColor = !alterColor;
        createAnimationImage();
    } else if (keyCode == KeyEvent.VK_I) {
        // I: Image - Toggles use of image or filled rectangle to show how 
        // straight edges affect animation perception
        useImage = !useImage;
        createAnimationImage();
    } else if (keyCode == KeyEvent.VK_UP) {
        // Up Arrow: Speed - Speeds up frame rate
        changeResolution(true);
    } else if (keyCode == KeyEvent.VK_DOWN) {
        // Down Arrow: Speed - Slows down frame rate
        changeResolution(false);
    } else if (keyCode == KeyEvent.VK_L) {
        // L: Linearity: Toggles linear/nonlinear motion
        linear = !linear;
    } else if (keyCode >= KeyEvent.VK_1 && keyCode <= KeyEvent.VK_9) {
        // 0-9: Blur size: Toggles size of ghost trail for motion blur
        blurSize = keyCode - KeyEvent.VK_0;
        prevMoveX = prevMoveY = null;
    }
}
 
Example 9
Source File: PlayerZoneButtonsPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public static int[] getKeyBindings(MagicPlayerZone aZone) {
    switch (aZone) {
        case HAND: return new int[]{KeyEvent.VK_1, KeyEvent.VK_Z, KeyEvent.VK_NUMPAD1};
        case GRAVEYARD: return new int[]{KeyEvent.VK_2, KeyEvent.VK_X, KeyEvent.VK_NUMPAD2};
        case EXILE: return new int[]{KeyEvent.VK_3, KeyEvent.VK_C, KeyEvent.VK_NUMPAD3};
        default: return new int[]{};
    }
}
 
Example 10
Source File: Utils.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Returns null if no plugin was launched.
 *  To launch a plugin, it needs a Utils.getControlModifier + 1,2,3,4... up to 9.
 *  @param active may be null. */
static final public Bureaucrat launchTPlugIn(final KeyEvent ke, final String menu, final Project project, final Displayable active) {
	try {
		if (0 == (ke.getModifiers() ^ Utils.getControlModifier())) {
			final TreeMap<String,TPlugIn> plugins = project.getPlugins("Display");
			if (plugins.size() > 0) {
				final int index = ke.getKeyCode() - KeyEvent.VK_1;
				if (index < plugins.size()) {
					int count = 0;
					for (final Map.Entry<String,TPlugIn> e : plugins.entrySet()) {
						if (index != count) {
							count++;
							continue;
						}
						return Bureaucrat.createAndStart(new Worker.Task(e.getKey()) {
							@Override
							public void exec() {
								e.getValue().invoke(active);
							}
						}, project);
					}
				}
			}
		}
	} catch (final Throwable t) {
		IJError.print(t);
	}
	return null;
}
 
Example 11
Source File: CreateWorkDialog.java    From workcraft with MIT License 4 votes vote down vote up
private int getKeyCode(int index) {
    if (index < 9) return KeyEvent.VK_1 + index;
    if (index == 9) return KeyEvent.VK_0;
    return KeyEvent.VK_A + index - 10;
}
 
Example 12
Source File: Robot.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 将字符型转换为按键码,可直接使用 {@link #press(int)}调用
 * @param key 字符型文字,包含 0~9 a~z .
 * @return 按键码
 */
public int StringToKey(String key){
	switch (key) {
	case "a":
		return KeyEvent.VK_A;
	case "b":
		return KeyEvent.VK_B;
	case "c":
		return KeyEvent.VK_C;
	case "d":
		return KeyEvent.VK_D;
	case "e":
		return KeyEvent.VK_E;
	case "f":
		return KeyEvent.VK_F;
	case "g":
		return KeyEvent.VK_G;
	case "h":
		return KeyEvent.VK_H;
	case "i":
		return KeyEvent.VK_I;
	case "j":
		return KeyEvent.VK_J;
	case "k":
		return KeyEvent.VK_K;
	case "l":
		return KeyEvent.VK_L;
	case "m":
		return KeyEvent.VK_M;
	case "n":
		return KeyEvent.VK_N;
	case "o":
		return KeyEvent.VK_O;
	case "p":
		return KeyEvent.VK_P;
	case "q":
		return KeyEvent.VK_Q;
	case "r":
		return KeyEvent.VK_R;
	case "s":
		return KeyEvent.VK_S;
	case "t":
		return KeyEvent.VK_T;
	case "u":
		return KeyEvent.VK_U;
	case "v":
		return KeyEvent.VK_V;
	case "w":
		return KeyEvent.VK_W;
	case "x":
		return KeyEvent.VK_X;
	case "y":
		return KeyEvent.VK_Y;
	case "z":
		return KeyEvent.VK_Z;
	case "0":
		return KeyEvent.VK_0;
	case "1":
		return KeyEvent.VK_1;
	case "2":
		return KeyEvent.VK_2;
	case "3":
		return KeyEvent.VK_3;
	case "4":
		return KeyEvent.VK_4;
	case "5":
		return KeyEvent.VK_5;
	case "6":
		return KeyEvent.VK_6;
	case "7":
		return KeyEvent.VK_7;
	case "8":
		return KeyEvent.VK_8;
	case "9":
		return KeyEvent.VK_9;
	case ".":
		return KeyEvent.VK_PERIOD;
	default:
		break;
	}
	
	return 0;
}
 
Example 13
Source File: KeyCodeToChar.java    From Repeat with Apache License 2.0 4 votes vote down vote up
private static String getNonAlphaCharWithoutShift(int code) {
	switch (code) {
	case KeyEvent.VK_BACK_QUOTE:
		return "`";
	case KeyEvent.VK_1:
		return "1";
	case KeyEvent.VK_2:
		return "2";
	case KeyEvent.VK_3:
		return "3";
	case KeyEvent.VK_4:
		return "4";
	case KeyEvent.VK_5:
		return "5";
	case KeyEvent.VK_6:
		return "6";
	case KeyEvent.VK_7:
		return "7";
	case KeyEvent.VK_8:
		return "8";
	case KeyEvent.VK_9:
		return "9";
	case KeyEvent.VK_0:
		return "0";
	case KeyEvent.VK_MINUS:
		return "-";
	case KeyEvent.VK_EQUALS:
		return "=";
	case KeyEvent.VK_OPEN_BRACKET:
		return "[";
	case KeyEvent.VK_CLOSE_BRACKET:
		return "]";
	case KeyEvent.VK_SEMICOLON:
		return ";";
	case KeyEvent.VK_QUOTE:
		return "'";
	case KeyEvent.VK_BACK_SLASH:
		return "\\";
	case KeyEvent.VK_COMMA:
		return ",";
	case KeyEvent.VK_PERIOD:
		return ".";
	case KeyEvent.VK_SLASH:
		return "/";
	case KeyEvent.VK_TAB:
		return "\t";
	case KeyEvent.VK_ENTER:
		return "\n";
	case KeyEvent.VK_SPACE:
		return " ";
	default:
		return "";
	}
}
 
Example 14
Source File: KeyCodeToChar.java    From Repeat with Apache License 2.0 4 votes vote down vote up
private static String getNonAlphaCharWithShift(int code) {
	switch (code) {
	case KeyEvent.VK_BACK_QUOTE:
		return "~";
	case KeyEvent.VK_1:
		return "!";
	case KeyEvent.VK_2:
		return "@";
	case KeyEvent.VK_3:
		return "#";
	case KeyEvent.VK_4:
		return "$";
	case KeyEvent.VK_5:
		return "%";
	case KeyEvent.VK_6:
		return "^";
	case KeyEvent.VK_7:
		return "&";
	case KeyEvent.VK_8:
		return "*";
	case KeyEvent.VK_9:
		return "(";
	case KeyEvent.VK_0:
		return ")";
	case KeyEvent.VK_MINUS:
		return "_";
	case KeyEvent.VK_EQUALS:
		return "+";
	case KeyEvent.VK_OPEN_BRACKET:
		return "{";
	case KeyEvent.VK_CLOSE_BRACKET:
		return "}";
	case KeyEvent.VK_SEMICOLON:
		return ":";
	case KeyEvent.VK_QUOTE:
		return "\"";
	case KeyEvent.VK_BACK_SLASH:
		return "|";
	case KeyEvent.VK_COMMA:
		return "<";
	case KeyEvent.VK_PERIOD:
		return ">";
	case KeyEvent.VK_SLASH:
		return "?";
	case KeyEvent.VK_TAB:
		return "\t";
	case KeyEvent.VK_ENTER:
		return "\n";
	case KeyEvent.VK_SPACE:
		return " ";
	default:
		return "";
	}
}
 
Example 15
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 16
Source File: ProjectTree.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent ke) {
	super.keyPressed(ke);
	if (ke.isConsumed()) return;
	if (!ke.getSource().equals(ProjectTree.this) || !project.isInputEnabled()) {
		return;
	}
	// get the first selected node only
	TreePath path = getSelectionPath();
	if (null == path) return;
	DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
	if (null == node) return;
	final ProjectThing pt = (ProjectThing)node.getUserObject();
	if (null == pt) return;
	//
	final int flags = ke.getModifiers();
	switch (ke.getKeyCode()) {
		case KeyEvent.VK_PAGE_UP:
			move(node, -1);
			ke.consume(); // in any case
			break;
		case KeyEvent.VK_PAGE_DOWN:
			move(node, 1);
			ke.consume(); // in any case
			break;
		case KeyEvent.VK_F2:
			rename(pt);
			ke.consume();
			break;
		case KeyEvent.VK_H:
			if (0 == (flags ^ Event.ALT_MASK)) {
				pt.setVisible(true);
				ke.consume();
			} else if (0 == flags) {
				pt.setVisible(false);
				ke.consume();
			}
			break;
		case KeyEvent.VK_A:
			if (0 == flags || (0 == (flags ^ Event.SHIFT_MASK))) {
				selectInDisplay(pt, 0 == (flags ^ Event.SHIFT_MASK));
				ke.consume();
			}
			break;
		case KeyEvent.VK_3:
			if (0 == flags) {
				ini.trakem2.display.Display3D.showAndResetView(pt);
				ke.consume();
				break;
			}
			// else, flow:
		case KeyEvent.VK_1:
		case KeyEvent.VK_2:
		case KeyEvent.VK_4:
		case KeyEvent.VK_5:
		case KeyEvent.VK_6:
		case KeyEvent.VK_7:
		case KeyEvent.VK_8:
		case KeyEvent.VK_9:
			// run a plugin, if any
			if (pt.getObject() instanceof Displayable && null != Utils.launchTPlugIn(ke, "Project Tree", project, (Displayable)pt.getObject())) {
				ke.consume();
			}
			break;
	}
	ke.consume();
}