Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.   Crhistian David Lucumi
  3.   Laboratorio de Prueba 1
  4.   07-04-2015
  5.  
  6. */
  7.  
  8. import processing.serial.*;
  9.  
  10. import java.awt.Robot;
  11. import java.awt.event.KeyEvent;
  12. import java.io.IOException;
  13.  Serial serie;
  14.  
  15.  Robot robot ;
  16. void setup() {
  17.   serie = new Serial(this, Serial.list()[1], 9600);
  18.   try {
  19.    
  20.     //Launch NotePad
  21.    // Runtime.getRuntime().exec("notepad");
  22.     //Get a Robot
  23.      delay(1200);
  24.      robot = new Robot();
  25.  
  26.  
  27.    
  28.   } catch (Exception e) {
  29.     //Uh-oh...
  30.     e.printStackTrace();
  31.     exit();
  32.   }
  33. }
  34.  
  35. void draw() {
  36.  
  37.   try{
  38.    
  39.     if (serie.available()>0){
  40.         char d = serie.readChar();
  41.         println(d);
  42.         if (d=='A'){
  43.           println(d);
  44.              presiona(KeyEvent.VK_UP);
  45.         }else
  46.         if (d=='B'){
  47.            
  48.             presiona(KeyEvent.VK_LEFT);
  49.             println(d);
  50.         }else
  51.         if (d=='C'){
  52.             presiona(KeyEvent.VK_DOWN);
  53.             println(d);
  54.         }
  55.         else
  56.         if (d=='D'){
  57.            
  58.             presiona(KeyEvent.VK_RIGHT);
  59.             println(d);
  60.         }
  61.         if (d=='P'){
  62.          
  63.           presiona(KeyEvent.VK_ENTER);
  64.           println(d);
  65.       }
  66.      
  67.    
  68.        
  69.      
  70.       }
  71.      
  72.   }catch (Exception e){
  73.     //oh oh
  74.     e.printStackTrace();
  75.     exit();
  76.   }
  77. }
  78.  
  79. void presiona(int llave){
  80.          robot.keyPress(llave);
  81.         robot.delay(50);
  82.         robot.keyRelease(llave);
  83.         robot.delay(50);
  84. }