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

The following examples show how to use java.awt.event.KeyEvent#VK_BACK_SPACE . 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: Keys.java    From SikuliNG with MIT License 8 votes vote down vote up
public static boolean isRepeatable(String token) {
  int key = toJavaKeyCodeFromText(token);
  switch (key) {
    case KeyEvent.VK_UP:
      return true;
    case KeyEvent.VK_DOWN:
      return true;
    case KeyEvent.VK_RIGHT:
      return true;
    case KeyEvent.VK_LEFT:
      return true;
    case -KeyEvent.VK_TAB:
      return true;
    case KeyEvent.VK_TAB:
      return true;
    case KeyEvent.VK_ENTER:
      return true;
    case KeyEvent.VK_BACK_SPACE:
      return true;
  }
  return false;
}
 
Example 2
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 3
Source File: BasicTextField.java    From 3Dscript with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	if(e.getKeyCode() == KeyEvent.VK_ENTER) {
		editing = false;
		selectall = false;
		fireTextFieldChanged();
		e.getComponent().repaint();
	} else if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
		selectall = false;
		fireTextFieldChanged();
		e.getComponent().repaint();
	} else if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
		if(selectall)
			text = "";
		else
			if(text.length() > 0)
				text = text.substring(0, text.length() - 1);
		selectall = false;
		fireTextFieldChanged();
		e.getComponent().repaint();
	}
}
 
Example 4
Source File: AbstractSpotModule.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public void keyPressed(KeyEvent e) {
    int keyNum = -1;
    try {
        keyNum = Integer.parseInt(e.getKeyChar() + "") + getClassNumOffset(); // number pressed? (if so, substract -1 because we count from 0)
    } catch (Exception ignored) {
    }
    if (keyNum >= 0) {
        setClass(keyNum, e);
    } else {
        // del pressed? -> remove selected items
        if (e.getKeyCode() == KeyEvent.VK_DELETE) {
            removeSpots();
            OrbitImageAnalysis.getInstance().getIFrame().getRecognitionFrame().repaint();
        } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
            unsetClass();
            OrbitImageAnalysis.getInstance().getIFrame().getRecognitionFrame().repaint();
        } else if (e.getKeyCode() == KeyEvent.VK_A) {
            acceptClass(e);
            OrbitImageAnalysis.getInstance().getIFrame().getRecognitionFrame().repaint();
        }
    }

}
 
Example 5
Source File: SelectTool.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void keyPressed(Canvas canvas, KeyEvent e) {
	if (state == MOVING && e.getKeyCode() == KeyEvent.VK_SHIFT) {
		handleMoveDrag(canvas, curDx, curDy, e.getModifiersEx());
	} else {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_BACK_SPACE:
		case KeyEvent.VK_DELETE:
			if (!canvas.getSelection().isEmpty()) {
				Action act = SelectionActions.clear(canvas.getSelection());
				canvas.getProject().doAction(act);
				e.consume();
			}
			break;
		default:
			processKeyEvent(canvas, e, KeyConfigurationEvent.KEY_PRESSED);
		}
	}
}
 
Example 6
Source File: ScriptAutoCompleteKeyListener.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {

    if (textPopupMenu != null && textPopupMenu.isVisible()) {
        if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyChar() == 65535) {
            e.consume();
            textPopupMenu.selectFirstMenu();
        } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
            closeMenu();
        } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
            char delChar = textInput.getText().charAt(textInput.getCaretPosition() - 1);
            if (delChar == '.') {
                // Deleted the dot - close the menu
                closeMenu();
            } else {
                String txt = textBefore(textInput.getText(), textInput.getCaretPosition() - 1);
                filterMenus(txt);
            }
        }
    }
}
 
Example 7
Source File: WiringTool.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(Canvas canvas, KeyEvent event) {
	switch (event.getKeyCode()) {
	case KeyEvent.VK_BACK_SPACE:
		if (lastAction != null && canvas.getProject().getLastAction() == lastAction) {
			canvas.getProject().undoAction();
			lastAction = null;
		}
	}
}
 
Example 8
Source File: CsvTableEditorKeyListener.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
    switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addColumnBefore.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_RIGHT:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addColumnAfter.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_UP:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addRowBefore.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_DOWN:
            if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.addRowAfter.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_ENTER:
            if (e.isControlDown() && csvTableEditor.isInCellEditMode()) {
                stopEditing.actionPerformed(null);
            } else if (!csvTableEditor.isInCellEditMode()) {
                startEditing.actionPerformed(null);
            }
            break;
        case KeyEvent.VK_DELETE:
        case KeyEvent.VK_BACK_SPACE:
            if (e.isControlDown() && e.isShiftDown()) {
                csvTableEditor.tableEditorActions.deleteColumn.actionPerformed(null);
            } else if (e.isControlDown()) {
                csvTableEditor.tableEditorActions.deleteRow.actionPerformed(null);
            } else if (!csvTableEditor.isInCellEditMode()) {
                csvTableEditor.tableEditorActions.clearCells.actionPerformed(null);
            }
            break;
        default:
            break;
    }
}
 
