Java Code Examples for java.awt.event.KeyEvent#isAltDown()

The following examples show how to use java.awt.event.KeyEvent#isAltDown() . 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: Ruler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    int step = e.isControlDown() ? 50 : e.isAltDown() ? 1 : 5;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            setLocation(getX() - step, getY());
            break;
        case KeyEvent.VK_RIGHT:
            setLocation(getX() + step, getY());
            break;
        case KeyEvent.VK_UP:
            setLocation(getX(), getY() - step);
            break;
        case KeyEvent.VK_DOWN:
            setLocation(getX(), getY() + step);
            break;
        case KeyEvent.VK_ESCAPE:
            exitAction.actionPerformed(null);
    }
}
 
Example 2
Source File: CAbstractKeyBehavior.java    From binnavi with Apache License 2.0 6 votes vote down vote up
private void setModifier(final KeyEvent event) {
  m_ctrl = false;
  m_shift = false;
  m_alt = false;

  if (event.getModifiersEx() == (InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)) {
    m_ctrl = true;
    m_shift = true;
  } else if (event.getModifiersEx() == (InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK)) {
    m_ctrl = true;
    m_alt = true;
  } else if (event.getModifiersEx() == (InputEvent.ALT_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)) {
    m_alt = true;
    m_shift = true;
  } else if (event.isAltDown()) {
    m_alt = true;
  } else if (event.isControlDown()) {
    m_ctrl = true;
  } else if (event.isShiftDown()) {
    m_shift = true;
  }
}
 
Example 3
Source File: Ruler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    int step = e.isControlDown() ? 50 : e.isAltDown() ? 1 : 5;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            setLocation(getX() - step, getY());
            break;
        case KeyEvent.VK_RIGHT:
            setLocation(getX() + step, getY());
            break;
        case KeyEvent.VK_UP:
            setLocation(getX(), getY() - step);
            break;
        case KeyEvent.VK_DOWN:
            setLocation(getX(), getY() + step);
            break;
        case KeyEvent.VK_ESCAPE:
            exitAction.actionPerformed(null);
    }
}
 
Example 4
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 6 votes vote down vote up
@Override
protected synchronized void doHandleKeyTyped(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key typed: " + e.paramString());
    final char keyChar = e.getKeyChar();

    // Don't type non printable characters.
    if (keyChar == KeyEvent.CHAR_UNDEFINED || Character.isWhitespace(keyChar) || Character.isISOControl(keyChar) || Character.isIdentifierIgnorable(keyChar)) {
        //LOGGER.debug("non printable {} / {}", Character.isWhitespace(keyChar), Character.isISOControl(keyChar));
        return;
    }

    // Don't type a character, if a modifier key is pressed at the same time.
    if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown())) {
        //LOGGER.debug("modifier {} / {} / {} / {}", e.isControlDown(), e.isAltDown(), e.isMetaDown(), windowsKeyDown);
        return;
    }

    //LOGGER.debug("type character \"{}\" ({})", keyChar, e.getKeyCode());
    handler.sendKeyType(keyChar);
    e.consume();
}
 
Example 5
Source File: Ruler.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    int step = e.isControlDown() ? 50 : e.isAltDown() ? 1 : 5;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            setLocation(getX() - step, getY());
            break;
        case KeyEvent.VK_RIGHT:
            setLocation(getX() + step, getY());
            break;
        case KeyEvent.VK_UP:
            setLocation(getX(), getY() - step);
            break;
        case KeyEvent.VK_DOWN:
            setLocation(getX(), getY() + step);
            break;
        case KeyEvent.VK_ESCAPE:
            exitAction.actionPerformed(null);
    }
}
 
Example 6
Source File: Ruler.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    int step = e.isControlDown() ? 50 : e.isAltDown() ? 1 : 5;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            setLocation(getX() - step, getY());
            break;
        case KeyEvent.VK_RIGHT:
            setLocation(getX() + step, getY());
            break;
        case KeyEvent.VK_UP:
            setLocation(getX(), getY() - step);
            break;
        case KeyEvent.VK_DOWN:
            setLocation(getX(), getY() + step);
            break;
        case KeyEvent.VK_ESCAPE:
            exitAction.actionPerformed(null);
    }
}
 
Example 7
Source File: KeyGetter.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
void processVTKeyReleased(KeyEvent e){
         displayInfo(e);
      if (isLinux && e.getKeyCode() == KeyEvent.VK_ALT_GRAPH) {

         isAltGr = false;
      }
      int keycode = e.getKeyCode();
      if (e.isAltDown() ||
         e.isShiftDown() ||
         e.isControlDown() ||
         e.isActionKey() ||
         keycode == KeyEvent.VK_CONTROL) {


         keyevent = e;
//            displayInfo(e,"Released added");
         dialog.setVisible(false);
         dialog.dispose();
      }
  }
 
Example 8
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
public KeyStroker(KeyEvent ke, boolean isAltGrDown) {


    this.keyCode = ke.getKeyCode();
    this.isShiftDown = ke.isShiftDown();
    this.isControlDown = ke.isControlDown();
    this.isAltDown = ke.isAltDown();
    this.isAltGrDown = isAltGrDown;
    this.location = ke.getKeyLocation();

    hashCode = keyCode +
        (isShiftDown ? 1 : 0) +
        (isControlDown ? 1 : 0) +
        (isAltDown ? 1 : 0) +
        (isAltGrDown ? 1 : 0) +
        location;

  }
 
Example 9
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
public void setAttributes(KeyEvent ke, boolean isAltGr) {

    keyCode = ke.getKeyCode();
    isShiftDown = ke.isShiftDown();
    isControlDown = ke.isControlDown();
    isAltDown = ke.isAltDown();
    isAltGrDown = isAltGr;
    location = ke.getKeyLocation();

    hashCode = keyCode +
        (isShiftDown ? 1 : 0) +
        (isControlDown ? 1 : 0) +
        (isAltDown ? 1 : 0) +
        (isAltGrDown ? 1 : 0) +
        location;
  }
 
Example 10
Source File: ColorPickerPanel.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	int dx = 0;
	int dy = 0;
	if(e.getKeyCode()==KeyEvent.VK_LEFT) {
		dx = -1;
	} else if(e.getKeyCode()==KeyEvent.VK_RIGHT) {
		dx = 1;
	} else if(e.getKeyCode()==KeyEvent.VK_UP) {
		dy = -1;
	} else if(e.getKeyCode()==KeyEvent.VK_DOWN) {
		dy = 1;
	}
	int multiplier = 1;
	if(e.isShiftDown() && e.isAltDown()) {
		multiplier = 10;
	} else if(e.isShiftDown() || e.isAltDown()) {
		multiplier = 5;
	}
	if(dx!=0 || dy!=0) {
		int size = Math.min(MAX_SIZE, Math.min(getWidth()-imagePadding.left-imagePadding.right,getHeight()-imagePadding.top-imagePadding.bottom));
		
		int offsetX = getWidth()/2-size/2;
		int offsetY = getHeight()/2-size/2;
		mouseListener.mousePressed(new MouseEvent(ColorPickerPanel.this,
				MouseEvent.MOUSE_PRESSED,
				System.currentTimeMillis(), 0,
				point.x+multiplier*dx+offsetX,
				point.y+multiplier*dy+offsetY,
				1, false
				));
	}
}
 
Example 11
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
public boolean equals(KeyEvent ke) {

    return (keyCode == ke.getKeyCode() &&
        isShiftDown == ke.isShiftDown() &&
        isControlDown == ke.isControlDown() &&
        isAltDown == ke.isAltDown() &&
        isAltGrDown == ke.isAltGraphDown() &&
        location == ke.getKeyLocation());
  }
 
Example 12
Source File: ClarifyingKeyListener.java    From SNT with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(final KeyEvent e) {

	final int keyCode = e.getKeyCode();

	if (e.isShiftDown() && (e.isControlDown() || e.isAltDown()) && (keyCode == KeyEvent.VK_A)) {
		IJ.error("You seem to be trying to start Sholl analysis, but the focus is on the wrong window.\n"
				+ "Bring the (2D) image window to the foreground and try again.");
		e.consume();
	}
}
 
Example 13
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 14
Source File: ColorPickerPanel.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    int dx = 0;
    int dy = 0;
    if (e.getKeyCode() == KeyEvent.VK_LEFT) {
        dx = -1;
    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
        dx = 1;
    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
        dy = -1;
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        dy = 1;
    }
    int multiplier = 1;
    if (e.isShiftDown() && e.isAltDown()) {
        multiplier = 10;
    } else if (e.isShiftDown() || e.isAltDown()) {
        multiplier = 5;
    }
    if (dx != 0 || dy != 0) {
        int size = Math.min(MAX_SIZE, Math
                .min(getWidth() - imagePadding.left - imagePadding.right, getHeight() - imagePadding.top - imagePadding.bottom));

        int offsetX = getWidth() / 2 - size / 2;
        int offsetY = getHeight() / 2 - size / 2;
        mouseListener.mousePressed(new MouseEvent(ColorPickerPanel.this,
                MouseEvent.MOUSE_PRESSED,
                System.currentTimeMillis(), 0,
                point.x + multiplier * dx + offsetX,
                point.y + multiplier * dy + offsetY,
                1, false
        ));
    }
}
 
Example 15
Source File: WTextFieldPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
    switch (e.getID()) {
       case KeyEvent.KEY_TYPED:
           if ((e.getKeyChar() == '\n') && !e.isAltDown() && !e.isControlDown()) {
                postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          getText(), e.getWhen(), e.getModifiers()));
                return true;
           }
       break;
    }
    return false;
}
 
Example 16
Source File: WTextFieldPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
    switch (e.getID()) {
       case KeyEvent.KEY_TYPED:
           if ((e.getKeyChar() == '\n') && !e.isAltDown() && !e.isControlDown()) {
                postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          getText(), e.getWhen(), e.getModifiers()));
                return true;
           }
       break;
    }
    return false;
}
 
Example 17
Source File: GrandExchangeInputListener.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void keyPressed(KeyEvent e)
{
	if (e.isAltDown())
	{
		plugin.setHotKeyPressed(true);
	}
}
 
Example 18
Source File: View2D.java    From energy2d with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void processKeyReleased(KeyEvent e) {
	if (runHeatingThread) {
		if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
			cooling = false;
		}
	}
	switch (e.getKeyCode()) {
	case KeyEvent.VK_DELETE:
	case KeyEvent.VK_BACK_SPACE:
		// this is different than cut() in that it doesn't create a copy for pasting
		if (selectedManipulable != null) {
			if (JOptionPane.showConfirmDialog(this, "Are you sure you want to delete the selected object?", "Delete Object", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
				undoManager.addEdit(new UndoRemoveManipulable(this));
				notifyManipulationListeners(selectedManipulable, ManipulationEvent.DELETE);
				setSelectedManipulable(null);
			}
		} else {
			if (showGraph) {
				if (JOptionPane.showConfirmDialog(this, "Are you sure you want to erase the graph?", "Erase Graph", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
					eraseGraph();
				}
			}
		}
		break;
	case KeyEvent.VK_R:
		notifyManipulationListeners(null, runToggle ? ManipulationEvent.STOP : ManipulationEvent.RUN);
		break;
	case KeyEvent.VK_T:
		notifyManipulationListeners(null, ManipulationEvent.RESET);
		break;
	case KeyEvent.VK_L:
		notifyManipulationListeners(null, ManipulationEvent.RELOAD);
		break;
	case KeyEvent.VK_S: // avoid conflict with the save keystroke
		if (!e.isControlDown() && !e.isMetaDown() && !e.isAltDown())
			notifyManipulationListeners(null, ManipulationEvent.SUN_SHINE);
		break;
	case KeyEvent.VK_Q:
		notifyManipulationListeners(null, ManipulationEvent.SUN_ANGLE_INCREASE);
		break;
	case KeyEvent.VK_W:
		notifyManipulationListeners(null, ManipulationEvent.SUN_ANGLE_DECREASE);
		break;
	case KeyEvent.VK_G:
		showGraph = !showGraph;
		notifyGraphListeners(showGraph ? GraphEvent.GRAPH_OPENED : GraphEvent.GRAPH_CLOSED);
		break;
	case KeyEvent.VK_ESCAPE: // allow the app to shut down when in full screen mode
		Object r = getClientProperty("close_full_screen");
		if (r instanceof Runnable)
			((Runnable) r).run();
		break;
	}
	repaint();
	tipText = null;
	// e.consume();//don't call, or this stops key binding
}
 
Example 19
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("Duplicates")
protected synchronized void doHandleKeyPress(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key pressed: " + e.paramString());

    // Get code of the pressed key.
    // Keypad arrows are translated to regular arrow keys.
    final int keyCode;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_KP_DOWN:
            keyCode = KeyEvent.VK_DOWN;
            break;
        case KeyEvent.VK_KP_LEFT:
            keyCode = KeyEvent.VK_LEFT;
            break;
        case KeyEvent.VK_KP_RIGHT:
            keyCode = KeyEvent.VK_RIGHT;
            break;
        case KeyEvent.VK_KP_UP:
            keyCode = KeyEvent.VK_UP;
            break;
        default:
            keyCode = e.getKeyCode();
            break;
    }

    // Never press undefined key codes.
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return;
    }

    // Never send caps lock, num lock and scroll lock key.
    if (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || keyCode == KeyEvent.VK_SCROLL_LOCK) {
        return;
    }

    // Detect, if a control key was pressed.
    final boolean isControlKey = e.isActionKey() ||
            keyCode == KeyEvent.VK_BACK_SPACE ||
            keyCode == KeyEvent.VK_DELETE ||
            keyCode == KeyEvent.VK_ENTER ||
            keyCode == KeyEvent.VK_SPACE ||
            keyCode == KeyEvent.VK_TAB ||
            keyCode == KeyEvent.VK_ESCAPE ||
            keyCode == KeyEvent.VK_ALT ||
            keyCode == KeyEvent.VK_ALT_GRAPH ||
            keyCode == KeyEvent.VK_CONTROL ||
            keyCode == KeyEvent.VK_SHIFT ||
            keyCode == KeyEvent.VK_META;

    // Press control keys.
    if (isControlKey) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        e.consume();
    }

    // Press other keys, if they are pressed together with a modifier key.
    else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown())) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        if (!pressedKeys.contains(keyCode))
            pressedKeys.add(keyCode);
        e.consume();
    }

    // Remember, that the Windows key was pressed.
    if (keyCode == KeyEvent.VK_WINDOWS) {
        synchronized (Frame.this) {
            windowsKeyDown = true;
        }
    }
}
 
Example 20
Source File: MenuBuilder.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public boolean matches(KeyEvent ev) {
    return ev.getKeyCode() == key && ev.isControlDown() == ctrlDown && ev.isShiftDown() == shiftDown && ev.isAltDown() == altDown;
}