SHARE
TWEET

Untitled

a guest Oct 10th, 2014 222 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import processing.serial.*;
  2. import java.awt.Robot;
  3. import java.awt.event.KeyEvent;
  4.  
  5. Serial myPort;  // Create object from Serial class
  6.  
  7. String buttonsPressed = "";
  8. Robot r;
  9. boolean stopped = false;
  10.  
  11. void setup(){
  12.   String portName = "COM13";//Serial.list()[0];
  13.   myPort = new Serial(this, portName, 115200);
  14.   try{
  15.   r = new Robot();
  16.   }
  17.   catch(Exception e){}
  18. }
  19.  
  20. void draw(){
  21.   buttonsPressed = "";
  22.   while ( myPort.available() > 0) {  // If data is available,
  23.     int c = myPort.read();         // read it and store it in val    
  24.     if ((char)c != '\n' && (char)c != '\r'){
  25.        buttonsPressed += (char)c;
  26.     }
  27.     else break;
  28.   }  
  29.   if (buttonsPressed.isEmpty()==false && buttonsPressed.length()==4){
  30.     println(buttonsPressed);
  31.    
  32.     if (buttonsPressed.charAt(0) == '1'){
  33.       pressKey(KeyEvent.VK_N);
  34.       while ( myPort.available() > 0) // If data is available,
  35.         myPort.read();
  36.       delay(500);    
  37.     }
  38.     if (buttonsPressed.charAt(1) == '1'){
  39.  
  40.       if (stopped == false){
  41.         pressKey(KeyEvent.VK_S);
  42.         stopped = true;
  43.       }
  44.       else{
  45.         pressKey(KeyEvent.VK_P);
  46.         stopped = false;
  47.       }
  48.       while ( myPort.available() > 0) // If data is available,
  49.         myPort.read();
  50.       delay(500);    
  51.     }
  52.     if (buttonsPressed.charAt(2) == '1'){
  53.       pressKey(KeyEvent.VK_D);
  54.     }
  55.     if (buttonsPressed.charAt(3) == '1'){
  56.       pressKey(KeyEvent.VK_U);
  57.     }
  58.   }
  59. }
  60.  
  61. void pressKey(int c){
  62.       r.keyPress(KeyEvent.VK_CONTROL);
  63.       r.keyPress(KeyEvent.VK_ALT);  
  64.       r.keyPress(KeyEvent.VK_SHIFT);
  65.       r.keyPress(c);
  66.       r.keyRelease(KeyEvent.VK_CONTROL);
  67.       r.keyRelease(KeyEvent.VK_ALT);  
  68.       r.keyRelease(KeyEvent.VK_SHIFT);
  69.       r.keyRelease(c);
  70. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 60% OFF on Pastebin PRO accounts!
Top