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

The following examples show how to use java.awt.event.KeyEvent#VK_CONTROL . 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: KeyShortCutEditPanel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
private void textFieldKeyCodeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldKeyCodeKeyPressed
  if (this.buttonEditKeyCode.isSelected()){
    switch(evt.getKeyCode()){
      case KeyEvent.VK_META:
      case KeyEvent.VK_ALT:
      case KeyEvent.VK_SHIFT:
      case KeyEvent.VK_CONTROL: evt.consume();break;
      default:{
        updateCurrentSelectedForKey(evt);
        this.buttonEditKeyCode.setSelected(false);
        this.tableKeyShortcuts.requestFocus();
      }break;
    }
  }
  evt.consume();
}
 
Example 2
Source File: Demo_SpeechRecognitionCopypasta.java    From haxademic with MIT License 6 votes vote down vote up
public void recognizedWord(String word) {
	P.out("WORD:", word);
	voiceCommand = word;

	int control = (P.platform == P.MACOSX) ? 157 : KeyEvent.VK_CONTROL;
	
	if(word.equals("copy")) {
		keyQueue.add(new KeySequence(true, control));
		keyQueue.add(new KeySequence(true, KeyEvent.VK_C));
		keyQueue.add(new KeySequence(false, KeyEvent.VK_C));
		keyQueue.add(new KeySequence(false, control));
	} else if(word.equals("paste")) {
		keyQueue.add(new KeySequence(true, control));
		keyQueue.add(new KeySequence(true, KeyEvent.VK_V));
		keyQueue.add(new KeySequence(false, KeyEvent.VK_V));
		keyQueue.add(new KeySequence(false, control));
	} else if(word.equals("undo")) {
		keyQueue.add(new KeySequence(true, control));
		keyQueue.add(new KeySequence(true, KeyEvent.VK_Z));
		keyQueue.add(new KeySequence(false, KeyEvent.VK_Z));
		keyQueue.add(new KeySequence(false, control));
	}
}
 
Example 3
Source File: MnemonicHandler.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean postProcessKeyEvent( KeyEvent e ) {
	int keyCode = e.getKeyCode();
	if( SystemInfo.IS_MAC ) {
		// Ctrl+Alt keys must be pressed on Mac
		if( keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT )
			showMnemonics( shouldShowMnemonics( e ) && e.isControlDown() && e.isAltDown(), e.getComponent() );
	} else {
		// Alt key must be pressed on Windows and Linux
		if( SystemInfo.IS_WINDOWS )
			return processKeyEventOnWindows( e );

		if( keyCode == KeyEvent.VK_ALT )
			showMnemonics( shouldShowMnemonics( e ), e.getComponent() );
	}

	return false;
}
 
Example 4
Source File: EditablePlot.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void keyReleased(KeyEvent e) {
    int keycode = e.getKeyCode();
    switch(keycode) {
    case KeyEvent.VK_CONTROL:
        _control = false;
        break;
    default:
        // None
    }
}
 
Example 5
Source File: KeyStrokeParser.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private int getModifier(int keycode) {
    switch (keycode) {
    case KeyEvent.VK_SHIFT:
        return InputEvent.SHIFT_MASK;
    case KeyEvent.VK_CONTROL:
        return InputEvent.CTRL_MASK;
    case KeyEvent.VK_ALT:
        return InputEvent.ALT_MASK;
    case KeyEvent.VK_META:
        return InputEvent.META_MASK;
    default:
        throw new RuntimeException(OSUtils.keyEventGetKeyText(keycode) + " is not a valid modifier");
    }
}
 
Example 6
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 7
Source File: BarbarianAssaultPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	if (e.getKeyCode() == KeyEvent.VK_SHIFT)
	{
		shiftDown = true;
	}

	if (e.getKeyCode() == KeyEvent.VK_CONTROL)
	{
		controlDown = true;
	}
}
 
