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

The following examples show how to use java.awt.event.KeyEvent#VK_LEFT . 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 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 2
Source File: TableFocusManager.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected boolean processExtraKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    if (e.getKeyCode() == KeyEvent.VK_UP && pressed) {
        nextUpElement();
        return true;
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN && pressed) {
        nextDownElement();
        return true;
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT && pressed) {
        prevFocusElement();
        return true;
    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT && pressed) {
        nextFocusElement();
        return true;
    } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE && pressed) {
        requestFocusIfWindowActive(impl);
        impl.editingCanceled(new ChangeEvent(this));
        // allow handle ESCAPE in window
        return false;
    } else {
        return false;
    }
}
 
Example 3
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) { // �u���b�N�����ֈړ�
        block.move(Block.LEFT);
    } else if (key == KeyEvent.VK_RIGHT) { // �u���b�N���E�ֈړ�
        block.move(Block.RIGHT);
    } else if (key == KeyEvent.VK_DOWN) { // �u���b�N�����ֈړ�
        block.move(Block.DOWN);
    } else if (key == KeyEvent.VK_SPACE || key == KeyEvent.VK_UP) { // �u���b�N����]
        block.turn();
    } else if (key == KeyEvent.VK_N) {  // �o�[�u���b�N��\��
        block.createBarBlock();
    }

    repaint();
}
 
Example 4
Source File: Keys.java    From SikuliX1 with MIT License 6 votes vote down vote up
public static boolean isRepeatable(String token) {
  int key = toJavaKeyCodeFromText(token);
  switch (key) {
    case KeyEvent.VK_UP:
      return true;
    case KeyEvent.VK_DOWN:
      return true;
    case KeyEvent.VK_RIGHT:
      return true;
    case KeyEvent.VK_LEFT:
      return true;
    case -KeyEvent.VK_TAB:
      return true;
    case KeyEvent.VK_TAB:
      return true;
    case KeyEvent.VK_ENTER:
      return true;
    case KeyEvent.VK_BACK_SPACE:
      return true;
  }
  return false;
}
 
Example 5
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 6
Source File: Sprite.java    From ThinkJavaCode2 with MIT License 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
        case KeyEvent.VK_UP:
            dy = -5;
            break;
        case KeyEvent.VK_DOWN:
            dy = +5;
            break;
        case KeyEvent.VK_LEFT:
            dx = -5;
            break;
        case KeyEvent.VK_RIGHT:
            dx = +5;
            break;
    }
}
 
Example 7
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();

    if (keyCode == KeyEvent.VK_LEFT) {
        leftKey.press();
    }
    if (keyCode == KeyEvent.VK_RIGHT) {
        rightKey.press();
    }
    if (keyCode == KeyEvent.VK_UP) {
        upKey.press();
    }
    if (keyCode == KeyEvent.VK_DOWN) {
        downKey.press();
    }
    if (keyCode == KeyEvent.VK_SPACE) {
        spaceKey.press();
    }
}
 
Example 8
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();

    if (keyCode == KeyEvent.VK_LEFT) {
        leftKey.press();
    }
    if (keyCode == KeyEvent.VK_RIGHT) {
        rightKey.press();
    }
    if (keyCode == KeyEvent.VK_UP) {
        upKey.press();
    }
    if (keyCode == KeyEvent.VK_DOWN) {
        downKey.press();
    }
    if (keyCode == KeyEvent.VK_SPACE) {
        spaceKey.press();
    }
}
 
Example 9
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
    if (key == KeyEvent.VK_SPACE) {
        firePressed = false;
    }
}
 
Example 10
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
    if (key == KeyEvent.VK_SPACE) {
        firePressed = false;
    }
}
 
Example 11
Source File: CalendarGridPanel.java    From microba with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
	if (!isEnabled())
		return;
	int id = getFocusedIndex();
	int row = id / 7;
	int col = id % 7;
	if (e.getKeyCode() == KeyEvent.VK_DOWN) {
		row++;
		if (row < 6) {
			setFocusedByIndex(row * 7 + col);
		}
	}
	if (e.getKeyCode() == KeyEvent.VK_UP) {
		row--;
		if (row >= 0) {
			setFocusedByIndex(row * 7 + col);
		}
	}
	if (e.getKeyCode() == KeyEvent.VK_LEFT) {
		col--;
		if (col >= 0) {
			setFocusedByIndex(row * 7 + col);
		}
	}
	if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
		col++;
		if (col < 7) {
			setFocusedByIndex(row * 7 + col);
		}
	}
}
 
