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

The following examples show how to use java.awt.event.KeyEvent#VK_WINDOWS . 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: ArcAction.java    From PIPE with MIT License 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {

    switch (e.getKeyCode()) {
        case KeyEvent.VK_META:
        case KeyEvent.VK_WINDOWS:
        case KeyEvent.VK_SPACE:
            tab.setMetaDown(true);
            break;

        case KeyEvent.VK_ESCAPE:
        case KeyEvent.VK_DELETE:
            tab.remove(temporaryArcView);
            tab.repaint();
            temporaryArcView = null;
        default:
            break;
    }
}
 
Example 2
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 3
Source File: KeyEventCodeToString.java    From Repeat with Apache License 2.0 5 votes vote down vote up
/**
 * Convert from code from KeyEvent.VK_* to a human friendly string.
 * This is needed because in some OSes the KeyEvent utility does
 * not work properly.
 */
public static String codeToString(int code) {
	switch (code) {
	case KeyEvent.VK_CONTROL:
		return "Ctrl";
	case KeyEvent.VK_ALT:
		if (OSIdentifier.IS_OSX) {
			return "Option";
		}
		return "Alt";
	case KeyEvent.VK_WINDOWS:
		return "Windows";
	case KeyEvent.VK_META:
		if (OSIdentifier.IS_LINUX) {
			return "Meta";
		}
		if (OSIdentifier.IS_OSX) {
			return "Command";
		}
		break;
	case KeyEvent.VK_SHIFT:
		return "Shift";
	case KeyEvent.VK_TAB:
		return "Tab";
	case KeyEvent.VK_SPACE:
		return "Space";
	}
	return KeyEvent.getKeyText(code);
}
 
Example 4
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 5
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("Duplicates")
protected synchronized void doHandleKeyRelease(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key released: " + e.paramString());

    // Get code of the released 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;

    // Release control keys.
    if (isControlKey) {
        //LOGGER.debug("release key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyRelease(keyCode);
        e.consume();
    }

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

    // Forget, that the Windows key is pressed.
    if (keyCode == KeyEvent.VK_WINDOWS) {
        synchronized (Frame.this) {
            windowsKeyDown = false;
        }
    }
}