Example 8
Source File: AntiDragPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void keyReleased(KeyEvent e)
{
	if (e.getKeyCode() == KeyEvent.VK_CONTROL && config.disableOnCtrl() && !(inPvp || config.onShiftOnly()))
	{
		setDragDelay();
		ctrlHeld = false;
	}
	else if (e.getKeyCode() == KeyEvent.VK_SHIFT && (inPvp || config.onShiftOnly()))
	{
		resetDragDelay();
		shiftHeld = false;
	}
}
 
Example 9
Source File: SelectTool.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(Canvas canvas, KeyEvent e) {
	int code = e.getKeyCode();
	if ((code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_CONTROL || code == KeyEvent.VK_ALT)
			&& curAction != IDLE) {
		setMouse(canvas, lastMouseX, lastMouseY, e.getModifiersEx());
	}
}
 
Example 10
Source File: KeyboardSupport.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void reactToReleaseEvent(CEventCallback callback, int vk_event, int modifier) {
    switch (vk_event) {
        case KeyEvent.VK_CONTROL:
            if ((mask & MULTITOUCH.mask) != 0)
                callback.endMultiTouch();
            break;
        case KeyEvent.VK_B:
        case KeyEvent.VK_BACK_SPACE:
            if ((mask & BACK.mask) != 0)
                callback.back();
            break;
        case KeyEvent.VK_P:
        case KeyEvent.VK_SPACE:
            if ((mask & PAUSE.mask) != 0)
                ((DesktopLifecycleBridge) Native.lifecycle()).toggleActivation();
            break;
        case KeyEvent.VK_ESCAPE:
        case KeyEvent.VK_Q:
            if ((mask & QUIT.mask) != 0)
                callback.powerOff();
            break;
        case KeyEvent.VK_M:
            if (modifier == KeyEvent.CTRL_MASK)
                memoryWarning();
            break;
        case KeyEvent.VK_H:
        case KeyEvent.VK_HOME:
            if ((mask & HOME.mask) != 0)
                callback.home();
            break;
        case KeyEvent.VK_LEFT:
            if ((mask & ROTATE.mask) != 0)
                callback.rotateLeft();
            break;
        case KeyEvent.VK_RIGHT:
            if ((mask & ROTATE.mask) != 0)
                callback.rotateRight();
            break;
    }
}
 
Example 11
Source File: RectangularTool.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(Canvas canvas, KeyEvent e) {
	int code = e.getKeyCode();
	if (active && (code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_ALT || code == KeyEvent.VK_CONTROL)) {
		updateMouse(canvas, lastMouseX, lastMouseY, e.getModifiersEx());
	}
}
 
Example 12
Source File: CameraPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyReleased(KeyEvent e)
{
	if (e.getKeyCode() == KeyEvent.VK_CONTROL)
	{
		controlDown = false;

		if (config.controlFunction() == ControlFunction.CONTROL_TO_RESET)
		{
			final int zoomValue = MiscUtils.clamp(config.ctrlZoomValue(), config.OUTER_LIMIT_MIN, config.INNER_ZOOM_LIMIT);
			clientThread.invokeLater(() -> client.runScript(ScriptID.CAMERA_DO_ZOOM, zoomValue, zoomValue));
		}
	}
}
 
Example 13
Source File: DefaultInputHandler.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Handle a key pressed event. This will look up the binding for the key stroke and execute it.
 */