Example 12
Source File: Tools.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks a given keyCode-value, usually passed from the
 * {@code KeyEvent-getKeyCode()}-method, and checks whether it is a
 * "navigation" key like arrows, page up/down, home etc.
 *
 * @param keyCode the keycode of the pressed or releases key
 * @return {@code true} if it is a navigation key, false otherwise.
 */
public static boolean isNavigationKey(int keyCode) {
    return (KeyEvent.VK_HOME == keyCode
            || KeyEvent.VK_END == keyCode
            || KeyEvent.VK_UP == keyCode
            || KeyEvent.VK_DOWN == keyCode
            || KeyEvent.VK_LEFT == keyCode
            || KeyEvent.VK_RIGHT == keyCode);
}
 
Example 13
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
    if (key == KeyEvent.VK_UP) {
        upPressed = false;
    }
}
 
Example 14
Source File: ImageCommand.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public int getKeyEvent(String key) {
    switch (key.toUpperCase()) {
        case "TAB":
            return KeyEvent.VK_TAB;
        case "ENTER":
            return KeyEvent.VK_ENTER;
        case "SHIFT":
            return KeyEvent.VK_SHIFT;
        case "CTRL":
            return KeyEvent.VK_CONTROL;
        case "ALT":
            return KeyEvent.VK_ALT;
        case "START":
            return KeyEvent.VK_WINDOWS;
        case "DELETE":
            return KeyEvent.VK_DELETE;
        case "BACKSPACE":
            return KeyEvent.VK_BACK_SPACE;
        case "HOME":
            return KeyEvent.VK_HOME;
        case "PAGE_UP":
        case "PAGEUP":
            return KeyEvent.VK_PAGE_UP;
        case "PAGE_DOWN":
        case "PAGEDOWN":
            return KeyEvent.VK_PAGE_DOWN;
        case "UP":
            return KeyEvent.VK_UP;
        case "DOWN":
            return KeyEvent.VK_DOWN;
        case "LEFT":
            return KeyEvent.VK_LEFT;
        case "RIGHT":
            return KeyEvent.VK_RIGHT;
        default:
            return KeyEvent.VK_ESCAPE;
    }
}
 
Example 15
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = true;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = true;
    }
    if (key == KeyEvent.VK_SPACE) {
        firePressed = true;
    }
}
 
Example 16
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
}
 
Example 17
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void onNonConsumedKeyEvent(@Nonnull final MindMapPanel source, @Nonnull final KeyEvent e, @Nonnull final KeyEventType type) {
  if (type == KeyEventType.PRESSED) {
    if (e.getModifiers() == 0) {
      switch (e.getKeyCode()) {
        case KeyEvent.VK_UP:
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_DOWN: {
          e.consume();
        }
        break;
      }
    }
  }

  boolean activated = false;
  final ShortcutSet findAtMindMap = getFindAtMindMapShortcutSet();
  if (findAtMindMap != null) {
    final KeyStroke eventStroke = KeyStroke.getKeyStrokeForEvent(e);
    for (final Shortcut c : findAtMindMap.getShortcuts()) {
      if (c instanceof KeyboardShortcut) {
        final KeyboardShortcut keyboardShortcut = (KeyboardShortcut) c;
        final KeyStroke firstKeyStroke = keyboardShortcut.getFirstKeyStroke();
        final KeyStroke secondKeyStroke = keyboardShortcut.getSecondKeyStroke();

        if (firstKeyStroke != null && firstKeyStroke.getModifiers() == eventStroke.getModifiers() && firstKeyStroke.getKeyCode() == eventStroke.getKeyCode() && firstKeyStroke.getKeyChar() == eventStroke.getKeyChar()) {
          activated = true;
          break;
        }
        if (secondKeyStroke != null && secondKeyStroke.getModifiers() == eventStroke.getModifiers() && secondKeyStroke.getKeyCode() == eventStroke.getKeyCode() && secondKeyStroke.getKeyChar() == eventStroke.getKeyChar()) {
          activated = true;
          break;
        }
      }
    }
  }

  if (activated) {
    e.consume();
    activateTextSearchPanel();
  }

  if (!e.isConsumed() && e.getModifiers() == 0 && e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        findTextPanel.deactivate();
      }
    });
  }
}
 
Example 18
Source File: CodePointInputMethod.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This is the input method's main routine.  The composed text is stored
 * in buffer.
 */
