Esempio n. 1
0
  /** 鼠标按下 */
  public void mousePressed(MouseEvent e) {

    int code = e.getButton();
    try {
      Screen.mouseDown[code] = true;
      Screen.mousePressed[this.pressedMouse] = code;
      this.pressedMouse++;
      if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
        leftClick(e);
      }
      if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
        middleClick(e);
      }
      if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
        rightClick(e);
      }
      if (mouseMap.size() > 0) {
        Action action = (Action) mouseMap.get(String.valueOf(code));
        if (action != null) {
          action.press();
        }
      }
      mouseDown(e);
      e.consume();
    } catch (Exception ex) {
      pressedMouse = 0;
    }
  }
Esempio n. 2
0
  /** 键盘按下 */
  public void keyPressed(KeyEvent e) {

    int code = e.getKeyCode();
    if (e.getModifiers() == InputEvent.ALT_MASK && e.getKeyCode() == KeyEvent.VK_F4) {
      if (handler != null) {
        handler.getScene().close();
      }
    }
    try {
      this.onKey(e);
      if (!keyDown[code & 0xFF]) {
        keyDown[code & 0xFF] = true;
        keyPressed[this.pressedKey] = code;
        this.pressedKey++;
        if (keyMap.size() > 0) {
          Action action = (Action) keyMap.get(String.valueOf(code));
          if (action != null) {
            action.press();
          }
        }
      }
      e.consume();
    } catch (Exception ex) {
      pressedKey = 0;
    }
  }
Esempio n. 3
0
 /** 鼠标放开 */
 public void mouseReleased(MouseEvent e) {
   int code = e.getButton();
   try {
     Screen.mouseDown[code] = false;
     Screen.mouseReleased[this.releasedMouse] = code;
     this.releasedMouse++;
     if (mouseMap.size() > 0) {
       Action action = (Action) mouseMap.get(String.valueOf(code));
       if (action != null) {
         action.release();
       }
     }
     mouseUp(e);
     e.consume();
   } catch (Exception ex) {
     releasedMouse = 0;
   }
 }
Esempio n. 4
0
  /** 键盘放开 */
  public void keyReleased(KeyEvent e) {

    int code = e.getKeyCode();
    try {
      this.onKeyUp(e);
      keyDown[code & 0xFF] = false;
      keyReleased[this.releasedKey] = code;
      this.releasedKey++;
      if (keyMap.size() > 0) {
        Action action = (Action) keyMap.get(String.valueOf(code));
        if (action != null) {
          action.release();
        }
      }
      e.consume();
    } catch (Exception ex) {
      releasedKey = 0;
    }
  }
Esempio n. 5
0
 /**
  * 触发指定事件
  *
  * @param actions
  * @param timer
  */
 private void updateAction(Map actions, int type, long timer) {
   int length = actions.size();
   if (length == 0) {
     return;
   }
   Action keyAction = null;
   switch (type) {
     case 0:
       keyAction = (Action) actions.get(String.valueOf(keyPressed[this.pressedKey]));
       break;
     case 1:
       keyAction = (Action) actions.get(String.valueOf(mousePressed[this.pressedMouse]));
       break;
   }
   if (keyAction != null) {
     if (keyAction.isPressed()) {
       IAction action = keyAction.getIAction();
       action.doAction(timer);
       if (!(action instanceof MoveAction)) {
         keyAction.reset();
       }
     }
   }
 }