@Override
@SuppressWarnings("unchecked")
public void keyPressed(KeyEvent evt) {
	int keyCode = evt.getKeyCode();
	int modifiers = evt.getModifiers();

	if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT
			|| keyCode == KeyEvent.VK_META) {
		return;
	}

	if ((modifiers & InputEvent.SHIFT_MASK) != 0 || (modifiers & InputEvent.CTRL_MASK) != 0 || evt.isActionKey()
			|| keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_ENTER
			|| keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ESCAPE) {

		if (grabAction != null) {
			handleGrabAction(evt);
			return;
		}

		KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers);
		Object o = currentBindings.get(keyStroke);
		if (o == null) {
			// Don't beep if the user presses some
			// key we don't know about unless a
			// prefix is active. Otherwise it will
			// beep when caps lock is pressed, etc.
			if (currentBindings != bindings) {
				Toolkit.getDefaultToolkit().beep();
				// F10 should be passed on, but C+e F10
				// shouldn't
				repeatCount = 0;
				repeat = false;
				evt.consume();
			}
			currentBindings = bindings;
			return;
		} else if (o instanceof ActionListener) {
			currentBindings = bindings;

			executeAction((ActionListener) o, evt.getSource(), null);

			evt.consume();
			return;
		} else if (o instanceof Hashtable) {
			currentBindings = (Hashtable<KeyStroke, Object>) o;
			evt.consume();
			return;
		}
	}
}
 
Example 14
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 15
Source File: RecentViewListAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    boolean editors = true;
    boolean views = !documentsOnly;
    if( "immediately".equals( evt.getActionCommand() ) ) {
        TopComponent activeTc = TopComponent.getRegistry().getActivated();
        if( null != activeTc ) {
            if( TopComponentTracker.getDefault().isEditorTopComponent( activeTc ) ) {
                //switching in a document, go to some other document
                views = false;
            } else {
                //switching in a view, go to some other view
                editors = false;
                views = true;
            }
        }
    }
    
    TopComponent[] documents = getRecentWindows(editors, views);
    
    if (documents.length < 2) {
        return;
    }
    
    if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
            !(evt.getSource() instanceof javax.swing.JMenuItem)) {
        // #46800: fetch key directly from action command
        KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
        
        if(keyStroke != null) {
            int triggerKey = keyStroke.getKeyCode();
            int reverseKey = KeyEvent.VK_SHIFT;
            int releaseKey = 0;
            
            int modifiers = keyStroke.getModifiers();
            if((InputEvent.CTRL_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_CONTROL;
            } else if((InputEvent.ALT_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_ALT;
            } else if((InputEvent.META_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_META;
            }
            
            if(releaseKey != 0) {
                if (!KeyboardPopupSwitcher.isShown()) {
                    KeyboardPopupSwitcher.showPopup(documentsOnly, releaseKey, triggerKey, (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0);
                }
                return;
            }
        }
    }

    int documentIndex = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : documents.length-1;
    TopComponent tc = documents[documentIndex];
    // #37226 Unmaximized the other mode if needed.
    WindowManagerImpl wm = WindowManagerImpl.getInstance();
    ModeImpl mode = (ModeImpl) wm.findMode(tc);
    if(mode != null && mode != wm.getCurrentMaximizedMode()) {
        wm.switchMaximizedMode(null);
    }
    
    tc.requestActive();
}
 
Example 16
Source File: KeyMaskTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void doTest() throws Exception {

        ArrayList<Component> components = new ArrayList();
        components.add(button);
        components.add(buttonLW);
        components.add(textField);
        components.add(textArea);
        components.add(list);
        components.add(listLW);

        int keys[];
        String OS = System.getProperty("os.name").toLowerCase();
        System.out.println(OS);
        if (OS.contains("os x") || OS.contains("sunos")) {
            keys = new int[] {KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_META};
        } else {
            keys = new int[] {KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT};
        }

        for (Component c: components) {

            System.out.print(c.getClass().getName() + ": ");

            Point origin = c.getLocationOnScreen();
            int xc = origin.x + c.getWidth() / 2;
            int yc = origin.y + c.getHeight() / 2;
            Point center = new Point(xc, yc);

            robot.delay(robotDelay);
            robot.glide(origin, center);
            robot.click();
            robot.delay(robotDelay);

            for (int k = 0; k < keys.length; ++k) {

                keyPressReceived = false;

                keyCode = keys[k];

                robot.type(keyCode);

                robot.delay(robotDelay);

                if (!keyPressReceived) {
                    synchronized (lock) {
                        try {
                            lock.wait(waitDelay);
                        } catch (InterruptedException e) {}
                    }
                }

                assertTrue(keyPressReceived, "key press event was not received");
            }

            System.out.println("passed");
        }

        robot.waitForIdle();
        frame.dispose();
    }
 
Example 17
Source File: JavaRecorderHook.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static String keyEventGetKeyText(int keycode) {
    if (keycode == KeyEvent.VK_TAB) {
        return "Tab";
    }
    if (keycode == KeyEvent.VK_CONTROL) {
        return "Ctrl";
    }
    if (keycode == KeyEvent.VK_ALT) {
        return "Alt";
    }
    if (keycode == KeyEvent.VK_SHIFT) {
        return "Shift";
    }
    if (keycode == KeyEvent.VK_META) {
        return "Meta";
    }
    if (keycode == KeyEvent.VK_SPACE) {
        return "Space";
    }
    if (keycode == KeyEvent.VK_BACK_SPACE) {
        return "Backspace";
    }
    if (keycode == KeyEvent.VK_HOME) {
        return "Home";
    }
    if (keycode == KeyEvent.VK_END) {
        return "End";
    }
    if (keycode == KeyEvent.VK_DELETE) {
        return "Delete";
    }
    if (keycode == KeyEvent.VK_PAGE_UP) {
        return "Pageup";
    }
    if (keycode == KeyEvent.VK_PAGE_DOWN) {
        return "Pagedown";
    }
    if (keycode == KeyEvent.VK_UP) {
        return "Up";
    }
    if (keycode == KeyEvent.VK_DOWN) {
        return "Down";
    }
    if (keycode == KeyEvent.VK_LEFT) {
        return "Left";
    }
    if (keycode == KeyEvent.VK_RIGHT) {
        return "Right";
    }
    if (keycode == KeyEvent.VK_ENTER) {
        return "Enter";
    }
    return KeyEvent.getKeyText(keycode);
}
 
Example 18
Source File: OSUtils.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public static String keyEventGetKeyText(int keycode) {
    if (keycode == KeyEvent.VK_TAB) {
        return "Tab";
    }
    if (keycode == KeyEvent.VK_CONTROL) {
        return "Ctrl";
    }
    if (keycode == KeyEvent.VK_ALT) {
        return "Alt";
    }
    if (keycode == KeyEvent.VK_SHIFT) {
        return "Shift";
    }
    if (keycode == KeyEvent.VK_META) {
        return "Meta";
    }
    if (keycode == KeyEvent.VK_SPACE) {
        return "Space";
    }
    if (keycode == KeyEvent.VK_BACK_SPACE) {
        return "Backspace";
    }
    if (keycode == KeyEvent.VK_HOME) {
        return "Home";
    }
    if (keycode == KeyEvent.VK_END) {
        return "End";
    }
    if (keycode == KeyEvent.VK_DELETE) {
        return "Delete";
    }
    if (keycode == KeyEvent.VK_PAGE_UP) {
        return "Pageup";
    }
    if (keycode == KeyEvent.VK_PAGE_DOWN) {
        return "Pagedown";
    }
    if (keycode == KeyEvent.VK_UP) {
        return "Up";
    }
    if (keycode == KeyEvent.VK_DOWN) {
        return "Down";
    }
    if (keycode == KeyEvent.VK_LEFT) {
        return "Left";
    }
    if (keycode == KeyEvent.VK_RIGHT) {
        return "Right";
    }
    if (keycode == KeyEvent.VK_ENTER) {
        return "Enter";
    }
    return KeyEvent.getKeyText(keycode);
}
 
Example 19
Source File: DesktopApi.java    From workcraft with MIT License 4 votes vote down vote up
public static int getMenuKeyCode() {
    if (getOs().isMac()) {
        return KeyEvent.VK_META;
    }
    return KeyEvent.VK_CONTROL;
}
 
Example 20
Source File: ModifierKeyDoubleClickHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static int getMultiCaretActionModifier() {
  return SystemInfo.isMac ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL;
}