Advertisement
shashiskills

Untitled

Oct 29th, 2012
1,877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package com.kant.remoteBluetooth;
  2.  
  3. import java.awt.Robot;
  4. import java.awt.event.KeyEvent;
  5. import java.io.InputStream;
  6.  
  7. import javax.microedition.io.StreamConnection;
  8.  
  9. public class ProcessConnectionThread implements Runnable {
  10.  
  11.  private StreamConnection comm = null;
  12.  private static final int EXIT_CMD = -1;
  13.  private static final int KEY_RIGHT = 2;
  14.  private static final int KEY_LEFT = 3;
  15.  
  16.  public ProcessConnectionThread(StreamConnection conn) {
  17.   comm = conn;
  18.  }
  19.  
  20.  @Override
  21.  public void run() {
  22.   try {
  23.    InputStream inputStream = comm.openInputStream();
  24.    System.out.println("waiting for the input");
  25.    Robot robo = new Robot();
  26.    
  27.  
  28.    while (true) {
  29.     int command = inputStream.read();
  30.     if(command == EXIT_CMD){System.out.println("Process terminating");break;}
  31.     switch (command) {
  32.     case KEY_RIGHT:
  33.      robo.keyPress(KeyEvent.VK_RIGHT);
  34.      break;
  35.     case KEY_LEFT:
  36.      robo.keyPress(KeyEvent.VK_LEFT);
  37.      break;
  38.     }
  39.    }
  40.   } catch (Exception e) {
  41.    // TODO Auto-generated catch block
  42.    e.printStackTrace();
  43.   }
  44.  }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement