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

The following examples show how to use java.awt.event.KeyEvent#VK_INSERT . 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: SqueakKeyboard.java    From trufflesqueak with MIT License 8 votes vote down vote up
private static int mapSpecialKeyCode(final KeyEvent e) {
    //@formatter:off
    switch(e.getExtendedKeyCode()) {
        case KeyEvent.VK_BACK_SPACE: return 8;
        case KeyEvent.VK_TAB: return 9;
        case KeyEvent.VK_ENTER: return 13;
        case KeyEvent.VK_ESCAPE: return 27;
        case KeyEvent.VK_SPACE: return 32;
        case KeyEvent.VK_PAGE_UP: return 11;
        case KeyEvent.VK_PAGE_DOWN: return 12;
        case KeyEvent.VK_END: return 4;
        case KeyEvent.VK_HOME: return 1;
        case KeyEvent.VK_LEFT: return 28;
        case KeyEvent.VK_UP: return 30;
        case KeyEvent.VK_RIGHT: return 29;
        case KeyEvent.VK_DOWN: return 31;
        case KeyEvent.VK_INSERT: return 5;
        case KeyEvent.VK_DELETE: return 127;
        default: return -1; // Not a special key.
    }
    //@formatter:on
}
 
Example 2
Source File: InterpANSI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void keyPressed(KeyEvent e) {

    switch (e.getKeyCode()) {
        //
        // 6 key editing group
        //
        case KeyEvent.VK_INSERT:
            sendChars(e, "\033[L");         // NOI18N
            break;
        case KeyEvent.VK_HOME:
            sendChars(e, "\033[H");         // NOI18N
            break;

        //
        // Arrow keys
        //
        case KeyEvent.VK_UP:
            sendChars(e, "\033[A");         // NOI18N
            break;
        case KeyEvent.VK_DOWN:
            sendChars(e, "\033[B");         // NOI18N
            break;
        case KeyEvent.VK_RIGHT:
            sendChars(e, "\033[C");         // NOI18N
            break;
        case KeyEvent.VK_LEFT:
            sendChars(e, "\033[D");         // NOI18N
            break;

    }
}
 
Example 3
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given event is corrent gesture for
 * accessing clipboard
 *
 * @param ie InputEvent to check
 */
@SuppressWarnings("deprecation")
private static boolean isAccessClipboardGesture(InputEvent ie) {
    boolean allowedGesture = false;
    if (ie instanceof KeyEvent) { //we can validate only keyboard gestures
        KeyEvent ke = (KeyEvent)ie;
        int keyCode = ke.getKeyCode();
        int keyModifiers = ke.getModifiers();
        switch(keyCode) {
        case KeyEvent.VK_C:
        case KeyEvent.VK_V:
        case KeyEvent.VK_X:
            allowedGesture = (keyModifiers == InputEvent.CTRL_MASK);
            break;
        case KeyEvent.VK_INSERT:
            allowedGesture = (keyModifiers == InputEvent.CTRL_MASK ||
                              keyModifiers == InputEvent.SHIFT_MASK);
            break;
        case KeyEvent.VK_COPY:
        case KeyEvent.VK_PASTE:
        case KeyEvent.VK_CUT:
            allowedGesture = true;
            break;
        case KeyEvent.VK_DELETE:
            allowedGesture = ( keyModifiers == InputEvent.SHIFT_MASK);
            break;
        }
    }
    return allowedGesture;
}
 
Example 4
Source File: TextEditor.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected void processKeyEvent(KeyEvent e) {
    super.processKeyEvent(e);

    //  Handle release of Insert key to toggle overtype/insert mode
    //  unless a modifier is active (eg Shift+Insert for paste or
    //  Ctrl+Insert for Copy)
    if (e.getID() == KeyEvent.KEY_RELEASED &&
            e.getKeyCode() == KeyEvent.VK_INSERT &&
            e.getModifiersEx() == 0) {
        setOvertypeMode(!isOvertypeMode());
    }
}
 
Example 5
Source File: GPTreeTableBase.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
private boolean isStartEditingEvent(KeyEvent e, boolean includeCharTyping) {
  boolean result = e.getKeyCode() == KeyEvent.VK_F2
      || e.getKeyCode() == KeyEvent.VK_INSERT
      || (myNewRowAction != null && KeyStroke.getKeyStrokeForEvent(e).equals(myNewRowAction.getKeyStroke()));
  if (!result && includeCharTyping) {
    result = e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && !e.isMetaDown() && !e.isControlDown();
  }
  return result;
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override protected void processKeyEvent(KeyEvent e) {
  super.processKeyEvent(e);
  // Handle release of Insert key to toggle overtype/insert mode
  if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_INSERT) {
    setCaretPosition(getCaretPosition()); // add
    moveCaretPosition(getCaretPosition()); // add
    setOvertypeMode(!isOvertypeMode());
    repaint(); // add
  }
}
 
