My current set of switch statements work, but they take up far too many lines and I am unsure of how to create a working loop to condense the switch statements.
Here is my current switch statement within a method (I have six, the following are incremented by 1)
public static String convert (String str) {
String strb = new StringBuilder(str);
switch (str.charAt(4)) {
case 'a':
case 'b':
case 'c':
strb.insert(4, 2);
strb.deleteCharAt(5);
break;
case 'd':
case 'e':
case 'f':
strb.insert(4, 3);
strb.deleteCharAt(5);
break;
case 'g':
case 'h':
case 'i':
strb.insert(4, 4);
strb.deleteCharAt(5);
break;
case 'j':
case 'k':
case 'l':
strb.insert(4, 5);
strb.deleteCharAt(5);
break;
case 'm':
case 'n':
case 'o':
strb.insert(4, 6);
strb.deleteCharAt(5);
break;
case 'p':
case 'q':
case 'r':
case 's':
strb.insert(4, 7);
strb.deleteCharAt(5);
break;
case 't':
case 'u':
case 'v':
strb.insert(4, 8);
strb.deleteCharAt(5);
break;
case 'w':
case 'x':
case 'y':
case 'z':
strb.insert(4, 9);
strb.deleteCharAt(5);
break;
}
return strb.toString();
}
I have tried a for loop, but it does not seem to work. Any suggestions?
for (index = 4; index < str.length(); index++) {
switch (str.charAt(index)) {
case 'a':
case 'b':
case 'c':
strb.insert(index, 2);
strb.deleteCharAt(index + 1);
break;
case 'd':
case 'e':
case 'f':
strb.insert(index, 3);
strb.deleteCharAt(index + 1);
break;
case 'g':
case 'h':
case 'i':
strb.insert(index, 4);
strb.deleteCharAt(index + 1);
break;
case 'j':
case 'k':
case 'l':
strb.insert(index, 5);
strb.deleteCharAt(index + 1);
break;
case 'm':
case 'n':
case 'o':
strb.insert(index, 6);
strb.deleteCharAt(index + 1);
break;
case 'p':
case 'q':
case 'r':
case 's':
strb.insert(index, 7);
strb.deleteCharAt(index + 1);
break;
case 't':
case 'u':
case 'v':
strb.insert(index, 8);
strb.deleteCharAt(index + 1);
break;
case 'w':
case 'x':
case 'y':
case 'z':
strb.insert(index, 9);
strb.deleteCharAt(index + 1);
break;
}
}
A better approach is to remove the switch statement altogether, and use a lookup table to select the digit:
private static final String DIGIT_LOOKUP = "22233344455566677778889999";
...
int pos = Character.toLowerCase(str.charAt(index)) - 'a';
char digit = DIGIT_LOOKUP.charAt(pos);
Demo.
Related
I'm creating a code that will output a number based on the input letter. My code is stuck was stuck on a loop of doing character 0 repeatedly. Friend said that char Check = userInput.charAt(numTelephone); would fix it. When I placed that into my code I recieved the error: error: char cannot be dereferenced char Check = userInput.charAt(numTelephone);
import java.util.Scanner;
public class PhoneWords {
public static void main(String []args){
Scanner scnr = new Scanner(System.in);
int numTelephone;
char userInput;
userInput = scnr.next().charAt(0);
System.out.println("Enter a telephone number using letters (EXIT to quit): ");
System.out.println("The corresponding telephone number is: ");
if ((userInput >= 'A') || (userInput <= 'Z') || (userInput >= 'a') || (userInput <= 'z')){
for (numTelephone = 0; numTelephone < 7; numTelephone++){
char Check = userInput.charAt(numTelephone);
if (numTelephone == 3){
System.out.print("-");
}
switch (userInput) {
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
System.out.print("2");
break;
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
System.out.print("3");
break;
case 'G':
case 'g':
case 'H':
case 'h':
case 'I':
case 'i':
System.out.print("4");
break;
case 'J':
case 'j':
case 'K':
case 'k':
case 'L':
case 'l':
System.out.print("5");
break;
case 'M':
case 'm':
case 'N':
case 'n':
case 'O':
case 'o':
System.out.print("6");
break;
case 'P':
case 'p':
case 'Q':
case 'q':
case 'R':
case 'r':
case 'S':
case 's':
System.out.print("7");
break;
case 'T':
case 't':
case 'U':
case 'u':
case 'V':
case 'v':
System.out.print("8");
break;
case 'W':
case 'w':
case 'X':
case 'x':
case 'Y':
case 'y':
case 'Z':
case 'z':
System.out.print("9");
break;
default:
break;
}
}
}
}
}
The type char is primitive -- not an object -- so it cannot be dereferenced
Dereferencing is the process of accessing the value referred to by a reference. Since a char is already a value (not a reference), it can not be dereferenced.
so get the char from the given input like:
char userInput = scnr.nextLine().charAt(0);
And comment this line which is suggested by your friend which is not used any where:
//char Check = userInput.charAt(numTelephone);
So I am writing code that will take a character and return its alpha-numeric keypad equivalent as a character.
The problem is, I am getting a question mark in a box as a return. I have checked that the input is correct. For example, with a char 'h' input, i should get a char '4' return. Hoping someone is able to spot my error.
Code is below:
public char getDigit(char letter) throws Exception{
switch (letter) {
case 'a': case 'b': case 'c': case '2':
return 2;
case 'd': case 'e': case 'f': case '3':
return 3;
case 'g': case 'h': case 'i': case '4':
return 4;
case 'j': case 'k': case 'l': case '5':
return 5;
case 'm': case 'n': case 'o': case '6':
return 6;
case 'p': case 'q': case 'r': case 's': case '7':
return 7;
case 't': case 'u': case 'v': case '8':
return 8;
case 'w': case 'x': case 'y': case 'z': case '9':
return 9;
default:
throw new IllegalArgumentException("Must be a letter or number on the Alpha-Numeric Keypad.");
}
}
The return type of your method is char.
Now take your switch statement. You return char values in the range from 2 to 9. Now look at an ASCII table.
Surprise: these chars are all "unprintable" control characters. Thus your console gives you "?" when you print them!
If you want '4', your code has to return '4', not 4! Or 52, because that entry in the ASCII table represents '4'.
You are not getting proper output because you are using char as a return type of getDigit(..) function. You should use int as a return type instead of char as in switch case you are comparing with characters and returning digit values So replace your code with the following code, this will work:
public int getDigit(char letter) throws Exception{
switch (letter) {
case 'a': case 'b': case 'c': case '2':
return 2;
case 'd': case 'e': case 'f': case '3':
return 3;
case 'g': case 'h': case 'i': case '4':
return 4;
case 'j': case 'k': case 'l': case '5':
return 5;
case 'm': case 'n': case 'o': case '6':
return 6;
case 'p': case 'q': case 'r': case 's': case '7':
return 7;
case 't': case 'u': case 'v': case '8':
return 8;
case 'w': case 'x': case 'y': case 'z': case '9':
return 9;
default:
throw new IllegalArgumentException("Must be a letter or number on the Alpha-Numeric Keypad.");
}
}
Im trying to make an Auto Typer but i cant go above 60'000 milliseconds between each message, is it possible to go above that?
Code:
import java.awt.AWTException;
import java.awt.Robot;
import static java.awt.event.KeyEvent.*;
public class Runnah implements Runnable {
private MainGUI gui;
// A new robot
private Robot robot;
private boolean toggle;
private static boolean enter;
public Runnah(MainGUI c) throws AWTException {
// Creates the Robot
this.robot = new Robot();
// Sets the current GUI
gui = c;
toggle = true;
enter = false;
}
public Runnah(Robot robot) {
this.robot = robot;
}
private void typeNow(int... key) {
typeNow(key, 0, key.length);
}
private void typeNow(int[] key, int offset, int length) {
if (length == 0) {
return;
}
// Presses and releases the key that is passed into typeNow
robot.keyPress(key[offset]);
typeNow(key, offset + 1, length - 1);
robot.keyRelease(key[offset]);
}
// GIANT SWITCH STATEMENT FOR EVERY CHARACTER ON THE KEYBOARD
public void typeThis(char let) {
switch (let) {
case 'a':
typeNow(VK_A);
break;
case 'b':
typeNow(VK_B);
break;
case 'c':
typeNow(VK_C);
break;
case 'd':
typeNow(VK_D);
break;
case 'e':
typeNow(VK_E);
break;
case 'f':
typeNow(VK_F);
break;
case 'g':
typeNow(VK_G);
break;
case 'h':
typeNow(VK_H);
break;
case 'i':
typeNow(VK_I);
break;
case 'j':
typeNow(VK_J);
break;
case 'k':
typeNow(VK_K);
break;
case 'l':
typeNow(VK_L);
break;
case 'm':
typeNow(VK_M);
break;
case 'n':
typeNow(VK_N);
break;
case 'o':
typeNow(VK_O);
break;
case 'p':
typeNow(VK_P);
break;
case 'q':
typeNow(VK_Q);
break;
case 'r':
typeNow(VK_R);
break;
case 's':
typeNow(VK_S);
break;
case 't':
typeNow(VK_T);
break;
case 'u':
typeNow(VK_U);
break;
case 'v':
typeNow(VK_V);
break;
case 'w':
typeNow(VK_W);
break;
case 'x':
typeNow(VK_X);
break;
case 'y':
typeNow(VK_Y);
break;
case 'z':
typeNow(VK_Z);
break;
case 'A':
typeNow(VK_SHIFT, VK_A);
break;
case 'B':
typeNow(VK_SHIFT, VK_B);
break;
case 'C':
typeNow(VK_SHIFT, VK_C);
break;
case 'D':
typeNow(VK_SHIFT, VK_D);
break;
case 'E':
typeNow(VK_SHIFT, VK_E);
break;
case 'F':
typeNow(VK_SHIFT, VK_F);
break;
case 'G':
typeNow(VK_SHIFT, VK_G);
break;
case 'H':
typeNow(VK_SHIFT, VK_H);
break;
case 'I':
typeNow(VK_SHIFT, VK_I);
break;
case 'J':
typeNow(VK_SHIFT, VK_J);
break;
case 'K':
typeNow(VK_SHIFT, VK_K);
break;
case 'L':
typeNow(VK_SHIFT, VK_L);
break;
case 'M':
typeNow(VK_SHIFT, VK_M);
break;
case 'N':
typeNow(VK_SHIFT, VK_N);
break;
case 'O':
typeNow(VK_SHIFT, VK_O);
break;
case 'P':
typeNow(VK_SHIFT, VK_P);
break;
case 'Q':
typeNow(VK_SHIFT, VK_Q);
break;
case 'R':
typeNow(VK_SHIFT, VK_R);
break;
case 'S':
typeNow(VK_SHIFT, VK_S);
break;
case 'T':
typeNow(VK_SHIFT, VK_T);
break;
case 'U':
typeNow(VK_SHIFT, VK_U);
break;
case 'V':
typeNow(VK_SHIFT, VK_V);
break;
case 'W':
typeNow(VK_SHIFT, VK_W);
break;
case 'X':
typeNow(VK_SHIFT, VK_X);
break;
case 'Y':
typeNow(VK_SHIFT, VK_Y);
break;
case 'Z':
typeNow(VK_SHIFT, VK_Z);
break;
case '`':
typeNow(VK_BACK_QUOTE);
break;
case '0':
typeNow(VK_0);
break;
case '1':
typeNow(VK_1);
break;
case '2':
typeNow(VK_2);
break;
case '3':
typeNow(VK_3);
break;
case '4':
typeNow(VK_4);
break;
case '5':
typeNow(VK_5);
break;
case '6':
typeNow(VK_6);
break;
case '7':
typeNow(VK_7);
break;
case '8':
typeNow(VK_8);
break;
case '9':
typeNow(VK_9);
break;
case '-':
typeNow(VK_MINUS);
break;
case '=':
typeNow(VK_EQUALS);
break;
case '~':
typeNow(VK_SHIFT, VK_BACK_QUOTE);
break;
case '!':
typeNow(VK_SHIFT, VK_1);
break;
case '#':
typeNow(VK_SHIFT, VK_2);
break;
case '#':
typeNow(VK_SHIFT, VK_3);
break;
case '$':
typeNow(VK_SHIFT, VK_4);
break;
case '%':
typeNow(VK_SHIFT, VK_5);
break;
case '^':
typeNow(VK_SHIFT, VK_6);
break;
case '&':
typeNow(VK_SHIFT, VK_7);
break;
case '*':
typeNow(VK_SHIFT, VK_8);
break;
case '(':
typeNow(VK_SHIFT, VK_9);
break;
case ')':
typeNow(VK_SHIFT, VK_0);
break;
case '_':
typeNow(VK_SHIFT, VK_MINUS);
break;
case '+':
typeNow(VK_SHIFT, VK_EQUALS);
break;
case '\t':
typeNow(VK_TAB);
break;
case '\n':
typeNow(VK_ENTER);
break;
case '[':
typeNow(VK_OPEN_BRACKET);
break;
case ']':
typeNow(VK_CLOSE_BRACKET);
break;
case '\\':
typeNow(VK_BACK_SLASH);
break;
case '{':
typeNow(VK_SHIFT, VK_OPEN_BRACKET);
break;
case '}':
typeNow(VK_SHIFT, VK_CLOSE_BRACKET);
break;
case '|':
typeNow(VK_SHIFT, VK_BACK_SLASH);
break;
case ';':
typeNow(VK_SEMICOLON);
break;
case ':':
typeNow(VK_SHIFT, VK_SEMICOLON);
break;
case '\'':
typeNow(VK_QUOTE);
break;
case '"':
typeNow(VK_SHIFT, VK_QUOTE);
break;
case ',':
typeNow(VK_COMMA);
break;
case '<':
typeNow(VK_SHIFT, VK_COMMA);
break;
case '.':
typeNow(VK_PERIOD);
break;
case '>':
typeNow(VK_SHIFT, VK_PERIOD);
break;
case '/':
typeNow(VK_SLASH);
break;
case '?':
typeNow(VK_SHIFT, VK_SLASH);
break;
case ' ':
typeNow(VK_SPACE);
break;
default:
throw new IllegalArgumentException("Derp! That chatacter doesn't work " + let);
}
}
public void setToggle() {
toggle = false;
}
// Enables/Disables the enter key
public void setEnter(boolean a) {
enter = a;
}
#Override
public void run() {
int seconds = 1;
// Get the input from the textField in the GUI
String temp = gui.getInput();
// Turns it into an array of chars
char[] test = new char[temp.length()];
for (int i = 0; i < temp.length(); i++) {
test[i] = temp.charAt(i);
}
// Sets the seconds to the entered seconds * 1000
// Becase .delay() runs in Milliseconds
try {
seconds = gui.getSeconds() * 1000;
} catch (Exception e) {
}
while (!Thread.currentThread().isInterrupted()) {
robot.delay(seconds);
for (int i = 0; i < temp.length(); i++) {
typeThis(test[i]);
}
if (enter) {
typeNow(VK_ENTER);
}
}
toggle = true;
}
}
Fixed.
Original Version :
try {
seconds = gui.getSeconds() * 1000;
} catch (Exception e) {
}
while (!Thread.currentThread().isInterrupted()) {
robot.delay(seconds);
for (int i = 0; i < temp.length(); i++) {
typeThis(test[i]);
}
if (enter) {
typeNow(VK_ENTER);
}
}
Fixed Version :
try {
seconds = gui.getSeconds() * 1000;
} catch (Exception e) {
}
System.out.print(seconds);
while (!Thread.currentThread().isInterrupted()) {
if (seconds <= 60000) {
robot.delay(seconds);
} else {
try {
int newTime = seconds - 60000;
robot.delay(60000);
Thread.sleep(newTime);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for (int i = 0; i < temp.length(); i++) {
typeThis(test[i]);
}
if (enter) {
typeNow(VK_ENTER);
}
}
Allows you to go above 60'000 ms delay.
import java.util.Scanner;
public class ConvertLetterToNumber {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter one letter");
String str = input.next();
char ch = str.charAt(0);
switch (ch){
case 'A': case 'a': case 'B': case 'b': case 'C': case 'c':
System.out.println("the number is 2");
break;
case 'D': case 'd': case 'E': case 'e': case 'F': case 'f':
System.out.println("the number is 3");
break;
case 'G': case 'g': case 'H': case 'h': case 'I': case 'i':
System.out.println("the number is 4");
break;
case 'J': case 'j': case 'K': case 'k': case 'L': case 'l':
System.out.println("the number is 5");
break;
case 'M': case 'm': case 'N': case 'n': case 'O': case 'o':
System.out.println("the number is 6");
break;
case 'P':case 'p': case 'Q': case 'q': case 'R': case 'r': case 'S': case's':
System.out.println("the number is 7");
break;
case 'T':case 't':case 'U':case'u':case'V':case 'v':
System.out.println("the number is 8");
break;
case 'W':case 'w':case 'X': case 'x': case 'Y':case'y':case 'Z':case 'z':
System.out.println("the number is 9");
break;
default :System.out.println("Error:invalid input");
System.exit(1);
}
}
}
the problem is if I enter two or more letters at one time (for example "ab" the answer will be "2", but what I want is "Invalid input". How can I add this instruction to ask user to enter only one letter?
You could check the str length before your switch, and return like so:
if (str.length > 1){
return;
}
I want to autologin to any desktop application like Lotus, Outlook, or any other applications (who needs user authentication) using Java.
Let say I want to auto login to desktop Skype app using Java program i.e we will open skype.exe & will provide authentication details(username, password) as parameters.
While searching, I got to know we have a Robot API , so I was trying with it in below way.
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;
public class RobotExp {
Robot robot = new Robot();
public static void main(String[] args) {
try {
// Process process = new ProcessBuilder(
// "C:\\Windows\\System32\\notepad.exe").start();//C:\SmartClientCache\Apps\Ellie
// Mae\Encompass
Process process = new ProcessBuilder(
"C:\\Program Files (x86)\\Skype\\Phone\\Skype.exe").start();
new RobotExp();
} catch (Exception e) {
// TODO: handle exception
}
}
public RobotExp() throws AWTException {
robot.delay(1200);
// robot.keyPress(KeyEvent.VK_TAB);
// robot.delay(200);
type("testaccess");
// robot.setAutoDelay(40);
// robot.setAutoWaitForIdle(true);
//
// robot.delay(4000);
// robot.mouseMove(40, 130);
// robot.delay(500);
//
robot.keyPress(KeyEvent.VK_TAB);
type("test#1234");
// robot.delay(200);
robot.keyPress(KeyEvent.VK_ENTER);
// type("wish is your");
// robot.delay(500);
// leftClick();
//
// robot.delay(500);
// type("Hello, world");
//
// robot.mouseMove(40, 160);
// robot.delay(500);
//
// leftClick();
// robot.delay(500);
// leftClick();
//
// robot.delay(500);
// type("This is a test of the Java Robot class");
//
// robot.delay(50);
// type(KeyEvent.VK_DOWN);
//
// robot.delay(250);
// type("Four score and seven years ago, our fathers ...");
//
// robot.delay(1000);
System.exit(0);
}
// private void leftClick() {
// robot.mousePress(InputEvent.BUTTON1_MASK);
// robot.delay(200);
// robot.mouseRelease(InputEvent.BUTTON1_MASK);
// robot.delay(200);
// }
// private void rightClick() {
// robot.mousePress(InputEvent.BUTTON2_MASK);
// robot.delay(200);
// robot.mouseRelease(InputEvent.BUTTON2_MASK);
// robot.delay(200);
// }
// private void type(int i) {
// robot.delay(40);
// robot.keyPress(i);
// robot.keyRelease(i);
// }
// private void type(String s) {
// byte[] bytes = s.getBytes();
// for (byte b : bytes) {
// int code = b;
// // keycode only handles [A-Z] (which is ASCII decimal [65-90])
// if (code > 96 && code < 123)
// code = code - 32;
// robot.delay(40);
// robot.keyPress(code);
// robot.keyRelease(code);
// }
// }
public void type(CharSequence characters) {
int length = characters.length();
for (int i = 0; i < length; i++) {
char character = characters.charAt(i);
type(character);
}
}
public void type(char character) {
switch (character) {
case 'a':
doType(VK_A);
break;
case 'b':
doType(VK_B);
break;
case 'c':
doType(VK_C);
break;
case 'd':
doType(VK_D);
break;
case 'e':
doType(VK_E);
break;
case 'f':
doType(VK_F);
break;
case 'g':
doType(VK_G);
break;
case 'h':
doType(VK_H);
break;
case 'i':
doType(VK_I);
break;
case 'j':
doType(VK_J);
break;
case 'k':
doType(VK_K);
break;
case 'l':
doType(VK_L);
break;
case 'm':
doType(VK_M);
break;
case 'n':
doType(VK_N);
break;
case 'o':
doType(VK_O);
break;
case 'p':
doType(VK_P);
break;
case 'q':
doType(VK_Q);
break;
case 'r':
doType(VK_R);
break;
case 's':
doType(VK_S);
break;
case 't':
doType(VK_T);
break;
case 'u':
doType(VK_U);
break;
case 'v':
doType(VK_V);
break;
case 'w':
doType(VK_W);
break;
case 'x':
doType(VK_X);
break;
case 'y':
doType(VK_Y);
break;
case 'z':
doType(VK_Z);
break;
case 'A':
doType(VK_SHIFT, VK_A);
break;
case 'B':
doType(VK_SHIFT, VK_B);
break;
case 'C':
doType(VK_SHIFT, VK_C);
break;
case 'D':
doType(VK_SHIFT, VK_D);
break;
case 'E':
doType(VK_SHIFT, VK_E);
break;
case 'F':
doType(VK_SHIFT, VK_F);
break;
case 'G':
doType(VK_SHIFT, VK_G);
break;
case 'H':
doType(VK_SHIFT, VK_H);
break;
case 'I':
doType(VK_SHIFT, VK_I);
break;
case 'J':
doType(VK_SHIFT, VK_J);
break;
case 'K':
doType(VK_SHIFT, VK_K);
break;
case 'L':
doType(VK_SHIFT, VK_L);
break;
case 'M':
doType(VK_SHIFT, VK_M);
break;
case 'N':
doType(VK_SHIFT, VK_N);
break;
case 'O':
doType(VK_SHIFT, VK_O);
break;
case 'P':
doType(VK_SHIFT, VK_P);
break;
case 'Q':
doType(VK_SHIFT, VK_Q);
break;
case 'R':
doType(VK_SHIFT, VK_R);
break;
case 'S':
doType(VK_SHIFT, VK_S);
break;
case 'T':
doType(VK_SHIFT, VK_T);
break;
case 'U':
doType(VK_SHIFT, VK_U);
break;
case 'V':
doType(VK_SHIFT, VK_V);
break;
case 'W':
doType(VK_SHIFT, VK_W);
break;
case 'X':
doType(VK_SHIFT, VK_X);
break;
case 'Y':
doType(VK_SHIFT, VK_Y);
break;
case 'Z':
doType(VK_SHIFT, VK_Z);
break;
case '`':
doType(VK_BACK_QUOTE);
break;
case '0':
doType(VK_0);
break;
case '1':
doType(VK_1);
break;
case '2':
doType(VK_2);
break;
case '3':
doType(VK_3);
break;
case '4':
doType(VK_4);
break;
case '5':
doType(VK_5);
break;
case '6':
doType(VK_6);
break;
case '7':
doType(VK_7);
break;
case '8':
doType(VK_8);
break;
case '9':
doType(VK_9);
break;
case '-':
doType(VK_MINUS);
break;
case '=':
doType(VK_EQUALS);
break;
case '~':
doType(VK_SHIFT, VK_BACK_QUOTE);
break;
case '!':
doType(VK_EXCLAMATION_MARK);
break;
case '#':
doType(VK_AT);
break;
case '#':
doType(VK_NUMBER_SIGN);
break;
case '$':
doType(VK_DOLLAR);
break;
case '%':
doType(VK_SHIFT, VK_5);
break;
case '^':
doType(VK_CIRCUMFLEX);
break;
case '&':
doType(VK_AMPERSAND);
break;
case '*':
doType(VK_ASTERISK);
break;
case '(':
doType(VK_LEFT_PARENTHESIS);
break;
case ')':
doType(VK_RIGHT_PARENTHESIS);
break;
case '_':
doType(VK_UNDERSCORE);
break;
case '+':
doType(VK_PLUS);
break;
case '\t':
doType(VK_TAB);
break;
case '\n':
doType(VK_ENTER);
break;
case '[':
doType(VK_OPEN_BRACKET);
break;
case ']':
doType(VK_CLOSE_BRACKET);
break;
case '\\':
doType(VK_BACK_SLASH);
break;
case '{':
doType(VK_SHIFT, VK_OPEN_BRACKET);
break;
case '}':
doType(VK_SHIFT, VK_CLOSE_BRACKET);
break;
case '|':
doType(VK_SHIFT, VK_BACK_SLASH);
break;
case ';':
doType(VK_SEMICOLON);
break;
case ':':
doType(VK_COLON);
break;
case '\'':
doType(VK_QUOTE);
break;
case '"':
doType(VK_QUOTEDBL);
break;
case ',':
doType(VK_COMMA);
break;
case '<':
doType(VK_LESS);
break;
case '.':
doType(VK_PERIOD);
break;
case '>':
doType(VK_GREATER);
break;
case '/':
doType(VK_SLASH);
break;
case '?':
doType(VK_SHIFT, VK_SLASH);
break;
case ' ':
doType(VK_SPACE);
break;
default:
throw new IllegalArgumentException("Cannot type character "
+ character);
}
}
private void doType(int... keyCodes) {
doType(keyCodes, 0, keyCodes.length);
}
private void doType(int[] keyCodes, int offset, int length) {
if (length == 0) {
return;
}
robot.keyPress(keyCodes[offset]);
doType(keyCodes, offset + 1, length - 1);
robot.keyRelease(keyCodes[offset]);
}
}
but still not getting any success.
Is it really possible to make auto login to any desktop application?
Please let me know if any suggestions or ways to available to achieve it?
As far as I know this isn't possible in Java. Every aplication has it's own login mechanism and primary purpose of the Robot API is for automated testing of Java platform implementations.