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

The following examples show how to use java.awt.event.KeyEvent#VK_V . 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: OpenTCSDrawingView.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void processKeyEvent(KeyEvent e) {
  if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
    // Cut, copy, paste and duplicate
    if (e.getKeyCode() == KeyEvent.VK_X
        || e.getKeyCode() == KeyEvent.VK_C
        || e.getKeyCode() == KeyEvent.VK_V
        || e.getKeyCode() == KeyEvent.VK_D) {
      if (!appState.hasOperationMode(OperationMode.MODELLING)) {
        return;
      }
      processCutPasteKeyEvent();
    }
  }

  super.processKeyEvent(e);
}
 
Example 2
Source File: KeyBindingUtilsTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseKeyStroke() {

	KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_V, 0);
	String parsed = KeyBindingUtils.parseKeyStroke(ks);
	assertEquals("V", parsed);

	ks = KeyStroke.getKeyStroke('v');
	parsed = KeyBindingUtils.parseKeyStroke(ks);
	assertEquals("v", parsed);

	int modifiers = InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK;
	ks = KeyStroke.getKeyStroke(KeyEvent.VK_V, modifiers);
	parsed = KeyBindingUtils.parseKeyStroke(ks);
	assertEquals("Ctrl-Shift-V", parsed);

	ks = KeyStroke.getKeyStroke(KeyEvent.VK_V, modifiers, true);
	parsed = KeyBindingUtils.parseKeyStroke(ks);
	assertEquals("Ctrl-Shift-V", parsed);

	JButton b = new JButton();
	KeyEvent event = new KeyEvent(b, KeyEvent.KEY_PRESSED, 1, modifiers, KeyEvent.VK_V, 'v');
	ks = KeyStroke.getKeyStrokeForEvent(event);
	parsed = KeyBindingUtils.parseKeyStroke(ks);
	assertEquals("Ctrl-Shift-V", parsed);
}
 
Example 3
Source File: ClipboardKeyAdapter.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Override
public void keyReleased(KeyEvent event) {
    if (event.isControlDown() || event.isMetaDown()) {
        switch (event.getKeyCode()) {
            case KeyEvent.VK_C:
                // Copy
                cancelEditing();
                XTableUtils.copyToClipboard(table, false);
                break;
            case KeyEvent.VK_X:
                // Cut
                cancelEditing();
                XTableUtils.copyToClipboard(table, true);
                break;
            case KeyEvent.VK_V:
                // Paste
                cancelEditing();
                XTableUtils.pasteFromClipboard(table);
                break;
            default:
                break;
        }
    }

}
 
Example 4
Source File: MasterCli.java    From brModelo with GNU General Public License v3.0 6 votes vote down vote up
public boolean processeAtalhos(int keyCode) {
    boolean res = false;
    switch (keyCode) {
        case KeyEvent.VK_V:
            doPaste();
            res = true;
            break;
        case KeyEvent.VK_Q:
            Sair();
            res = true;
            break;
        case KeyEvent.VK_D:
            Cancelar();
            res = true;
            break;
    }
    return res;
}
 
Example 5
Source File: Utilities.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
/**
 * Listener for KeyPressed events.
 * 
 * @param e Event.
 * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
 */
@Override
public void keyPressed(KeyEvent e) {
  if ((e.getKeyCode() == KeyEvent.VK_V) &&
      ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0)) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    try {
      String s = (String) clipData.getTransferData(DataFlavor.stringFlavor);
      int start = text.getSelectionStart();
      int end = text.getSelectionEnd();
      if (end > start) {
        text.getDocument().remove(start, end - start);
      }
      text.getDocument().insertString(start, s, null);
      e.consume();
    } catch (Exception ex) {
      //
    }
  }
}
 
Example 6
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 7
Source File: ApplicationKeyListener.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
/**
 * Performs certain actions for certain keys:
 * <ul>
 *     <li>Escape: close application</li>
 *     <li>V and B: cancel rotation</li>
 *     <li>N: clear rotation</li>
 * </ul>
 * @param e The key event
 */
@Override
public void keyReleased(KeyEvent e) {
    if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
        //Close application on escape
        Utilities.closeApplication(frame);
    } else if (KeyEvent.VK_V == e.getKeyCode() || KeyEvent.VK_B == e.getKeyCode()) {
        //Cancel rotation
        rotateTimer.stop();
    } else if (KeyEvent.VK_N == e.getKeyCode()) {
        mapController.setRotation(0);
        mapController.getLocationController().setNavigationMode(NavigationMode.NORTH_UP);
    }
}
 
Example 8
Source File: ChatRoomTransferDecorator.java    From Spark with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent ke) {
       if (ke.getKeyCode() == KeyEvent.VK_V) {
           int i = ke.getModifiers();
           if ((i & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
               Clipboard clb = Toolkit.getDefaultToolkit().getSystemClipboard();
               Transferable contents = clb.getContents(ke.getSource());
               if (contents != null && contents.getTransferDataFlavors().length == 1) {
                   if (contents.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                       SparkManager.getTransferManager().sendImage(SparkTransferManager.getClipboard(), chatRoom);
                   }
               }
           }
       }
   }
 
Example 9
Source File: RobotKeyPressMidi.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {
	MidiDevice.init(0, 0);
	try { _robot = new Robot(); } catch( Exception error ) { println("couldn't init Robot"); }
	
	midiKeyTriggers = new MidiKeyTrigger[] {
			new MidiKeyTrigger(39, KeyEvent.VK_V),
			new MidiKeyTrigger(40, KeyEvent.VK_A),
			new MidiKeyTrigger(54, KeyEvent.VK_B),
			new MidiKeyTrigger(65, KeyEvent.VK_L)
	};
}
 
Example 10
Source File: TableListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
        pressed = true;
    }
    if (pressed && e.getKeyCode() == KeyEvent.VK_V) {
        adaptee.pasteClipboard();
    }
}
 
Example 11
Source File: ObjectSelector.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	int keyCode = e.getKeyCode();
	boolean control = e.isControlDown();
	if (control && keyCode == KeyEvent.VK_C) {
		if (currentEntity != null) {
			GUIFrame.getInstance().copyToClipboard(currentEntity);
		}
	}
	if (control && keyCode == KeyEvent.VK_V) {
		GUIFrame.getInstance().pasteEntityFromClipboard();
	}
}
 
Example 12
Source File: PasteAction.java    From PIPE with MIT License 4 votes vote down vote up
public PasteAction(PipeApplicationController applicationController) {
    super("Paste", "Paste (Ctrl-V)", KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    this.applicationController = applicationController;
}
 
Example 13
Source File: LoginScreenPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	if (!config.pasteEnabled() || (
		client.getGameState() != GameState.LOGIN_SCREEN &&
			client.getGameState() != GameState.LOGIN_SCREEN_AUTHENTICATOR))
	{
		return;
	}

	// enable pasting on macOS with the Command (meta) key
	boolean isModifierDown = OSType.getOSType() == OSType.MacOS ? e.isMetaDown() : e.isControlDown();

	if (e.getKeyCode() == KeyEvent.VK_V && isModifierDown)
	{
		try
		{
			final String data = Toolkit
				.getDefaultToolkit()
				.getSystemClipboard()
				.getData(DataFlavor.stringFlavor)
				.toString()
				.trim();

			switch (client.getLoginIndex())
			{
				// Username/password form
				case 2:
					if (client.getCurrentLoginField() == 0)
					{
						// Truncate data to maximum username length if necessary
						client.setUsername(data.substring(0, Math.min(data.length(), MAX_USERNAME_LENGTH)));
					}

					break;
				// Authenticator form
				case 4:
					// Truncate data to maximum OTP code length if necessary
					client.setOtp(data.substring(0, Math.min(data.length(), MAX_PIN_LENGTH)));
					break;
			}
		}
		catch (UnsupportedFlavorException | IOException ex)
		{
			log.warn("failed to fetch clipboard data", ex);
		}
	}
}
 
Example 14
Source File: AreaTree.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent ke) {
	final int tool = ProjectToolbar.getToolId();
	try {
		if (ProjectToolbar.BRUSH == tool) {

			final Object origin = ke.getSource();
			if (! (origin instanceof DisplayCanvas)) {
				ke.consume();
				return;
			}
			final DisplayCanvas dc = (DisplayCanvas)origin;
			final Layer layer = dc.getDisplay().getLayer();

			final Collection<Node<Area>> nodes = node_layer_map.get(layer);
			if (null == nodes || nodes.isEmpty()) {
				return;
			}

			final Point p = dc.getCursorLoc(); // as offscreen coords
			int x = p.x;
			int y = p.y;
			if (!this.at.isIdentity()) {
				final Point2D.Double po = inverseTransformPoint(x, y);
				x = (int)po.x;
				y = (int)po.y;
			}

			final AreaNode nd = findEventReceiver(nodes, x, y, layer, dc.getMagnification(), ke);

			// Prepare for paste command:
			if (null != nd && null == nd.aw && ke.getKeyCode() == KeyEvent.VK_V) {
				nd.getData(); // creates an.aw
			}

			if (null != nd && null != nd.aw) {
				nd.aw.setSource(this);
				nd.aw.keyPressed(ke, dc, layer);
				nd.aw.setSource(null);
				if (ke.isConsumed()) {
					updateViewData(nd);
					return;
				}
			}
		}
	} finally {
		if (!ke.isConsumed()) {
			super.keyPressed(ke);
		}
	}
}
 
Example 15
Source File: MergedPanel.java    From Briss-2.0 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
        case KeyEvent.VK_C:
            if (e.getModifiersEx() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()) {
                copyToClipBoard();
            }
            break;
        case KeyEvent.VK_V:
            if (e.getModifiersEx() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()) {
                pasteFromClipBoard();
            }
            break;
        case KeyEvent.VK_DELETE:
            deleteAllSelected();
            break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_UP:
        case KeyEvent.VK_DOWN:
            int x = 0;
            int y = 0;
            switch (e.getKeyCode()) {
                case KeyEvent.VK_LEFT:
                    x = -1;
                    break;
                case KeyEvent.VK_RIGHT:
                    x = 1;
                    break;
                case KeyEvent.VK_UP:
                    y = -1;
                    break;
                case KeyEvent.VK_DOWN:
                    y = 1;
                    break;
            }
            if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
                x *= 10;
                y *= 10;
            }
            if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
                briss.resizeSelRects(x, y);
            } else {
                briss.moveSelectedRects(x, y);
            }
            break;
        default:
    }
}
 
Example 16
Source File: LoginScreenPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	if (!config.pasteEnabled() || (
		client.getGameState() != GameState.LOGIN_SCREEN &&
		client.getGameState() != GameState.LOGIN_SCREEN_AUTHENTICATOR))
	{
		return;
	}

	// enable pasting on macOS with the Command (meta) key
	boolean isModifierDown = OSType.getOSType() == OSType.MacOS ? e.isMetaDown() : e.isControlDown();

	if (e.getKeyCode() == KeyEvent.VK_V && isModifierDown)
	{
		try
		{
			final String data = Toolkit
				.getDefaultToolkit()
				.getSystemClipboard()
				.getData(DataFlavor.stringFlavor)
				.toString()
				.trim();

			switch (client.getLoginIndex())
			{
				// Username/password form
				case 2:
					if (client.getCurrentLoginField() == 0)
					{
						// Truncate data to maximum username length if necessary
						client.setUsername(data.substring(0, Math.min(data.length(), MAX_USERNAME_LENGTH)));
					}

					break;
				// Authenticator form
				case 4:
					// Truncate data to maximum OTP code length if necessary
					client.setOtp(data.substring(0, Math.min(data.length(), MAX_PIN_LENGTH)));
					break;
			}
		}
		catch (UnsupportedFlavorException | IOException ex)
		{
			log.warn("failed to fetch clipboard data", ex);
		}
	}
}
 
Example 17
Source File: KeyCodeToChar.java    From Repeat with Apache License 2.0 4 votes vote down vote up
private static String getUpperCaseAlphaChar(int code) {
	switch (code) {
	case KeyEvent.VK_Q:
		return "Q";
	case KeyEvent.VK_W:
		return "W";
	case KeyEvent.VK_E:
		return "E";
	case KeyEvent.VK_R:
		return "R";
	case KeyEvent.VK_T:
		return "T";
	case KeyEvent.VK_Y:
		return "Y";
	case KeyEvent.VK_U:
		return "U";
	case KeyEvent.VK_I:
		return "I";
	case KeyEvent.VK_O:
		return "O";
	case KeyEvent.VK_P:
		return "P";
	case KeyEvent.VK_A:
		return "A";
	case KeyEvent.VK_S:
		return "S";
	case KeyEvent.VK_D:
		return "D";
	case KeyEvent.VK_F:
		return "F";
	case KeyEvent.VK_G:
		return "G";
	case KeyEvent.VK_H:
		return "H";
	case KeyEvent.VK_J:
		return "J";
	case KeyEvent.VK_K:
		return "K";
	case KeyEvent.VK_L:
		return "L";
	case KeyEvent.VK_Z:
		return "Z";
	case KeyEvent.VK_X:
		return "X";
	case KeyEvent.VK_C:
		return "C";
	case KeyEvent.VK_V:
		return "V";
	case KeyEvent.VK_B:
		return "B";
	case KeyEvent.VK_N:
		return "N";
	case KeyEvent.VK_M:
		return "M";
	default:
		return "";
	}
}
 
Example 18
Source File: KeyCodeToChar.java    From Repeat with Apache License 2.0 4 votes vote down vote up
private static String getLowerCaseAlphaChar(int code) {
	switch (code) {
	case KeyEvent.VK_Q:
		return "q";
	case KeyEvent.VK_W:
		return "w";
	case KeyEvent.VK_E:
		return "e";
	case KeyEvent.VK_R:
		return "r";
	case KeyEvent.VK_T:
		return "t";
	case KeyEvent.VK_Y:
		return "y";
	case KeyEvent.VK_U:
		return "u";
	case KeyEvent.VK_I:
		return "i";
	case KeyEvent.VK_O:
		return "o";
	case KeyEvent.VK_P:
		return "p";
	case KeyEvent.VK_A:
		return "a";
	case KeyEvent.VK_S:
		return "s";
	case KeyEvent.VK_D:
		return "d";
	case KeyEvent.VK_F:
		return "f";
	case KeyEvent.VK_G:
		return "g";
	case KeyEvent.VK_H:
		return "h";
	case KeyEvent.VK_J:
		return "j";
	case KeyEvent.VK_K:
		return "k";
	case KeyEvent.VK_L:
		return "l";
	case KeyEvent.VK_Z:
		return "z";
	case KeyEvent.VK_X:
		return "x";
	case KeyEvent.VK_C:
		return "c";
	case KeyEvent.VK_V:
		return "v";
	case KeyEvent.VK_B:
		return "b";
	case KeyEvent.VK_N:
		return "n";
	case KeyEvent.VK_M:
		return "m";
	default:
		return "";
	}
}
 
Example 19
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 20
Source File: SelectionTool.java    From workcraft with MIT License 4 votes vote down vote up
@Override
public boolean keyPressed(GraphEditorKeyEvent e) {
    GraphEditor editor = e.getEditor();
    switch (e.getKeyCode()) {
    case KeyEvent.VK_ESCAPE:
        if (isDragging()) {
            cancelDrag(editor);
        } else {
            cancelSelection(editor);
        }
        return true;
    case KeyEvent.VK_PAGE_UP:
        changeLevelUp(editor);
        return true;
    case KeyEvent.VK_PAGE_DOWN:
        changeLevelDown(editor);
        return true;
    }

    if (!e.isMenuKeyDown() && !e.isShiftKeyDown()) {
        switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            offsetSelection(editor, -1, 0);
            return true;
        case KeyEvent.VK_RIGHT:
            offsetSelection(editor, 1, 0);
            return true;
        case KeyEvent.VK_UP:
            offsetSelection(editor, 0, -1);
            return true;
        case KeyEvent.VK_DOWN:
            offsetSelection(editor, 0, 1);
            return true;
        }
    }

    if (enablePaging && e.isAltKeyDown() && !e.isMenuKeyDown()) {
        switch (e.getKeyCode()) {
        case KeyEvent.VK_G:
            if (e.isShiftKeyDown()) {
                ungroupSelection(editor);
            } else {
                pageSelection(editor);
            }
            return true;
        }
    }

    if (enableGroupping && e.isMenuKeyDown() && !e.isAltKeyDown()) {
        switch (e.getKeyCode()) {
        case KeyEvent.VK_G:
            if (e.isShiftKeyDown()) {
                ungroupSelection(editor);
            } else {
                groupSelection(editor);
            }
            return true;
        }
    }

    if (e.isMenuKeyDown() && !e.isAltKeyDown()) {
        switch (e.getKeyCode()) {
        case KeyEvent.VK_V:
            Point2D pastePosition = TransformHelper.snapP5(currentMousePosition);
            editor.getWorkspaceEntry().setPastePosition(pastePosition);
            return true;
        }
    }

    if (e.isExtendKeyDown()) {
        currentNodes = getNodeWithAdjacentConnections(e.getModel(), currentNode);
        editor.repaint();
        return true;
    }

    return super.keyPressed(e);
}