Q:

Recording keyboard, mouse activity in linux

I need some way to detect mouse/keyboard activity on Linux. I need to record this activity and send this record to my android tablet using tcp socket. I m running this program in terminal and it is showing error Exception in thread "main"java.lang.UnsupportedClassVersionError: Mouse : Unsupported major.minor version 51.0..any help????
import java.awt.HeadlessException;
 import java.awt.MouseInfo;
 import java.awt.Point;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
  import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
  import java.net.InetAddress;
  import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.util.Timer;
 import java.util.TimerTask;

 public class Mouse {
 public static void main(String[] args) throws InterruptedException {
Point p, prev_p;
p = MouseInfo.getPointerInfo().getLocation();
DatagramSocket socket = null;
try {
    socket = new DatagramSocket(8988);
} catch (SocketException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
InetAddress addr = null;
try {
    addr = InetAddress.getByName("107.108.203.204");
} catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
File file = new File("/sys/kernel/debug/usb/usbmon/6u");
BufferedReader br = null;
try {
    br = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    System.err
            .println("To fix the error Run as root or Change ownership of the file to the user who runs this program");

}
String line, s = null;
try {
    while ((line = br.readLine()) != null) {
        prev_p = p;
        p = MouseInfo.getPointerInfo().getLocation();

             String[] arr = line.split(" ");
             if (arr.length == 8)
             s = arr[7];
             System.out.println(s+"  "+Integer.parseInt(s.substring(2,4),16));
            byte[] buffer = s.getBytes();
            DatagramPacket pak = new DatagramPacket(buffer, buffer.length,
                    addr, 8988);
            try {
                socket.send(pak);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
}
}

A:

I shall not go into the basics of telling you how to use a tcp socket, that is simple enough.
However the basics of your question is that you will need to open and constantly read the /dev/input/by-id/yourmouseorkeyboardnamehere file. Reading this file will cause your program to block until there is a keyboard/mouse input (depending on if you read the keyboard or mouse file) then you will be able to read data representing what data came from the keyboard or mouse.
It should from there be fairly easy to send this data over a tcp socket to your tablet, you can learn to do that from any sockets tutorial on the Internet.
If you have any questions or need more detail please comment bellow.