Example 9
Source File: ItemPanel.java    From Java-Simple-Hotel-Management with GNU General Public License v3.0 5 votes vote down vote up
private void tf_item_priceKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_item_priceKeyTyped
     char c = evt.getKeyChar();
    
    if(!(Character.isDigit(c) || c== KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE ))
    {
        evt.consume();
    }
}
 
Example 10
Source File: OrderPanel.java    From Java-Simple-Hotel-Management with GNU General Public License v3.0 5 votes vote down vote up
private void tf_priceKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_priceKeyTyped
    char c = evt.getKeyChar();
    
    if(!(Character.isDigit(c) || c== KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE ))
    {
        evt.consume();
    }
}
 
Example 11
Source File: NeverLog.java    From ExternalPlugins with GNU General Public License v3.0 5 votes vote down vote up
private void pressKey()
{
	KeyEvent keyPress = new KeyEvent(this.client.getCanvas(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_BACK_SPACE);
	this.client.getCanvas().dispatchEvent(keyPress);
	KeyEvent keyRelease = new KeyEvent(this.client.getCanvas(), KeyEvent.KEY_RELEASED, System.currentTimeMillis(), 0, KeyEvent.VK_BACK_SPACE);
	this.client.getCanvas().dispatchEvent(keyRelease);
	KeyEvent keyTyped = new KeyEvent(this.client.getCanvas(), KeyEvent.KEY_TYPED, System.currentTimeMillis(), 0, KeyEvent.VK_BACK_SPACE);
	this.client.getCanvas().dispatchEvent(keyTyped);
}
 
Example 12
Source File: ImageCommand.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public int getKeyEvent(String key) {
    switch (key.toUpperCase()) {
        case "TAB":
            return KeyEvent.VK_TAB;
        case "ENTER":
            return KeyEvent.VK_ENTER;
        case "SHIFT":
            return KeyEvent.VK_SHIFT;
        case "CTRL":
            return KeyEvent.VK_CONTROL;
        case "ALT":
            return KeyEvent.VK_ALT;
        case "START":
            return KeyEvent.VK_WINDOWS;
        case "DELETE":
            return KeyEvent.VK_DELETE;
        case "BACKSPACE":
            return KeyEvent.VK_BACK_SPACE;
        case "HOME":
            return KeyEvent.VK_HOME;
        case "PAGE_UP":
        case "PAGEUP":
            return KeyEvent.VK_PAGE_UP;
        case "PAGE_DOWN":
        case "PAGEDOWN":
            return KeyEvent.VK_PAGE_DOWN;
        case "UP":
            return KeyEvent.VK_UP;
        case "DOWN":
            return KeyEvent.VK_DOWN;
        case "LEFT":
            return KeyEvent.VK_LEFT;
        case "RIGHT":
            return KeyEvent.VK_RIGHT;
        default:
            return KeyEvent.VK_ESCAPE;
    }
}
 
Example 13
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 14
Source File: InstantRenamePerformerTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testCancel3() throws Exception {
    KeyEvent ke = new KeyEvent(new JFrame(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_BACK_SPACE, '\0');
    performTest("package test; public class Test { public void test() {int x|xx = 0; int y = xxx; } }", 79 - 22, ke, "package test; public class Test { public void test() {in xxx = 0; int y = xxx; } }", false);
}
 
Example 15
Source File: Commander.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent ke) {

	final int key = ke.getKeyCode();
	final Object source = ke.getSource();
	final boolean meta = (ke.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
	final boolean metaShift = meta && ke.isShiftDown();

	// Close if Esc, Ctrl+W or Cmd+W
	if (key == KeyEvent.VK_ESCAPE || (key == KeyEvent.VK_W && meta)) {
		quit();

		// Trigger Menu accelerators
	} else if (metaShift) {
		if (key == KeyEvent.VK_C) // Enter/Exit Console
			toggleConsoleMode();
		else if (key == KeyEvent.VK_G) // Go To...
			changeDirectory("");
		else if (!isConsoleMode() && key == KeyEvent.VK_R) // Reveal Path
			Utils.revealFile(path);

	} else if (meta) {

		if (key == KeyEvent.VK_L) {
			prompt.requestFocusInWindow();
			prompt.selectAll();
		} else if (key == KeyEvent.VK_B) {
			activateTable();
		} else if (key == KeyEvent.VK_COMMA) {
			showOptionsDialog();
		} else if (key == KeyEvent.VK_S) {
			saveQuery();
		} else if (!isConsoleMode() && key == KeyEvent.VK_D) {
			addBookmark();
		} else if (!isConsoleMode() && key == KeyEvent.VK_P) {
			printList();
		} else if (!isConsoleMode() && key == KeyEvent.VK_R) {
			resetFileList("Contents reloaded...");
		}

	} else if (source == prompt) {

		// Up or down arrows pressed in prompt: Move the focus to list
		if (key == KeyEvent.VK_UP || key == KeyEvent.VK_DOWN) {
			activateTable();
		}

	} else if (source == table) {

		// Focus in list and left arrow key: move up in directory hierarchy
		if (key == KeyEvent.VK_LEFT) {
			selectParentDirectory(path);
			setSelectedItem(table.getSelectedRow());

			// Focus in list and right arrow key: List sub-directory
		} else if (key == KeyEvent.VK_RIGHT) {
			setSelectedItem(table.getSelectedRow());
			if (isFolder(selectedItem))
				selectSubDirectory(selectedItem);

			// Focus in list and enter: Open selected item
		} else if (key == KeyEvent.VK_ENTER) {
			ke.consume();
			setSelectedItem(table.getSelectedRow());
			openItem(selectedItem);

			// Focus in list and backspace: Switch focus back to prompt
		} else if (key == KeyEvent.VK_BACK_SPACE) {
			prompt.requestFocusInWindow();
			prompt.selectAll();

			// Focus in list and up/down arrow key: Loop through list
		} else if (key == KeyEvent.VK_UP) {
			if (table.getSelectedRow() == 0)
				table.setRowSelectionInterval(tableModel.getRowCount() - 1, tableModel.getRowCount() - 1);
		} else if (key == KeyEvent.VK_DOWN) {
			if (table.getSelectedRow() == tableModel.getRowCount() - 1)
				table.setRowSelectionInterval(0, 0);
		}

	}

}
 
Example 16
Source File: InstantRenamePerformerTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testSimple6() throws Exception {
    KeyEvent[] kes = new KeyEvent[] {new KeyEvent(new JFrame(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_BACK_SPACE, '\0'), new KeyEvent(new JFrame(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_BACK_SPACE, '\0')};
    performTest("package test; public class Test { public void test() {int b| = 0; int y = b; } }", 80 - 22, kes, 81 - 22, "package test; public class Test { public void test() {int = 0; int y = ; } }", false);
}
 
Example 17
Source File: InstantRenamePerformerTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testSimple3() throws Exception {
    KeyEvent ke = new KeyEvent(new JFrame(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_BACK_SPACE, '\0');
    performTest("package test; public class Test { public void test() {int a|bc = 0; int y = abc; } }", 83 - 22 - 1, ke, "package test; public class Test { public void test() {int ac = 0; int y = ac; } }", true);
}
 
Example 18
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 19
Source File: Get2FACode.java    From megabasterd with GNU General Public License v3.0 4 votes vote down vote up
private void current_code_textfieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_current_code_textfieldKeyTyped

        if (current_code_textfield.getText().length() == MAX_CODE_LENGTH || (!Character.isDigit(evt.getKeyChar()) && evt.getKeyCode() != KeyEvent.VK_BACK_SPACE && evt.getKeyCode() != KeyEvent.VK_DELETE)) {
            evt.consume();
        }
    }
 
Example 20
Source File: ActiveBagContentPreviewPanel.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public boolean processKey(KeyEvent e) {
  boolean consumed = false;
  if (cgrid >= 0 && grid[cgrid] != null && tgc[cgrid] != null) {
    int dx = 0, dy = 0;
    boolean delete = false, moveFirst = false;
    Point cur = grid[cgrid].getCursor();
    char ch1 = 0;

    switch (e.getID()) {
    case KeyEvent.KEY_PRESSED:
      switch (e.getKeyCode()) {
      case KeyEvent.VK_RIGHT:
        dx = 1;
        break;
      case KeyEvent.VK_LEFT:
        dx = -1;
        break;
      case KeyEvent.VK_DOWN:
        dy = 1;
        break;
      case KeyEvent.VK_UP:
        dy = -1;
        break;
      case KeyEvent.VK_BACK_SPACE:
        dx = -1;
        delete = true;
        moveFirst = true;
        break;
      case KeyEvent.VK_DELETE:
        delete = true;
        break;
      }
      break;

    case KeyEvent.KEY_TYPED:
      char ch0 = e.getKeyChar();
      int kk = e.getKeyCode();
      if (cur != null) {
        dx = 1;
        if (Character.isLetterOrDigit(ch0))
          ch1 = Character.toUpperCase(ch0);
        else if (ch0 == tgc[cgrid].wild || Character.isSpaceChar(ch0))
          delete = true;
        else
          dx = 0;
      }
      break;
    }
    if (moveFirst && (dx != 0 || dy != 0)) {
      moveCursor(dx, dy);
      cur = grid[cgrid].getCursor();
      consumed = true;
    }
    if (delete)
      ch1 = tgc[cgrid].wild;
    if (ch1 != 0 && cur != null) {
      if (crossWord) {
        checkWildChanges(cur, ch1);
      }
      grid[cgrid].setCharAt(cur.x, cur.y, ch1);
      tgc[cgrid].setCharAt(cur.x, cur.y, ch1);
      setModified(true);
      consumed = true;
    }
    if (!moveFirst && (dx != 0 || dy != 0)) {
      moveCursor(dx, dy);
      consumed = true;
    }
  }
  return consumed;
}