public void dispatchEvent(AWTEvent event) {
    // This input method handles KeyEvent only.
    if (!(event instanceof KeyEvent)) {
        return;
    }

    KeyEvent e = (KeyEvent) event;
    int eventID = event.getID();
    boolean notInCompositionMode = buffer.length() == 0;

    if (eventID == KeyEvent.KEY_PRESSED) {
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }

        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                moveCaretLeft();
                break;
            case KeyEvent.VK_RIGHT:
                moveCaretRight();
                break;
        }
    } else if (eventID == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();

        // If we are not in composition mode, wait a back slash
        if (notInCompositionMode) {
            // If the type character is not a back slash, pass through
            if (c != '\\') {
                return;
            }

            startComposition();     // Enter to composition mode
        } else {
            switch (c) {
                case ' ':       // Exit from composition mode
                    finishComposition();
                    break;
                case '\u007f':  // Delete
                    deleteCharacter();
                    break;
                case '\b':      // BackSpace
                    deletePreviousCharacter();
                    break;
                case '\u001b':  // Escape
                    cancelComposition();
                    break;
                case '\n':      // Return
                case '\t':      // Tab
                    sendCommittedText();
                    break;
                default:
                    composeUnicodeEscape(c);
                    break;
            }
        }
    } else {  // KeyEvent.KEY_RELEASED
        // If we are not in composition mode, pass through
        if (notInCompositionMode) {
            return;
        }
    }

    e.consume();
}
 
Example 19
Source File: ActiveBagContentPreviewPanel.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public boolean processKey(KeyEvent e) {
  boolean consumed = false;
  if (cgrid >= 0 && grid[cgrid] != null && tgc[cgrid] != null) {
    int dx = 0, dy = 0;
    boolean delete = false, moveFirst = false;
    Point cur = grid[cgrid].getCursor();
    char ch1 = 0;

    switch (e.getID()) {
    case KeyEvent.KEY_PRESSED:
      switch (e.getKeyCode()) {
      case KeyEvent.VK_RIGHT:
        dx = 1;
        break;
      case KeyEvent.VK_LEFT:
        dx = -1;
        break;
      case KeyEvent.VK_DOWN:
        dy = 1;
        break;
      case KeyEvent.VK_UP:
        dy = -1;
        break;
      case KeyEvent.VK_BACK_SPACE:
        dx = -1;
        delete = true;
        moveFirst = true;
        break;
      case KeyEvent.VK_DELETE:
        delete = true;
        break;
      }
      break;

    case KeyEvent.KEY_TYPED:
      char ch0 = e.getKeyChar();
      int kk = e.getKeyCode();
      if (cur != null) {
        dx = 1;
        if (Character.isLetterOrDigit(ch0))
          ch1 = Character.toUpperCase(ch0);
        else if (ch0 == tgc[cgrid].wild || Character.isSpaceChar(ch0))
          delete = true;
        else
          dx = 0;
      }
      break;
    }
    if (moveFirst && (dx != 0 || dy != 0)) {
      moveCursor(dx, dy);
      cur = grid[cgrid].getCursor();
      consumed = true;
    }
    if (delete)
      ch1 = tgc[cgrid].wild;
    if (ch1 != 0 && cur != null) {
      if (crossWord) {
        checkWildChanges(cur, ch1);
      }
      grid[cgrid].setCharAt(cur.x, cur.y, ch1);
      tgc[cgrid].setCharAt(cur.x, cur.y, ch1);
      setModified(true);
      consumed = true;
    }
    if (!moveFirst && (dx != 0 || dy != 0)) {
      moveCursor(dx, dy);
      consumed = true;
    }
  }
  return consumed;
}
 
Example 20
Source File: TimeUI.java    From whyline with MIT License 4 votes vote down vote up
public boolean handleKeyPressed(KeyEvent e) {

			if(breakpointDebuggerIsRunning()) return false;
			
			Trace trace = whylineUI.getTrace();
			
			// Get the io event before the current one.
			if(e.getKeyCode() == KeyEvent.VK_LEFT) {
				
				// Get event before current 
				IOEvent ioEvent = whylineUI.getTrace().getIOHistory().getMostRecentBeforeTime(whylineUI.getInputEventID() - 1);
				setInputOutputTimes(determineSelectableIOEventAtOrBefore(ioEvent));
				return true;
				
			}
			// Get the io event after the current one.
			else if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
				
				setInputOutputTimes(determineSelectableIOEventAfter(whylineUI.getEventAtInputTime()));
				return true;

			}
			else return false;
			
		}