Created
July 31, 2013 03:54
-
-
Save shivam5992/6119154 to your computer and use it in GitHub Desktop.
Gist for simulating the key presses of keyboard using java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
Robot shaz=new Robot(); | |
shaz.setAutoDelay(100); | |
char ch; | |
int len=0; | |
String text="hello my name is Github"; | |
len=text.length(); | |
for (int i=0;i<len;i++) | |
{ | |
ch = textz.charAt(i); | |
switch(ch) | |
{ | |
case'A':case'a':shaz.keyPress(KeyEvent.VK_A);break; | |
case'b':case'B':shaz.keyPress(KeyEvent.VK_B);break; | |
case'c':case'C':shaz.keyPress(KeyEvent.VK_C);break; | |
case'd':case'D':shaz.keyPress(KeyEvent.VK_D);break; | |
case'e':case'E':shaz.keyPress(KeyEvent.VK_E);break; | |
case'f':case'F':shaz.keyPress(KeyEvent.VK_F);break; | |
case'g':case'G':shaz.keyPress(KeyEvent.VK_G);break; | |
case'h':case'H':shaz.keyPress(KeyEvent.VK_H);break; | |
case'i':case'I':shaz.keyPress(KeyEvent.VK_I);break; | |
case'j':case'J':shaz.keyPress(KeyEvent.VK_J);break; | |
case'k':case'K':shaz.keyPress(KeyEvent.VK_K);break; | |
case'l':case'L':shaz.keyPress(KeyEvent.VK_L);break; | |
case'm':case'M':shaz.keyPress(KeyEvent.VK_M);break; | |
case'n':case'N':shaz.keyPress(KeyEvent.VK_N);break; | |
case'o':case'O':shaz.keyPress(KeyEvent.VK_O);break; | |
case'p':case'P':shaz.keyPress(KeyEvent.VK_P);break; | |
case'q':case'Q':shaz.keyPress(KeyEvent.VK_Q);break; | |
case'r':case'R':shaz.keyPress(KeyEvent.VK_R);break; | |
case's':case'S':shaz.keyPress(KeyEvent.VK_S);break; | |
case't':case'T':shaz.keyPress(KeyEvent.VK_T);break; | |
case'u':case'U':shaz.keyPress(KeyEvent.VK_U);break; | |
case'v':case'V':shaz.keyPress(KeyEvent.VK_V);break; | |
case'w':case'W':shaz.keyPress(KeyEvent.VK_W);break; | |
case'x':case'X':shaz.keyPress(KeyEvent.VK_X);break; | |
case'y':case'Y':shaz.keyPress(KeyEvent.VK_Y);break; | |
case'z':case'Z':shaz.keyPress(KeyEvent.VK_Z);break; | |
case' ':shaz.keyPress(KeyEvent.VK_SPACE);break; | |
case'0':shaz.keyPress(KeyEvent.VK_0);break; | |
case'1':shaz.keyPress(KeyEvent.VK_1);break; | |
case'2':shaz.keyPress(KeyEvent.VK_2);break; | |
case'3':shaz.keyPress(KeyEvent.VK_3);break; | |
case'4':shaz.keyPress(KeyEvent.VK_4);break; | |
case'5':shaz.keyPress(KeyEvent.VK_5);break; | |
case'6':shaz.keyPress(KeyEvent.VK_6);break; | |
case'7':shaz.keyPress(KeyEvent.VK_7);break; | |
case'8':shaz.keyPress(KeyEvent.VK_8);break; | |
case'9':shaz.keyPress(KeyEvent.VK_9);break; | |
default:throw new IllegalArgumentException("exception "+ch);} | |
} | |
shaz.keyPress(KeyEvent.VK_SPACE); | |
} | |
catch(Exception e) | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment