コード例 #1
0
  /** Handles all the actions when a key is pressed */
  public void keyPressed(ShrimpKeyEvent e) {
    int code = e.getKeyCode();
    // in case the system didn't throw all the events, this clears the modifiers for us
    if (e.getModifiers() == 0) {
      isCtrlPressed = false;
      isShiftPressed = false;
      isAltPressed = false;
    }
    if (code == KeyEvent.VK_CONTROL) {
      isCtrlPressed = true;
    } else if (code == KeyEvent.VK_SHIFT) {
      isShiftPressed = true;
    } else if (code == KeyEvent.VK_ALT) {
      isAltPressed = true;
    }

    // tool.clearOutputText();

    for (int i = 0; i < keyPressedEvents.size(); i++) {
      UserEvent userEvent = (UserEvent) keyPressedEvents.elementAt(i);
      if (userEvent.getKeyOrButton() == code) {
        if ((isShiftPressed == userEvent.isShiftRequired())
            && (isCtrlPressed == userEvent.isControlRequired())
            && (isAltPressed == userEvent.isAltRequired())) {
          startAction(userEvent.getAction());
        }
      }
    }
  }
コード例 #2
0
  /** Handles all the actions when a key is released */
  public void keyReleased(ShrimpKeyEvent e) {
    int code = e.getKeyCode();
    if (code == KeyEvent.VK_CONTROL) {
      isCtrlPressed = false;
    } else if (code == KeyEvent.VK_SHIFT) {
      isShiftPressed = false;
    } else if (code == KeyEvent.VK_ALT) {
      isAltPressed = false;
    }

    for (int i = 0; i < keyReleasedEvents.size(); i++) {
      UserEvent userEvent = (UserEvent) keyReleasedEvents.elementAt(i);
      if (userEvent.getKeyOrButton() == code) {
        if ((isShiftPressed == userEvent.isShiftRequired())
            && (isCtrlPressed == userEvent.isControlRequired())
            && (isAltPressed == userEvent.isAltRequired())) {
          stopAction(userEvent.getAction());
        }
      }
    }
  }