Skip to content

Instantly share code, notes, and snippets.

@mauriciofierrom
Created May 21, 2012 19:28
Show Gist options
  • Save mauriciofierrom/2764142 to your computer and use it in GitHub Desktop.
Save mauriciofierrom/2764142 to your computer and use it in GitHub Desktop.
Este código permite cambiar de ventana a Google Chrome, entrar a google y buscar algo. Usa la clase de testing Robot de Java
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.event.KeyEvent;
public class robo_test
{
Robot rob;
public robo_test() throws AWTException
{
rob = new Robot();
rob.delay(2000);
// Cambiar de ventana
rob.keyPress(KeyEvent.VK_ALT);
rob.keyPress(KeyEvent.VK_TAB);
rob.keyRelease(KeyEvent.VK_TAB);
rob.keyRelease(KeyEvent.VK_ALT);
System.out.println("Changing the window...");
rob.delay(1500);
// Dar el foco a la barra de navegacion
rob.keyPress(KeyEvent.VK_F6);
rob.keyRelease(KeyEvent.VK_F6);
System.out.println("Setting focus on address bar...");
rob.delay(500);
String url = "google.com";
String criteria = "como matar a tu novia con un lapiz sin punta";
for(int i=0;i<url.length();i++)
{
rob.delay(150);
if(Character.isLetterOrDigit(url.charAt(i)))
{
rob.keyPress((int)Character.toUpperCase(url.charAt(i)));
rob.keyRelease((int)Character.toUpperCase(url.charAt(i)));
}
else
{
rob.keyPress((int)url.charAt(i));
rob.keyRelease((int)url.charAt(i));
}
}
rob.keyPress(KeyEvent.VK_ENTER);
rob.keyRelease(KeyEvent.VK_ENTER);
rob.delay(4000);
for(int i=0;i<criteria.length();i++)
{
rob.delay(150);
if(Character.isLetterOrDigit(criteria.charAt(i)))
{
rob.keyPress((int)Character.toUpperCase(criteria.charAt(i)));
rob.keyRelease((int)Character.toUpperCase(criteria.charAt(i)));
}
else
{
rob.keyPress((int)criteria.charAt(i));
rob.keyRelease((int)criteria.charAt(i));
}
}
rob.keyPress(KeyEvent.VK_ENTER);
rob.keyRelease(KeyEvent.VK_ENTER);
}
public static void main(String _[]) throws AWTException
{
robo_test x = new robo_test();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment