import java.awt.AWTException; import java.awt.Robot; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; System.exit(0);import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.lang.reflect.Field; import java.util.StringTokenizer; public class KeyType{ /** * Robot */ // public Robot robot; public KeyType(){ KeySet(""); } /** * 文字列をKeyEventの定数 VK_* に変換する。 * * @param scode コード * @return 変換後のコード */ public void KeySet(String chars){ chars = chars.toUpperCase(); System.out.println("keySet chars=" + chars); for (int i = 0; i < chars.length(); ++i) { int code = convertKeyCode(chars.substring(i, i + 1)); System.out.println("keySet code=" + code); try{ Robot r = new Robot(); r.keyPress(code); r.keyRelease(code); }catch(Exception e){} } } public int convertKeyCode(String scode) { int code = KeyEvent.VK_UNDEFINED; try { scode = scode.trim();//String から先頭、末尾にある空白を削除する Field field = KeyEvent.class.getField("VK_" + scode); code = field.getInt(null); System.out.println("keySet scode=" + scode); } catch (IllegalAccessException iae) { iae.printStackTrace(); } catch (NoSuchFieldException nsfe) { nsfe.printStackTrace(); } catch (SecurityException se) { se.printStackTrace(); } return code; } }