Example 7
Source File: Editor.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
/**
     * Called whenever the user presses a key in the text area.
     *
     * @param event The key event.
     */
    public void keyPressed(KeyEvent event) {
        int keyCode = event.getKeyCode();
        switch (keyCode) {
            // If they're releasing the Insert key, toggle between
            // insert/overwrite mode for all editors OTHER THAN the one in
            // which the key was pressed (it is done for that one already).
            case KeyEvent.VK_INSERT : {
//                boolean isInsertMode = editorPanel.getTextMode() == PlainTextArea.INSERT_MODE;
                boolean isInsertMode = false;
                statusBar.setOverwriteModeIndicatorEnabled(isInsertMode);
                break;
            }
            // If they're releasing the Caps Lock key, toggle caps lock
            // in the status bar to reflect the actual state.
            case KeyEvent.VK_CAPS_LOCK : {
                try {
                    boolean state = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
                    statusBar.setCapsLockIndicatorEnabled(state);
                } catch (UnsupportedOperationException e) {
                	// ignore
                }
                break;
            }
            default:
        }
    }
 
Example 8
Source File: TextFieldCaret.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
@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
	}
}
 
Example 9
Source File: ActionUtils.java    From workcraft with MIT License 4 votes vote down vote up
public static String getKeyString(int keyCode) {
    // Letters and numbers
    if (((keyCode >= KeyEvent.VK_0) && (keyCode <= KeyEvent.VK_9))
            || ((keyCode >= KeyEvent.VK_A) && (keyCode <= KeyEvent.VK_Z))) {
        return String.valueOf((char) keyCode);
    }
    switch (keyCode) {
    // Navigation keys
    case KeyEvent.VK_LEFT: return "Left";
    case KeyEvent.VK_UP: return "Up";
    case KeyEvent.VK_RIGHT: return "Right";
    case KeyEvent.VK_DOWN: return "Down";
    // Extra navigation keys
    case KeyEvent.VK_INSERT: return "Insert";
    case KeyEvent.VK_DELETE: return "Delete";
    case KeyEvent.VK_END: return "End";
    case KeyEvent.VK_HOME: return "Home";
    case KeyEvent.VK_PAGE_UP: return "PgUp";
    case KeyEvent.VK_PAGE_DOWN: return "PgDn";
    // Function keys
    case KeyEvent.VK_F1: return "F1";
    case KeyEvent.VK_F2: return "F2";
    case KeyEvent.VK_F3: return "F3";
    case KeyEvent.VK_F4: return "F4";
    case KeyEvent.VK_F5: return "F5";
    case KeyEvent.VK_F6: return "F6";
    case KeyEvent.VK_F7: return "F7";
    case KeyEvent.VK_F8: return "F8";
    case KeyEvent.VK_F9: return "F9";
    case KeyEvent.VK_F10: return "F10";
    case KeyEvent.VK_F11: return "F11";
    case KeyEvent.VK_F12: return "F12";
    // Symbols
    case KeyEvent.VK_EXCLAMATION_MARK: return "!";
    case KeyEvent.VK_QUOTEDBL: return "\"";
    case KeyEvent.VK_EURO_SIGN: return "€";
    case KeyEvent.VK_DOLLAR: return "$";
    case KeyEvent.VK_CIRCUMFLEX: return "^";
    case KeyEvent.VK_AMPERSAND: return "&";
    case KeyEvent.VK_ASTERISK: return "*";
    case KeyEvent.VK_UNDERSCORE: return "_";
    case KeyEvent.VK_MINUS: return "-";
    case KeyEvent.VK_PLUS: return "+";
    case KeyEvent.VK_EQUALS: return "=";
    case KeyEvent.VK_AT: return "@";
    case KeyEvent.VK_NUMBER_SIGN: return "#";
    case KeyEvent.VK_COLON: return ":";
    case KeyEvent.VK_SEMICOLON: return ";";
    case KeyEvent.VK_COMMA: return ",";
    case KeyEvent.VK_PERIOD: return ".";
    case KeyEvent.VK_SLASH: return "/";
    case KeyEvent.VK_BACK_SLASH: return "\\";
    case KeyEvent.VK_DEAD_TILDE: return "~";
    // Parenthesis and brackets
    case KeyEvent.VK_LEFT_PARENTHESIS: return "(";
    case KeyEvent.VK_RIGHT_PARENTHESIS: return ")";
    case KeyEvent.VK_OPEN_BRACKET: return "[";
    case KeyEvent.VK_CLOSE_BRACKET: return "]";
    case KeyEvent.VK_BRACELEFT: return "{";
    case KeyEvent.VK_BRACERIGHT: return "}";
    case KeyEvent.VK_LESS: return "<";
    case KeyEvent.VK_GREATER: return ">";
    // Formatting keys
    case KeyEvent.VK_SPACE: return "Space";
    case KeyEvent.VK_TAB: return "Tab";
    case KeyEvent.VK_ENTER: return "Enter";
    case KeyEvent.VK_BACK_SPACE: return "Backspace";
    case KeyEvent.VK_ESCAPE: return "Esc";
    }
    return "0x" + Integer.toString(keyCode, 16);
}
 
Example 10
Source File: VncClientPacketSender.java    From cosmic with Apache License 2.0 4 votes vote down vote up
private int mapAwtKeyToVncKey(final int key) {
    switch (key) {
        case KeyEvent.VK_BACK_SPACE:
            return 0xff08;
        case KeyEvent.VK_TAB:
            return 0xff09;
        case KeyEvent.VK_ENTER:
            return 0xff0d;
        case KeyEvent.VK_ESCAPE:
            return 0xff1b;
        case KeyEvent.VK_INSERT:
            return 0xff63;
        case KeyEvent.VK_DELETE:
            return 0xffff;
        case KeyEvent.VK_HOME:
            return 0xff50;
        case KeyEvent.VK_END:
            return 0xff57;
        case KeyEvent.VK_PAGE_UP:
            return 0xff55;
        case KeyEvent.VK_PAGE_DOWN:
            return 0xff56;
        case KeyEvent.VK_LEFT:
            return 0xff51;
        case KeyEvent.VK_UP:
            return 0xff52;
        case KeyEvent.VK_RIGHT:
            return 0xff53;
        case KeyEvent.VK_DOWN:
            return 0xff54;
        case KeyEvent.VK_F1:
            return 0xffbe;
        case KeyEvent.VK_F2:
            return 0xffbf;
        case KeyEvent.VK_F3:
            return 0xffc0;
        case KeyEvent.VK_F4:
            return 0xffc1;
        case KeyEvent.VK_F5:
            return 0xffc2;
        case KeyEvent.VK_F6:
            return 0xffc3;
        case KeyEvent.VK_F7:
            return 0xffc4;
        case KeyEvent.VK_F8:
            return 0xffc5;
        case KeyEvent.VK_F9:
            return 0xffc6;
        case KeyEvent.VK_F10:
            return 0xffc7;
        case KeyEvent.VK_F11:
            return 0xffc8;
        case KeyEvent.VK_F12:
            return 0xffc9;
        case KeyEvent.VK_SHIFT:
            return 0xffe1;
        case KeyEvent.VK_CONTROL:
            return 0xffe3;
        case KeyEvent.VK_META:
            return 0xffe7;
        case KeyEvent.VK_ALT:
            return 0xffe9;
        case KeyEvent.VK_ALT_GRAPH:
            return 0xffea;
        case KeyEvent.VK_BACK_QUOTE:
            return 0x0060;
    }

    return key;
}
 
Example 11
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];
}
 
Example 12
Source File: VncClientPacketSender.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
private int mapAwtKeyToVncKey(int key) {
    switch (key) {
        case KeyEvent.VK_BACK_SPACE:
            return 0xff08;
        case KeyEvent.VK_TAB:
            return 0xff09;
        case KeyEvent.VK_ENTER:
            return 0xff0d;
        case KeyEvent.VK_ESCAPE:
            return 0xff1b;
        case KeyEvent.VK_INSERT:
            return 0xff63;
        case KeyEvent.VK_DELETE:
            return 0xffff;
        case KeyEvent.VK_HOME:
            return 0xff50;
        case KeyEvent.VK_END:
            return 0xff57;
        case KeyEvent.VK_PAGE_UP:
            return 0xff55;
        case KeyEvent.VK_PAGE_DOWN:
            return 0xff56;
        case KeyEvent.VK_LEFT:
            return 0xff51;
        case KeyEvent.VK_UP:
            return 0xff52;
        case KeyEvent.VK_RIGHT:
            return 0xff53;
        case KeyEvent.VK_DOWN:
            return 0xff54;
        case KeyEvent.VK_F1:
            return 0xffbe;
        case KeyEvent.VK_F2:
            return 0xffbf;
        case KeyEvent.VK_F3:
            return 0xffc0;
        case KeyEvent.VK_F4:
            return 0xffc1;
        case KeyEvent.VK_F5:
            return 0xffc2;
        case KeyEvent.VK_F6:
            return 0xffc3;
        case KeyEvent.VK_F7:
            return 0xffc4;
        case KeyEvent.VK_F8:
            return 0xffc5;
        case KeyEvent.VK_F9:
            return 0xffc6;
        case KeyEvent.VK_F10:
            return 0xffc7;
        case KeyEvent.VK_F11:
            return 0xffc8;
        case KeyEvent.VK_F12:
            return 0xffc9;
        case KeyEvent.VK_SHIFT:
            return 0xffe1;
        case KeyEvent.VK_CONTROL:
            return 0xffe3;
        case KeyEvent.VK_META:
            return 0xffe7;
        case KeyEvent.VK_ALT:
            return 0xffe9;
        case KeyEvent.VK_ALT_GRAPH:
            return 0xffea;
        case KeyEvent.VK_BACK_QUOTE:
            return 0x0060;
    }

    return key;
}