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

The following examples show how to use java.awt.event.KeyEvent#VK_W . 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: Search.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
private void tryCloseTab(KeyEvent ke) {
	switch (ke.getKeyCode()) {
	case KeyEvent.VK_W:
		if (!ke.isControlDown())
			return;
		int ntabs = search_tabs.getTabCount();
		if (0 == ntabs) {
			instance.destroy();
			return;
		}
		search_tabs.remove(search_tabs.getSelectedIndex());
		return;
	default:
		return;
	}
}
 
Example 2
Source File: DefaultInteractionEventHandler.java    From constellation with Apache License 2.0 6 votes vote down vote up
/**
 * Respond to a key press event on the graph. This will respond to keys that
 * interact directly with the graph's visuals, such as W,A,S,D to pan. Most
 * key presses in CONSTELLATION, for example Ctrl+A, will be picked up by
 * the netbeans framework and cause plugins to be executed.
 * <p>
 * This is called continually whenever a key is held down (at the key repeat
 * rate of the operating system).
 *
 * @param event The KeyEvent related to the key press.
 */
@Override
public void keyPressed(final KeyEvent event) {
    final int keyCode = event.getKeyCode();
    // Avoid the control key so we don't interfere with ^S for save, for example.
    final boolean isCtrl = event.isControlDown();
    final boolean isShift = event.isShiftDown();
    if (keyCode == KeyEvent.VK_PAGE_UP || keyCode == KeyEvent.VK_PAGE_DOWN || (!isCtrl
            && (keyCode == KeyEvent.VK_A || keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_S || keyCode == KeyEvent.VK_W))) {
        queue.add(wg -> {
            if (wg != null) {
                final Camera camera = new Camera(VisualGraphUtilities.getCamera(wg));
                if (keyCode == KeyEvent.VK_PAGE_UP) {
                    CameraUtilities.changeMixRatio(camera, true, isCtrl);
                    eventState.addEventName(MIX_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_PAGE_DOWN) {
                    CameraUtilities.changeMixRatio(camera, false, isCtrl);
                    eventState.addEventName(MIX_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_A) {
                    CameraUtilities.pan(camera, -0.5f * (isShift ? 10 : 1), 0);
                    eventState.addEventName(PAN_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_D) {
                    CameraUtilities.pan(camera, 0.5f * (isShift ? 10 : 1), 0);
                    eventState.addEventName(PAN_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_S) {
                    CameraUtilities.pan(camera, 0, -0.5f * (isShift ? 10 : 1));
                    eventState.addEventName(PAN_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_W) {
                    CameraUtilities.pan(camera, 0, 0.5f * (isShift ? 10 : 1));
                    eventState.addEventName(PAN_ACTION_NAME);
                }
                VisualGraphUtilities.setCamera(wg, camera);
                scheduleCameraChangeOperation();
            }
            return STANDARD_DELAY;
        });
    }
}
 
Example 3
Source File: Block.java    From JavaGame with MIT License 6 votes vote down vote up
/**
 * ���̰����¼�
 * 
 * @param e
 */
public void keyPressed(KeyEvent e) {
	switch (e.getKeyCode()) {
	case KeyEvent.VK_UP:
	case KeyEvent.VK_W:
		rotate = true;
		down = left = right = false;
		break;
	case KeyEvent.VK_DOWN:
	case KeyEvent.VK_S:
		down = true;
		rotate = left = right = false;
		break;
	case KeyEvent.VK_LEFT:
	case KeyEvent.VK_A:
		left = true;
		rotate = right = down = false;
		break;
	case KeyEvent.VK_RIGHT:
	case KeyEvent.VK_D:
		right = true;
		rotate = left = down = false;
		break;
	}
}
 
Example 4
Source File: Plane.java    From JavaGame with MIT License 6 votes vote down vote up
/**
 * �ɿ����̵ķ���
 * 
 * @param e
 *            �����¼�
 */
public void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
	case KeyEvent.VK_A:
		left = false;
		break;
	case KeyEvent.VK_S:
		down = false;
		break;
	case KeyEvent.VK_D:
		right = false;
		break;
	case KeyEvent.VK_W:
		up = false;
		break;
	case KeyEvent.VK_J:// ���ӵ�
		fire = false;
		break;
	}
}
 
Example 5
Source File: Plane.java    From JavaGame with MIT License 6 votes vote down vote up
/**
 * �ɿ����̵ķ���
 * 
 * @param e
 *            �����¼�
 */
public void keyReleased(KeyEvent e) {
	switch (e.getKeyCode()) {
	case KeyEvent.VK_A:
		left = false;
		break;
	case KeyEvent.VK_S:
		down = false;
		break;
	case KeyEvent.VK_D:
		right = false;
		break;
	case KeyEvent.VK_W:
		up = false;
		break;
	case KeyEvent.VK_J:// ���ӵ�
		fire = false;
		break;
	}
}
 
Example 6
Source File: KeyManager.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
public void tick(){
	for(int i = 0;i < keys.length;i++){
		if(cantPress[i] && !keys[i]){
			cantPress[i] = false;
		}else if(justPressed[i]){
			cantPress[i] = true;
			justPressed[i] = false;
		}
		if(!cantPress[i] && keys[i]){
			justPressed[i] = true;
		}
	}
	
	up = keys[KeyEvent.VK_W];
	down = keys[KeyEvent.VK_S];
	left = keys[KeyEvent.VK_A];
	right = keys[KeyEvent.VK_D];
	
	aUp = keys[KeyEvent.VK_UP];
	aDown = keys[KeyEvent.VK_DOWN];
	aLeft = keys[KeyEvent.VK_LEFT];
	aRight = keys[KeyEvent.VK_RIGHT];
}
 
Example 7
Source File: KeyManager.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
public void tick(){
	for(int i = 0;i < keys.length;i++){
		if(cantPress[i] && !keys[i]){
			cantPress[i] = false;
		}else if(justPressed[i]){
			cantPress[i] = true;
			justPressed[i] = false;
		}
		if(!cantPress[i] && keys[i]){
			justPressed[i] = true;
		}
	}
	
	up = keys[KeyEvent.VK_W];
	down = keys[KeyEvent.VK_S];
	left = keys[KeyEvent.VK_A];
	right = keys[KeyEvent.VK_D];
	
	aUp = keys[KeyEvent.VK_UP];
	aDown = keys[KeyEvent.VK_DOWN];
	aLeft = keys[KeyEvent.VK_LEFT];
	aRight = keys[KeyEvent.VK_RIGHT];
}
 
Example 8
Source File: GUILabelingTool.java    From Pixie with MIT License 5 votes vote down vote up
/**
 * Handling of keyboard events when Alt key is pressed.
 *
 * @param key the key code
 */
private void handleAltKey(int key) {
    switch (key) {
        case KeyEvent.VK_A:
            // increase left
            gc.changeSizeSelection(-1, 0, 0, 0);
            break;

        case KeyEvent.VK_W:
            // increase top
            gc.changeSizeSelection(0, -1, 0, 0);
            break;

        case KeyEvent.VK_D:
            // increase right
            gc.changeSizeSelection(0, 0, 1, 0);
            break;

        case KeyEvent.VK_S:
            // increase bottom
            gc.changeSizeSelection(0, 0, 0, 1);
            break;

        case KeyEvent.VK_Z:
            // decrease box
            gc.changeSizeSelection(1, 1, -1, -1);
            break;

        case KeyEvent.VK_X:
            // increase box
            gc.changeSizeSelection(-1, -1, 1, 1);
            break;

        default:
            // do nothing
            break;
    }
}
 
Example 9
Source File: BlockLoader.java    From JavaGame with MIT License 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
	if (!isPressed) {
		int direction = e.getKeyCode();
		switch (direction) {
		case KeyEvent.VK_UP:
		case KeyEvent.VK_W:
			direction = Block.DIRECTION_UP;
			isPressed = true;
			break;
		case KeyEvent.VK_DOWN:
		case KeyEvent.VK_S:
			direction = Block.DIRECTION_DOWN;
			isPressed = true;
			break;
		case KeyEvent.VK_LEFT:
		case KeyEvent.VK_A:
			direction = Block.DIRECTION_LEFT;
			isPressed = true;
			break;
		case KeyEvent.VK_RIGHT:
		case KeyEvent.VK_D:
			direction = Block.DIRECTION_RIGHT;
			isPressed = true;
			break;
		default:
			direction = -1;
			break;
		}
		if (isPressed) {
			for (Block block : blockList) {
				block.keyPressed(direction);
			}
		}
	}
	// newBlock();
}
 
Example 10
Source File: NativeDisplayKeyListener.java    From salty-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(final KeyEvent e) {

    if (keyboardHandler != null) {
        keyboardHandler.keyPressed(e);
    }

    currentKey = e.getKeyChar();

    if (e.getKeyCode() == KeyEvent.VK_W || e.getKeyCode() == KeyEvent.VK_UP) {

        inputUp = true;
    }
    if (e.getKeyCode() == KeyEvent.VK_S || e.getKeyCode() == KeyEvent.VK_DOWN) {

        inputDown = true;
    }
    if (e.getKeyCode() == KeyEvent.VK_A || e.getKeyCode() == KeyEvent.VK_LEFT) {

        inputLeft = true;
    }
    if (e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_RIGHT) {

        inputRight = true;
    }

    if (SceneManager.getCurrentScene().getUI() != null) {
        SceneManager.getCurrentScene().getUI().keyPressed(e);
    }

    Input.keyboardInput.handleKeyPressed(e);
    updateInputStates();
    Input.lastInput = e;
    Input.getKeyboardHandlers().forEach(keyboardInputHandler -> keyboardInputHandler.keyPressed(e));
}
 
Example 11
Source File: BoundingBoxWindow.java    From Pixie with MIT License 5 votes vote down vote up
/**
 * Handle the keyboard events when Alt key is pressed.
 *
 * @param key the key code
 */
private void handleAltKey(int key) {
    switch (key) {
        case KeyEvent.VK_A:
            // increase left
            changeSize(-1, 0, 0, 0);
            break;

        case KeyEvent.VK_W:
            // increase top
            changeSize(0, -1, 0, 0);
            break;

        case KeyEvent.VK_D:
            // increase right
            changeSize(0, 0, 1, 0);
            break;

        case KeyEvent.VK_S:
            // increase bottom
            changeSize(0, 0, 0, 1);
            break;

        case KeyEvent.VK_Z:
            // decrease box
            changeSize(1, 1, -1, -1);
            break;

        case KeyEvent.VK_X:
            // increase box
            changeSize(-1, -1, 1, 1);
            break;

        default:
            // do nothing
            break;
    }
}
 
Example 12
Source File: GUILabelingTool.java    From Pixie with MIT License 4 votes vote down vote up
/**
 * Handling of the keyboard events.
 *
 * @param key the key code
 */
private void handleNormalKey(int key) {
    switch (key) {
        case KeyEvent.VK_LEFT:
            if (!jTFJumpFrame.isFocusOwner()) {
                getFrame(Constants.PREV_FRAME);
            }
            break;

        case KeyEvent.VK_RIGHT:
            if (!jTFJumpFrame.isFocusOwner()) {
                // get the next frame; save the data and load other data if there exists any
                getFrame(Constants.NEXT_FRAME);
            }
            break;

        case KeyEvent.VK_A:
            // move the crop to the left                            
            gc.moveSelection(-1, 0);
            break;

        case KeyEvent.VK_D:
            // move the crop to the right
            gc.moveSelection(1, 0);
            break;

        case KeyEvent.VK_W:
            // move the crop up
            gc.moveSelection(0, -1);
            break;

        case KeyEvent.VK_S:
            // move the crop down
            gc.moveSelection(0, 1);
            break;

        case KeyEvent.VK_DELETE:
            gc.removeSelection();
            break;

        case KeyEvent.VK_ESCAPE:
            cancelCurrentObject();
            break;

        default:
            // do nothing
            break;
    }
}
 
Example 13
Source File: KeyManager.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public void tick(){
	up = keys[KeyEvent.VK_W];
	down = keys[KeyEvent.VK_S];
	left = keys[KeyEvent.VK_A];
	right = keys[KeyEvent.VK_D];
}
 
Example 14
Source File: InputHandler.java    From JavaGame with GNU Affero General Public License v3.0 4 votes vote down vote up
private void toggleKey(int keyCode, boolean isPressed) {
	if (!isIgnoreInput()) {
		if (keyCode == KeyEvent.VK_Z && isAzertyCountry || keyCode == KeyEvent.VK_W && !isAzertyCountry
				|| keyCode == KeyEvent.VK_UP) {
			up.toggle(isPressed);
		}

		if (keyCode == KeyEvent.VK_Q && isAzertyCountry || keyCode == KeyEvent.VK_A && !isAzertyCountry
				|| keyCode == KeyEvent.VK_LEFT) {
			left.toggle(isPressed);
		}

		if (keyCode == KeyEvent.VK_S || keyCode == KeyEvent.VK_DOWN) {
			down.toggle(isPressed);
		}

		if (keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_RIGHT) {
			right.toggle(isPressed);
		}
	}
	if (isIgnoreInput()) {
		up.toggle(false);
		down.toggle(false);
		left.toggle(false);
		right.toggle(false);
	}

	if (keyCode == KeyEvent.VK_M) {
		if(!toggleMusic){
			Game.getBackgroundMusic().play();
			print.print("Playing Music", PrintTypes.MUSIC);
			toggleMusic = true;
		}
	}

	if (keyCode == KeyEvent.VK_COMMA) {
		Game.getBackgroundMusic().stop();
		if(toggleMusic)
			print.print("Stopping Music", PrintTypes.MUSIC);
			toggleMusic = false;
	}


	if (keyCode == KeyEvent.VK_W && isAzertyCountry || keyCode == KeyEvent.VK_Z && !isAzertyCountry) {
		// if (map == 0){
		// Game.getGame().setMap("/levels/water_level.png");
		// map++;
		// } else{
		// Game.getGame().setMap("/levels/custom_level.png");
		// map--;
		// }
		if (Game.getMap() == 2) {
			if (Game.isNpc()) {
				Game.setNpc(false);
			}
			Game.setChangeLevel(true);
		}
	}
	if (keyCode == KeyEvent.VK_N) {
		if (Game.getPlayer().isMoving()) {
			setIgnoreInput(true);
			int n = popup.Warn("Stop moving before spawning dummy AI");
			if (n == 0) {
				setIgnoreInput(false);
			}
			return;
		}
		if (!Game.isNpc()) {
			Game.setNpc(true);
			Game.npcSpawn();
			print.print("Dummy has been spawned", PrintTypes.GAME);
		}
	}
	if (keyCode == KeyEvent.VK_K) {
		if (Game.isNpc()) {
			Game.setNpc(false);
			Game.npcKill();
			print.print("Dummy has been removed", PrintTypes.GAME);
		}
	}

	if (keyCode == KeyEvent.VK_A && isAzertyCountry || keyCode == KeyEvent.VK_Q && !isAzertyCountry)
		this.quitGame();

	if (keyCode == KeyEvent.VK_BACK_QUOTE) {
		if (!Game.isClosing() && !Game.isDevMode()) {
			Game.setDevMode(true);
			new Thread(new SleepThread());
		}
	}
}
 
Example 15
Source File: KeyManager.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public void tick(){
	up = keys[KeyEvent.VK_W];
	down = keys[KeyEvent.VK_S];
	left = keys[KeyEvent.VK_A];
	right = keys[KeyEvent.VK_D];
}
 
Example 16
Source File: KeyManager.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public void tick(){
	up = keys[KeyEvent.VK_W];
	down = keys[KeyEvent.VK_S];
	left = keys[KeyEvent.VK_A];
	right = keys[KeyEvent.VK_D];
}
 
Example 17
Source File: KeyManager.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public void tick(){
	up = keys[KeyEvent.VK_W];
	down = keys[KeyEvent.VK_S];
	left = keys[KeyEvent.VK_A];
	right = keys[KeyEvent.VK_D];
}
 
Example 18
Source File: KeyManager.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public void tick(){
	up = keys[KeyEvent.VK_W];
	down = keys[KeyEvent.VK_S];
	left = keys[KeyEvent.VK_A];
	right = keys[KeyEvent.VK_D];
}
 
Example 19
Source File: DarkColorChooserPanel.java    From darklaf with MIT License 4 votes vote down vote up
@Override
public int getMnemonic() {
    return KeyEvent.VK_W;
}
 
Example 20
Source File: Robot.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 将字符型转换为按键码,可直接使用 {@link #press(int)}调用
 * @param key 字符型文字,包含 0~9 a~z .
 * @return 按键码
 */
public int StringToKey(String key){
	switch (key) {
	case "a":
		return KeyEvent.VK_A;
	case "b":
		return KeyEvent.VK_B;
	case "c":
		return KeyEvent.VK_C;
	case "d":
		return KeyEvent.VK_D;
	case "e":
		return KeyEvent.VK_E;
	case "f":
		return KeyEvent.VK_F;
	case "g":
		return KeyEvent.VK_G;
	case "h":
		return KeyEvent.VK_H;
	case "i":
		return KeyEvent.VK_I;
	case "j":
		return KeyEvent.VK_J;
	case "k":
		return KeyEvent.VK_K;
	case "l":
		return KeyEvent.VK_L;
	case "m":
		return KeyEvent.VK_M;
	case "n":
		return KeyEvent.VK_N;
	case "o":
		return KeyEvent.VK_O;
	case "p":
		return KeyEvent.VK_P;
	case "q":
		return KeyEvent.VK_Q;
	case "r":
		return KeyEvent.VK_R;
	case "s":
		return KeyEvent.VK_S;
	case "t":
		return KeyEvent.VK_T;
	case "u":
		return KeyEvent.VK_U;
	case "v":
		return KeyEvent.VK_V;
	case "w":
		return KeyEvent.VK_W;
	case "x":
		return KeyEvent.VK_X;
	case "y":
		return KeyEvent.VK_Y;
	case "z":
		return KeyEvent.VK_Z;
	case "0":
		return KeyEvent.VK_0;
	case "1":
		return KeyEvent.VK_1;
	case "2":
		return KeyEvent.VK_2;
	case "3":
		return KeyEvent.VK_3;
	case "4":
		return KeyEvent.VK_4;
	case "5":
		return KeyEvent.VK_5;
	case "6":
		return KeyEvent.VK_6;
	case "7":
		return KeyEvent.VK_7;
	case "8":
		return KeyEvent.VK_8;
	case "9":
		return KeyEvent.VK_9;
	case ".":
		return KeyEvent.VK_PERIOD;
	default:
		break;
	}
	
	return 0;
}