Example usage for java.awt.event KeyEvent getExtendedKeyCodeForChar

List of usage examples for java.awt.event KeyEvent getExtendedKeyCodeForChar

Introduction

In this page you can find the example usage for java.awt.event KeyEvent getExtendedKeyCodeForChar.

Prototype

public static int getExtendedKeyCodeForChar(int c) 

Source Link

Document

Returns an extended key code for a unicode character.

Usage

From source file:KeyboardEmulator.java

public static String type(String s, boolean appendEnter) throws AWTException {
    if (isBlank(s))
        return s;

    String typed = "";
    try {// ww w .j ava 2 s .com
        Robot keyboard = getKeyboard();
        int size = s.length();
        char c;
        for (int i = 0; i < size; i++) {
            c = s.charAt(i);
            int idx = shiftChars.indexOf(c);
            if (idx > -1) {
                char cc = unShiftChars.charAt(idx);
                keyboard.keyPress(Shift);
                keyboard.keyPress(KeyEvent.getExtendedKeyCodeForChar(cc));
                keyboard.keyRelease(KeyEvent.getExtendedKeyCodeForChar(cc));
                keyboard.keyRelease(Shift);
            } else {
                keyboard.keyPress(KeyEvent.getExtendedKeyCodeForChar(c));
                keyboard.keyRelease(KeyEvent.getExtendedKeyCodeForChar(c));
            }
            typed += String.valueOf(c);
        }
        if (appendEnter) {
            keyboard.keyPress(Enter);
            keyboard.keyRelease(Enter);
        }
    } catch (AWTException e) {

    } finally {
        return typed;
    }
}